From 5de4a5c44996dabce15c4ed9e7ba3bcabfae38db Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 14 Mar 2016 13:28:15 +0100 Subject: [PATCH] Fix in ParticleView and LayerView appearance ou PropertyChanged --- .../Views/SampleDesigner/ConnectableView.cpp | 22 ++---- .../Views/SampleDesigner/ConnectableView.h | 3 +- .../Views/SampleDesigner/ILayerView.cpp | 13 ++-- GUI/coregui/Views/SampleDesigner/ILayerView.h | 4 +- GUI/coregui/Views/SampleDesigner/IView.cpp | 26 +++---- GUI/coregui/Views/SampleDesigner/IView.h | 6 +- .../Views/SampleDesigner/LayerView.cpp | 8 --- .../Views/SampleDesigner/ParticleView.cpp | 67 ++++++++++++------- .../Views/SampleDesigner/ParticleView.h | 5 ++ 9 files changed, 79 insertions(+), 75 deletions(-) diff --git a/GUI/coregui/Views/SampleDesigner/ConnectableView.cpp b/GUI/coregui/Views/SampleDesigner/ConnectableView.cpp index 36a954fef95..c97ae870bb9 100644 --- a/GUI/coregui/Views/SampleDesigner/ConnectableView.cpp +++ b/GUI/coregui/Views/SampleDesigner/ConnectableView.cpp @@ -33,16 +33,6 @@ ConnectableView::ConnectableView(QGraphicsItem *parent, QRect rect) setFlag(QGraphicsItem::ItemSendsGeometryChanges); } -//void ConnectableView::setParameterizedItem(SessionItem *item) -//{ -// IView::setParameterizedItem(item); -// if (m_item) { -// setLabel( hyphenate(m_item->itemName()) ); -// // TODO restore logic -//// connect(m_item, SIGNAL(siblingsChanged()), this, SLOT(onSiblingsChanged())); -// } -//} - void ConnectableView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -122,14 +112,10 @@ int ConnectableView::getInputPortIndex(NodeEditorPort *port) return m_input_ports.indexOf(port); } -void ConnectableView::update_appearance() -{ - setLabel( hyphenate(m_item->itemName()) ); -} - void ConnectableView::onSiblingsChanged() { if (m_item) { + Q_ASSERT(0); setLabel( hyphenate(m_item->itemName()) ); update(); } @@ -190,6 +176,12 @@ int ConnectableView::getNumberOfInputPorts() return m_input_ports.size(); } +void ConnectableView::update_appearance() +{ + setLabel( hyphenate(m_item->itemName()) ); + IView::update_appearance(); +} + QString ConnectableView::hyphenate(const QString &name) const { QRegExp capital_letter("[A-Z]"); diff --git a/GUI/coregui/Views/SampleDesigner/ConnectableView.h b/GUI/coregui/Views/SampleDesigner/ConnectableView.h index 99cf7be1fc0..1d918bf2e2a 100644 --- a/GUI/coregui/Views/SampleDesigner/ConnectableView.h +++ b/GUI/coregui/Views/SampleDesigner/ConnectableView.h @@ -60,8 +60,6 @@ public: virtual void setColor(const QColor &color) { m_color = color; } - virtual void update_appearance(); - public slots: virtual void onSiblingsChanged(); @@ -70,6 +68,7 @@ protected: virtual int getNumberOfPorts(); virtual int getNumberOfOutputPorts(); virtual int getNumberOfInputPorts(); + virtual void update_appearance(); QString m_name; QColor m_color; diff --git a/GUI/coregui/Views/SampleDesigner/ILayerView.cpp b/GUI/coregui/Views/SampleDesigner/ILayerView.cpp index 4bdf70f49c7..1b11e46483c 100644 --- a/GUI/coregui/Views/SampleDesigner/ILayerView.cpp +++ b/GUI/coregui/Views/SampleDesigner/ILayerView.cpp @@ -78,12 +78,6 @@ void ILayerView::updateColor() } } -void ILayerView::update_appearance() -{ - updateHeight(); - updateColor(); -} - //! Detects movement of the ILayerView and sends possible drop areas to GraphicsScene //! for visualization. QVariant ILayerView::itemChange(GraphicsItemChange change, const QVariant &value) @@ -181,6 +175,13 @@ void ILayerView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) throw GUIHelpers::Error(tr("LayerView::mouseReleaseEvent() -> Loggic error.")); } +void ILayerView::update_appearance() +{ + updateHeight(); + updateColor(); + ConnectableView::update_appearance(); +} + //! Finds candidate (another MultiLayer) into which we will move our ILayerView. //! //! To become the candidate, the bounding rectangles of MultiLayerView and given diff --git a/GUI/coregui/Views/SampleDesigner/ILayerView.h b/GUI/coregui/Views/SampleDesigner/ILayerView.h index 2eeabbb5746..6121e6fa4e9 100644 --- a/GUI/coregui/Views/SampleDesigner/ILayerView.h +++ b/GUI/coregui/Views/SampleDesigner/ILayerView.h @@ -34,15 +34,13 @@ public: int type() const { return TYPE; } -// void setParameterizedItem(SessionItem *item); virtual QString getLabel() const { return QString(); } - virtual void update_appearance(); - protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void update_appearance(); public slots: void onPropertyChange(const QString &propertyName); diff --git a/GUI/coregui/Views/SampleDesigner/IView.cpp b/GUI/coregui/Views/SampleDesigner/IView.cpp index 0ea49686f94..8b2a5c5ebf4 100644 --- a/GUI/coregui/Views/SampleDesigner/IView.cpp +++ b/GUI/coregui/Views/SampleDesigner/IView.cpp @@ -56,6 +56,18 @@ void IView::addView(IView *childView, int row) << childView->getParameterizedItem()->itemName() << " row:" << row; } +void IView::onChangedX() +{ + Q_ASSERT(m_item); + m_item->setItemValue(SessionGraphicsItem::P_XPOS, x()); +} + +void IView::onChangedY() +{ + Q_ASSERT(m_item); + m_item->setItemValue(SessionGraphicsItem::P_YPOS, y()); +} + ModelMapper *IView::mapper() { if (!m_mapper) { @@ -67,19 +79,7 @@ ModelMapper *IView::mapper() //! updates visual appearance of the item (color, icons, size etc) void IView::update_appearance() { - -} - -void IView::onChangedX() -{ - Q_ASSERT(m_item); - m_item->setItemValue(SessionGraphicsItem::P_XPOS, x()); -} - -void IView::onChangedY() -{ - Q_ASSERT(m_item); - m_item->setItemValue(SessionGraphicsItem::P_YPOS, y()); + update(); } void IView::onPropertyChange(const QString &propertyName) diff --git a/GUI/coregui/Views/SampleDesigner/IView.h b/GUI/coregui/Views/SampleDesigner/IView.h index f22b3f715df..48317c0bb63 100644 --- a/GUI/coregui/Views/SampleDesigner/IView.h +++ b/GUI/coregui/Views/SampleDesigner/IView.h @@ -41,10 +41,6 @@ public: virtual void addView(IView *childView, int row = 0); - ModelMapper *mapper(); - - virtual void update_appearance(); - signals: void aboutToBeDeleted(); @@ -53,6 +49,8 @@ public slots: virtual void onChangedY(); protected: + ModelMapper *mapper(); + virtual void update_appearance(); virtual void onPropertyChange(const QString &propertyName); SessionItem *m_item; diff --git a/GUI/coregui/Views/SampleDesigner/LayerView.cpp b/GUI/coregui/Views/SampleDesigner/LayerView.cpp index 42ad79eba35..7e47a041337 100644 --- a/GUI/coregui/Views/SampleDesigner/LayerView.cpp +++ b/GUI/coregui/Views/SampleDesigner/LayerView.cpp @@ -42,14 +42,6 @@ void LayerView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, { Q_UNUSED(widget); -// if(SessionItem *item = getParameterizedItem()) { -// qDebug() << "XXX " << item; -// QVariant v = item->property("Material"); -// Q_ASSERT(v.isValid()); -// MaterialProperty mat = v.value<MaterialProperty>(); -// m_color = mat.getColor(); -// } - painter->setPen(Qt::black); if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) { painter->setPen(Qt::DashLine); diff --git a/GUI/coregui/Views/SampleDesigner/ParticleView.cpp b/GUI/coregui/Views/SampleDesigner/ParticleView.cpp index fa33335f1be..b0bc13627a0 100644 --- a/GUI/coregui/Views/SampleDesigner/ParticleView.cpp +++ b/GUI/coregui/Views/SampleDesigner/ParticleView.cpp @@ -23,21 +23,22 @@ #include <QObject> #include <QDebug> - -ParticleView::ParticleView(QGraphicsItem *parent) - : ConnectableView(parent) +ParticleView::ParticleView(QGraphicsItem *parent) : ConnectableView(parent) { setName(Constants::ParticleType); setColor(DesignerHelper::getDefaultParticleColor()); - setRectangle(DesignerHelper::getDefaultBoundingRect(Constants::ParticleType)); + setRectangle( + DesignerHelper::getDefaultBoundingRect(Constants::ParticleType)); addPort("out", NodeEditorPort::OUTPUT, NodeEditorPort::FORM_FACTOR); - addPort("transformation", NodeEditorPort::INPUT, NodeEditorPort::TRANSFORMATION); + addPort("transformation", NodeEditorPort::INPUT, + NodeEditorPort::TRANSFORMATION); m_roundpar = 5; m_label_vspace = 45; } - -void ParticleView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void ParticleView::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget) { Q_UNUSED(widget); @@ -46,32 +47,33 @@ void ParticleView::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti painter->setPen(Qt::DashLine); } - painter->setBrush(DesignerHelper::getDecorationGradient(m_color, getRectangle() ) ); + painter->setBrush( + DesignerHelper::getDecorationGradient(m_color, getRectangle())); painter->drawRoundedRect(getRectangle(), m_roundpar, m_roundpar); - if ( m_label.isEmpty() ) return; + if (m_label.isEmpty()) + return; painter->setPen(Qt::black); - double width = getRectangle().width()*0.9; + double width = getRectangle().width() * 0.9; double yoffset = 5; // space above the label - //double height = m_label_vspace - yoffset; + // double height = m_label_vspace - yoffset; double height = 20; - QFont serifFont("Monospace", DesignerHelper::getLabelFontSize(), QFont::Normal); + QFont serifFont("Monospace", DesignerHelper::getLabelFontSize(), + QFont::Normal); painter->setFont(serifFont); - QRect textRect( getRectangle().x() + (getRectangle().width()-width)/2., getRectangle().y() + yoffset, width, height ); + QRect textRect(getRectangle().x() + (getRectangle().width() - width) / 2., + getRectangle().y() + yoffset, width, height); painter->drawText(textRect, Qt::AlignCenter, m_label); - QRect target(getRectangle().width()/2 - 16, 25, 32, 32); + QRect target(getRectangle().width() / 2 - 16, 25, 32, 32); painter->drawPixmap(target, m_pixmap); } void ParticleView::onPropertyChange(const QString &propertyName) { - if(propertyName == ParticleItem::P_FORM_FACTOR) { - GroupProperty_t group_property = dynamic_cast<GroupItem*>(getParameterizedItem()->getItem(ParticleItem::P_FORM_FACTOR))->group(); - QString current_ff_type = group_property->getCurrentType(); - QString filename = QString(":/SampleDesigner/images/ff_%1_32.png").arg(current_ff_type); - m_pixmap = QPixmap(filename); + if (propertyName == ParticleItem::P_FORM_FACTOR) { + updatePixmap(); } IView::onPropertyChange(propertyName); @@ -79,11 +81,28 @@ void ParticleView::onPropertyChange(const QString &propertyName) void ParticleView::addView(IView *childView, int /*row*/) { - qDebug() << "ParticleView::addView() xxx " << m_item->itemName() << childView->getParameterizedItem()->itemName() << childView->type() << DesignerHelper::PARTICLE; - if(childView->type() == DesignerHelper::TRANSFORMATION) { + if (childView->type() == DesignerHelper::TRANSFORMATION) { connectInputPort(dynamic_cast<ConnectableView *>(childView), 0); + } else { + throw GUIHelpers::Error( + "ParticleView::addView() -> Error. Unknown view"); } - else { - throw GUIHelpers::Error("ParticleView::addView() -> Error. Unknown view"); - } +} + +void ParticleView::update_appearance() +{ + updatePixmap(); + ConnectableView::update_appearance(); +} + +void ParticleView::updatePixmap() +{ + GroupProperty_t group_property + = dynamic_cast<GroupItem *>( + getParameterizedItem()->getItem(ParticleItem::P_FORM_FACTOR)) + ->group(); + QString current_ff_type = group_property->getCurrentType(); + QString filename + = QString(":/SampleDesigner/images/ff_%1_32.png").arg(current_ff_type); + m_pixmap = QPixmap(filename); } diff --git a/GUI/coregui/Views/SampleDesigner/ParticleView.h b/GUI/coregui/Views/SampleDesigner/ParticleView.h index 1f48b53ea74..bd6e23e9cb0 100644 --- a/GUI/coregui/Views/SampleDesigner/ParticleView.h +++ b/GUI/coregui/Views/SampleDesigner/ParticleView.h @@ -40,7 +40,12 @@ public: void addView(IView *childView, int row = 0); // to add Transformation +protected: + void update_appearance(); + private: + void updatePixmap(); + QPixmap m_pixmap; }; -- GitLab