From 0ad190b4a41ab537e92f486994236745cb293cb6 Mon Sep 17 00:00:00 2001 From: pospelov <pospelov@fz-juelich.de> Date: Tue, 11 Jun 2013 11:51:14 +0200 Subject: [PATCH] Refactoring in MaterialBrowser and PropertyBrowser --- .../SampleDesigner/DesignerHelper.h | 6 +- .../Components/SampleDesigner/ISampleView.h | 16 +- .../Components/SampleDesigner/LayerView.cpp | 65 ++-- .../Components/SampleDesigner/LayerView.h | 30 +- .../SampleDesigner/MaterialBrowser.cpp | 114 ++++--- .../SampleDesigner/MaterialBrowser.h | 10 +- .../SampleDesigner/MaterialBrowserView.cpp | 54 ++-- .../SampleDesigner/MaterialBrowserView.h | 9 +- .../SampleDesigner/MaterialProperty.h | 7 + .../SampleDesigner/MultiLayerView.cpp | 8 - .../SampleDesigner/MultiLayerView.h | 11 - .../SampleDesigner/PropertyBrowserUtils.cpp | 10 +- .../SampleDesigner/PropertyVariantFactory.cpp | 45 +-- .../SampleDesigner/PropertyVariantFactory.h | 7 +- .../SampleDesigner/PropertyVariantManager.cpp | 90 +----- .../SampleDesigner/PropertyVariantManager.h | 14 - .../SampleDesigner/SamplePropertyEditor.cpp | 278 +++++++++--------- .../SampleDesigner/SamplePropertyEditor.h | 18 +- .../SampleDesigner/SampleToolBar.cpp | 4 +- GUI/coregui/mainwindow/main.cpp | 2 + 20 files changed, 346 insertions(+), 452 deletions(-) diff --git a/GUI/coregui/Views/Components/SampleDesigner/DesignerHelper.h b/GUI/coregui/Views/Components/SampleDesigner/DesignerHelper.h index 1872cc39846..d1ec8968dd3 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/DesignerHelper.h +++ b/GUI/coregui/Views/Components/SampleDesigner/DesignerHelper.h @@ -66,9 +66,9 @@ public: static int m_default_layer_width; }; -//#include <complex> -//typedef std::complex<double> complex_t; -//Q_DECLARE_METATYPE(complex_t) +#include <complex> +typedef std::complex<double> complex_t; +Q_DECLARE_METATYPE(complex_t) #endif // EDITORHELPER_H diff --git a/GUI/coregui/Views/Components/SampleDesigner/ISampleView.h b/GUI/coregui/Views/Components/SampleDesigner/ISampleView.h index a52ed578a29..e9f250d8fc3 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/ISampleView.h +++ b/GUI/coregui/Views/Components/SampleDesigner/ISampleView.h @@ -32,16 +32,16 @@ public: virtual NodeEditorPort* addPort(const QString &name, NodeEditorPort::PortDirection direction, NodeEditorPort::PortType port_type); - QString getName() const { return m_name; } - QColor getColor() const { return m_color; } - void setColor(const QColor &color) { m_color = color; } - QRect getRectangle() const { return m_rect;} - void setRectangle(QRect rect) { m_rect = rect; } - QString getLabel() const { return m_label; } - void setLabel(const QString &name); + virtual QString getName() const { return m_name; } + virtual QColor getColor() const { return m_color; } + virtual QRect getRectangle() const { return m_rect;} + virtual void setRectangle(QRect rect) { m_rect = rect; } + virtual QString getLabel() const { return m_label; } + virtual void setLabel(const QString &name); public slots: - void setName(const QString &name) { m_name = name; } + virtual void setName(const QString &name) { m_name = name; } + virtual void setColor(const QColor &color) { m_color = color; } protected: virtual void setPortCoordinates(); diff --git a/GUI/coregui/Views/Components/SampleDesigner/LayerView.cpp b/GUI/coregui/Views/Components/SampleDesigner/LayerView.cpp index d1f1687f4e5..c35e5b109be 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/LayerView.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/LayerView.cpp @@ -39,26 +39,23 @@ LayerView::LayerView(QGraphicsItem *parent) void LayerView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); - painter->setPen(Qt::black); if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) { painter->setPen(Qt::DashLine); } - painter->setBrush(DesignerHelper::getLayerGradient(m_color, getRectangle() ) ); painter->drawRect(getRectangle()); } -void LayerView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - std::cout << "LayerView::mouseMoveEvent -> " << x() << " " << y() << std::endl; - QGraphicsObject::mouseMoveEvent(event); -} +//void LayerView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +//{ +// std::cout << "LayerView::mouseMoveEvent -> " << x() << " " << y() << std::endl; +// QGraphicsObject::mouseMoveEvent(event); +//} void LayerView::mousePressEvent(QGraphicsSceneMouseEvent *event) { - std::cout << "LayerView::mousePressEvent -> " << x() << " " << y() << std::endl; // remove selection from child items QList<QGraphicsItem *> list = childItems(); foreach(QGraphicsItem *item, list) { @@ -77,47 +74,37 @@ void LayerView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } -void LayerView::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - Q_UNUSED(event); - std::cout << "LayerView::dragEnterEvent() ->" << std::endl; -} +//void LayerView::dragEnterEvent(QGraphicsSceneDragDropEvent *event) +//{ +// Q_UNUSED(event); +// std::cout << "LayerView::dragEnterEvent() ->" << std::endl; +//} -void LayerView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) -{ - Q_UNUSED(event); - std::cout << "LayerView::dragLeaveEvent() ->" << std::endl; -} +//void LayerView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) +//{ +// Q_UNUSED(event); +// std::cout << "LayerView::dragLeaveEvent() ->" << std::endl; +//} -void LayerView::dropEvent(QGraphicsSceneDragDropEvent *event) -{ - Q_UNUSED(event); - std::cout << "LayerView::dropEvent() ->" << std::endl; +//void LayerView::dropEvent(QGraphicsSceneDragDropEvent *event) +//{ +// Q_UNUSED(event); +// std::cout << "LayerView::dropEvent() ->" << std::endl; -} +//} + +//void LayerView::dragMoveEvent(QGraphicsSceneDragDropEvent *event) +//{ +// Q_UNUSED(event); +// std::cout << "LayerView::dragMoveEvent() ->" << std::endl; +//} -void LayerView::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -{ - Q_UNUSED(event); - std::cout << "LayerView::dragMoveEvent() ->" << std::endl; -} // layers are not allowed to move horizontally QVariant LayerView::itemChange(GraphicsItemChange change, const QVariant &value) { - std::cout << "YYY itemChange " << x() << " " << y() << std::endl; if (change == ItemPositionChange && scene() && m_fixed) { - // value is the new position. QPointF newPos = value.toPointF(); -// QRectF rect = parentItem()->boundingRect(); -// //std::cout << "rect " << rect.x() << " " << rect.y() << " " << rect.width() << " " << rect.height() << std::endl; -// rect.setY(rect.y() - boundingRect().height()/2.); -// rect.setHeight(rect.height() - boundingRect().height()/2.); -// //std::cout << "rect " << rect.x() << " " << rect.y() << " " << rect.width() << " " << rect.height() << std::endl; -// if (!rect.contains(newPos)) { -// // Keep the item inside the scene rect. -// newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); -// } newPos.setX(m_fixed_xpos); return newPos; } diff --git a/GUI/coregui/Views/Components/SampleDesigner/LayerView.h b/GUI/coregui/Views/Components/SampleDesigner/LayerView.h index 3bd17261d15..7c1a6aeff1d 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/LayerView.h +++ b/GUI/coregui/Views/Components/SampleDesigner/LayerView.h @@ -20,28 +20,24 @@ public: void setFixedX() { m_fixed_xpos = x(); m_fixed=true; } qreal getFixedX() { return m_fixed_xpos; } - QString getName() const { return m_name; } double getThickness() const { return m_thickness; } - QColor getColor() const { return m_color; } MaterialProperty getMaterialProperty() const { return m_materialProperty; } public slots: - void setName(const QString &name); void setThickness(double thickness); - void setColor(const QColor &color); void setMaterialProperty(const MaterialProperty &materialProperty); signals: void LayerMoved(); protected: - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); +// virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event); - virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); - virtual void dropEvent(QGraphicsSceneDragDropEvent *event); - virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event); +// virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event); +// virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); +// virtual void dropEvent(QGraphicsSceneDragDropEvent *event); +// virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event); QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: @@ -52,13 +48,6 @@ private: }; -inline void LayerView::setName(const QString &name) -{ - if(name != m_name) { - m_name = name; - } -} - inline void LayerView::setThickness(double thickness) { if(thickness != m_thickness) { @@ -69,18 +58,11 @@ inline void LayerView::setThickness(double thickness) } } -inline void LayerView::setColor(const QColor &color) -{ - if(color != m_color) { - m_color = color; - update(); - } -} inline void LayerView::setMaterialProperty(const MaterialProperty &materialProperty) { m_materialProperty = materialProperty; - m_color = materialProperty.getColor(); + setColor(materialProperty.getColor()); update(); } diff --git a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.cpp b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.cpp index f726456a297..48d9e633680 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.cpp @@ -21,7 +21,6 @@ MaterialBrowser::MaterialBrowser(QWidget *parent) MaterialManager::getHomogeneousMaterial("Default", 1., 0.); m_browserModel = new MaterialBrowserModel(0); - } @@ -37,56 +36,103 @@ MaterialBrowser *MaterialBrowser::instance() } -// create new MaterialBrowserView or raise old one if exists -void MaterialBrowser::BrowserViewCall(bool isModal) +MaterialProperty MaterialBrowser::getMaterialProperty() +{ + Q_ASSERT(instance()); + return instance()->this_getSelectedMaterialProperty(); +} + + +void MaterialBrowser::BrowserViewCall(Qt::WindowModality modality) +{ + Q_ASSERT(instance()); + return instance()->this_BrowserViewCall(modality); +} + + + +void MaterialBrowser::this_BrowserViewCall(Qt::WindowModality modality) { - std::cout << "MaterialBrowser::BrowserViewCall() isModal " << isModal << std::endl; + m_browserModel->resetSelection(); if( !m_browserView ) { - std::cout << " MaterialBrowser::BrowserViewCall() " << m_parent << std::endl; - m_browserModel->resetSelection(); + std::cout << "MaterialBrowser::BroswerViewCall() -> new " << std::endl; m_browserView = new MaterialBrowserView(m_browserModel, m_parent); -// NonModal, -// WindowModal, -// ApplicationModal - - connect( m_browserView, SIGNAL(WindowClosed()), this, SLOT(BrowserViewOnCloseEvent()) ); - //m_browserView->setWindowModality(Qt::ApplicationModal); - //m_browserView->setModal(isModal); - std::cout << "MaterialBrowser::BrowserViewCall() -> before " << std::endl; - if(isModal) { - m_browserView->show(); - } else { - if(m_browserView->exec() == QDialog::Accepted) return; - } - std::cout << "MaterialBrowser::BrowserViewCall() -> after " << std::endl; + connect(m_browserView, SIGNAL(destroyed()), this, SLOT(BrowserViewOnDeleteEvent())); + } + if(modality == Qt::NonModal) { + std::cout << "MaterialBrowser::BroswerViewCall() -> show " << std::endl; + m_browserView->show(); + m_browserView->raise(); + std::cout << "MaterialBrowser::BroswerViewCall() -> show done " << std::endl; } else { - if(isModal) { - m_browserView->raise(); - //m_browserView->show(); - } else { - m_browserView->hide(); - if(m_browserView->exec() == QDialog::Accepted) return; - } + std::cout << "MaterialBrowser::BroswerViewCall() -> exec " << std::endl; +// m_browserView->show(); + //m_browserView->hide(); + //m_browserView->exec(); + //m_browserView->setWindowModality(Qt::ApplicationModal); + m_browserView->exec(); +// if(m_browserView->exec() == QDialog::Accepted) return; + std::cout << "MaterialBrowser::BroswerViewCall() -> exec done" << std::endl; } } +// create new MaterialBrowserView or raise old one if exists +//void MaterialBrowser::BrowserViewCall(bool isModal) +//{ +// m_browserModel->resetSelection(); +// if( !m_browserView ) { +// // create new MaterialBrowserView +// m_browserView = new MaterialBrowserView(m_browserModel, m_parent); +//// connect( m_browserView, SIGNAL(WindowClosed()), this, SLOT(BrowserViewOnCloseEvent()) ); +// connect(m_browserView, SIGNAL(destroyed()), this, SLOT(BrowserViewOnCloseEvent())); +// if(isModal) { +// m_browserView->show(); +// } else { +//// if(m_browserView->exec() == QDialog::Accepted) return; +// //if(m_browserView->exec() == QDialog::Accepted) return; +// m_browserView->exec(); +// } +// } else { +// // raise existing MaterialBrowserView +// std::cout << "MaterialBrowser::BrowserViewCall() -> isModal " << isModal << std::endl; +// if(isModal) { +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, raise " << std::endl; +// m_browserView->show(); +// m_browserView->raise(); +// } else { +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, hide, exec " << std::endl; +// m_browserView->exec(); +//// m_browserView->show(); +//// m_browserView->hide(); // necessary to swtich modal mode +//// if(m_browserView->exec() == QDialog::Accepted) return; +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, hide, exec 1.1" << std::endl; +// //m_browserView->setModal(false); +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, hide, exec 1.2" << std::endl; +// //m_browserView->show(); +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, hide, exec 1.3" << std::endl; +// //m_browserView->setModal(true); +// std::cout << "MaterialBrowser::BrowserViewCall() -> show, hide, exec 1.4" << std::endl; +// } +// } +//} + + // delete MaterialBrowserView if it was closed by the user -void MaterialBrowser::BrowserViewOnCloseEvent() +void MaterialBrowser::BrowserViewOnDeleteEvent() { - std::cout << "MaterialBrowser::BrowserViewOnCloseEvent()" << std::endl; - delete m_browserView; + std::cout << "MaterialBrowser::BrowserViewOnCloseEvent() -> XXX" << std::endl; m_browserView = 0; } MaterialProperty MaterialBrowser::this_getSelectedMaterialProperty() { - std::cout << "MaterialBrowser::this_getMaterialProperty()-> 1.1" << std::endl; - BrowserViewCall(false); - std::cout << "MaterialBrowser::this_getMaterialProperty()-> 1.2" << std::endl; - Q_ASSERT(m_browserModel->hasSelection()); + std::cout << "MaterialBrowser::this_getSelectedMaterialProperty() -> 1.1" << std::endl; + BrowserViewCall(Qt::WindowModal); + std::cout << "MaterialBrowser::this_getSelectedMaterialProperty() -> 1.3" << std::endl; + //Q_ASSERT(m_browserModel->hasSelection()); return m_browserModel->getSelectedMaterialProperty(); } diff --git a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.h b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.h index 4f78a1b630f..e9323f67714 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.h +++ b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowser.h @@ -24,15 +24,17 @@ public: static MaterialBrowser *instance(); - static MaterialProperty getMaterialProperty() { return instance()->this_getSelectedMaterialProperty(); } + static MaterialProperty getMaterialProperty(); + + static void BrowserViewCall(Qt::WindowModality modality=Qt::NonModal); public slots: //! create new MaterialBrowserView or raise old one if exists - //! @param isModal The dialog window will be independent from main view, if true - void BrowserViewCall(bool isModal = true); + //! @param A modal widget prevents widgets in all other windows from getting any input. + void this_BrowserViewCall(Qt::WindowModality modality=Qt::NonModal); //! delete MaterialBrowserView if it was closed by the user - void BrowserViewOnCloseEvent(); + void BrowserViewOnDeleteEvent(); private: MaterialProperty this_getSelectedMaterialProperty(); diff --git a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.cpp b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.cpp index 0fcb1656dcc..8fc95bf0aac 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.cpp @@ -32,30 +32,31 @@ MaterialBrowserView::MaterialBrowserView(MaterialBrowserModel *tableModel, QWidg setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //setStyleSheet("background-color:white;"); - m_tableView = new MyTableView(this); +// m_tableView = new MyTableView; + m_tableView = new QTableView; std::cout << "XXX " << m_tableModel << std::endl; m_tableView->setModel( m_tableModel ); m_tableView->horizontalHeader()->setStretchLastSection(true); m_tableView->horizontalHeader()->resizeSection(0, 140); - m_toolBar = new QToolBar(this); + m_toolBar = new QToolBar; m_toolBar->setFixedHeight(28); m_toolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); const int size = style()->pixelMetric(QStyle::PM_SmallIconSize); m_toolBar->setIconSize(QSize(size, size)); m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_statusBar = new QStatusBar(this); + m_statusBar = new QStatusBar; connect(m_tableModel, SIGNAL(SetDataMessage(QString)), this, SLOT(showMessage(QString))); - QVBoxLayout *layout = new QVBoxLayout; + QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(m_toolBar); layout->addWidget(m_tableView); QPushButton *closeButton = new QPushButton(tr("Close")); - connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(closeButton, SIGNAL(clicked()), this, SLOT(closeButtonClicked())); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(1); @@ -70,7 +71,8 @@ MaterialBrowserView::MaterialBrowserView(MaterialBrowserModel *tableModel, QWidg SetupActions(); -// show(); +// setAttribute(Qt::WA_DeleteOnClose); +// setAttribute(Qt::WA_QuitOnClose); } @@ -80,16 +82,34 @@ MaterialBrowserView::~MaterialBrowserView() } -bool MaterialBrowserView::close() +void MaterialBrowserView::closeButtonClicked() { - std::cout << "MaterialBrowserView::close() ->" << std::endl; + std::cout << "MaterialBrowserView::close() -> 1.1" << std::endl; Q_ASSERT(m_tableModel); if( !m_tableModel->hasSelection() && isModal() ) { showMessage("Please select material with checkbox"); - return false; +// setResult(QDialog::Rejected); +// return false; + return; } - accepted(); - return QDialog::close(); + std::cout << "MaterialBrowserView::close() -> 1.2" << std::endl; +// setResult(QDialog::Accepted); + accept(); + std::cout << "MaterialBrowserView::close() -> 1.3" << std::endl; + close(); + std::cout << "MaterialBrowserView::close() -> 1.4" << std::endl; +// return QDialog::close(); +} + + +void MaterialBrowserView::close() +{ + Q_ASSERT(m_tableModel); + if( !m_tableModel->hasSelection() && isModal() ) { + showMessage("Please select material with checkbox"); + return; + } + QDialog::close(); } @@ -139,11 +159,11 @@ void MaterialBrowserView::removeMaterial() } -void MaterialBrowserView::closeEvent(QCloseEvent *event) -{ - std::cout << "MaterialBrowserView::closeEvent() ->" << std::endl; - emit WindowClosed(); - event->accept(); -} +//void MaterialBrowserView::closeEvent(QCloseEvent *event) +//{ +// std::cout << "MaterialBrowserView::closeEvent() ->" << std::endl; +// emit WindowClosed(); +// event->accept(); +//} diff --git a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.h b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.h index dab2d81fadf..af2991110cb 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.h +++ b/GUI/coregui/Views/Components/SampleDesigner/MaterialBrowserView.h @@ -14,7 +14,7 @@ class QToolBar; class MyTableView : public QTableView { public: - MyTableView(QWidget *parent) : QTableView(parent){} + explicit MyTableView(QWidget *parent = 0) : QTableView(parent){} // QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const // { // return QSize(50,50); @@ -49,14 +49,15 @@ public slots: void addMaterial(); void removeMaterial(); void showMessage(const QString &message); - bool close(); + void closeButtonClicked(); + void close(); protected: - void closeEvent(QCloseEvent *event); + //void closeEvent(QCloseEvent *event); private: void SetupActions(); - MyTableView *m_tableView; + QTableView *m_tableView; MaterialBrowserModel *m_tableModel; QStatusBar *m_statusBar; QToolBar *m_toolBar; diff --git a/GUI/coregui/Views/Components/SampleDesigner/MaterialProperty.h b/GUI/coregui/Views/Components/SampleDesigner/MaterialProperty.h index 011f5114ce7..0c7570fe133 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MaterialProperty.h +++ b/GUI/coregui/Views/Components/SampleDesigner/MaterialProperty.h @@ -5,6 +5,11 @@ #include <QString> #include <QColor> #include <QPixmap> +#include <QMetaType> + +#if QT_VERSION < 0x050000 +#define QStringLiteral QString +#endif //! The MaterialProperty defines material property (name,color) to be used @@ -23,6 +28,8 @@ public: } void setName(const QString &name) { m_name = name; } void setColor(const QColor &color) { m_color = color; } + bool operator!=(const MaterialProperty &other) { return getName() != other.getName();} + bool isDefined() { return m_name != QStringLiteral("Undefined"); } private: QString m_name; QColor m_color; diff --git a/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.cpp b/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.cpp index 33edef56e08..a286c245648 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.cpp @@ -17,14 +17,8 @@ #include "DesignerHelper.h" #include "DesignerMimeData.h" - - - MultiLayerView::MultiLayerView(QGraphicsItem *parent) -// : LayerView(parent) : ISampleRectView(parent) -// , m_color(Qt::blue) -// , m_rect(0, 0, DesignerHelper::getDefaultMultiLayerWidth(), DesignerHelper::getDefaultMultiLayerHeight()) , m_fixed_xpos(0) , m_fixed(false) { @@ -35,8 +29,6 @@ MultiLayerView::MultiLayerView(QGraphicsItem *parent) setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges); setAcceptDrops(true); - // setCursor(Qt::OpenHandCursor); - // setAcceptedMouseButtons(Qt::LeftButton); m_expected_types << QString("Layer") << QString("MultiLayer"); allowDropType(QString("Layer")); diff --git a/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.h b/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.h index b9b33e1cd1c..ee144033622 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.h +++ b/GUI/coregui/Views/Components/SampleDesigner/MultiLayerView.h @@ -25,17 +25,11 @@ public: MultiLayerView(QGraphicsItem *parent = 0); -// QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); -// QRect rect() const { return m_rect; } - void addLayer(LayerView *layer, QPointF pos=QPointF()); void addMultiLayer(MultiLayerView *layer, QPointF pos=QPointF()); - void setColor(const QColor &color) { m_color = color; } - void setRectangle(const QRect &rect) { m_rect = rect; } - //! allows droping of object of given type void allowDropType(const QString &name); @@ -68,16 +62,11 @@ protected: bool isExpectedObject(const QString &name); private: - -// QColor m_color; -// QRect m_rect; QList<QRectF> m_drop_areas; QStringList m_expected_types; QStringList m_current_types; - qreal m_fixed_xpos; bool m_fixed; - }; diff --git a/GUI/coregui/Views/Components/SampleDesigner/PropertyBrowserUtils.cpp b/GUI/coregui/Views/Components/SampleDesigner/PropertyBrowserUtils.cpp index 18dc600bf7c..66c6788510f 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/PropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/PropertyBrowserUtils.cpp @@ -35,10 +35,12 @@ MaterialPropertyEdit::MaterialPropertyEdit(QWidget *parent) void MaterialPropertyEdit::buttonClicked() { - m_materialProperty = MaterialBrowser::getMaterialProperty(); - m_textLabel->setText(m_materialProperty.getName()); - m_pixmapLabel->setPixmap(m_materialProperty.getPixmap()); - emit materialPropertyChanged(m_materialProperty); + std::cout << "MaterialPropertyEdit::buttonClicked() " << std::endl; + MaterialProperty mat = MaterialBrowser::getMaterialProperty(); + if(mat != m_materialProperty && mat.isDefined() ) { + setMaterialProperty(mat); + emit materialPropertyChanged(m_materialProperty); + } } diff --git a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.cpp b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.cpp index eb2be5466e6..de74414cfa3 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.cpp @@ -3,7 +3,6 @@ #include "PropertyBrowserUtils.h" #include "MaterialBrowser.h" -#include <iostream> PropertyVariantFactory::~PropertyVariantFactory() { @@ -17,22 +16,17 @@ void PropertyVariantFactory::connectPropertyManager(QtVariantPropertyManager *ma { connect(manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), this, SLOT(slotPropertyChanged(QtProperty *, const QVariant &))); - connect(manager, SIGNAL(attributeChanged(QtProperty *, const QString &, const QVariant &)), - this, SLOT(slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &))); +// connect(manager, SIGNAL(attributeChanged(QtProperty *, const QString &, const QVariant &)), +// this, SLOT(slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &))); QtVariantEditorFactory::connectPropertyManager(manager); } + QWidget *PropertyVariantFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property, QWidget *parent) { if (manager->propertyType(property) == PropertyVariantManager::materialTypeId()) { MaterialPropertyEdit *editor = new MaterialPropertyEdit(parent); -// QVariant var = manager->value(property); -// MaterialProperty mat = var.value<MaterialProperty>(); -// editor->setMaterialProperty(mat); -// editor->setFilePath(manager->value(property).toString()); -// editor->setFilter(manager->attributeValue(property, QLatin1String("filter")).toString()); - QVariant var = manager->value(property); MaterialProperty mat = var.value<MaterialProperty>(); editor->setMaterialProperty(mat); @@ -40,8 +34,6 @@ QWidget *PropertyVariantFactory::createEditor(QtVariantPropertyManager *manager, theCreatedEditors[property].append(editor); theEditorToProperty[editor] = property; -// connect(editor, SIGNAL(filePathChanged(const QString &)), -// this, SLOT(slotSetValue(const QString &))); connect(editor, SIGNAL(materialPropertyChanged(const MaterialProperty &)), this, SLOT(slotSetValue(const MaterialProperty &))); connect(editor, SIGNAL(destroyed(QObject *)), @@ -51,6 +43,7 @@ QWidget *PropertyVariantFactory::createEditor(QtVariantPropertyManager *manager, return QtVariantEditorFactory::createEditor(manager, property, parent); } + void PropertyVariantFactory::disconnectPropertyManager(QtVariantPropertyManager *manager) { disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), @@ -60,45 +53,24 @@ void PropertyVariantFactory::disconnectPropertyManager(QtVariantPropertyManager QtVariantEditorFactory::disconnectPropertyManager(manager); } + void PropertyVariantFactory::slotPropertyChanged(QtProperty *property, const QVariant &value) { - std::cout << "PropertyVariantFactory::slotPropertyChanged() ->v1.1" << std::endl; if (!theCreatedEditors.contains(property)) return; - std::cout << "PropertyVariantFactory::slotPropertyChanged() ->v1.2" << std::endl; QList<MaterialPropertyEdit *> editors = theCreatedEditors[property]; QListIterator<MaterialPropertyEdit *> itEditor(editors); -// while (itEditor.hasNext()) -// itEditor.next()->setFilePath(value.toString()); while (itEditor.hasNext()) { MaterialProperty mat = value.value<MaterialProperty>(); - std::cout << "PropertyVariantFactory::slotPropertyChanged() ->v1.3" << mat.getName().toStdString()<< std::endl; itEditor.next()->setMaterialProperty(mat); } } -void PropertyVariantFactory::slotPropertyAttributeChanged(QtProperty *property, - const QString &attribute, const QVariant &value) -{ - std::cout << "PropertyVariantFactory::slotPropertyAttributeChanged() ->" << std::endl; -// if (!theCreatedEditors.contains(property)) -// return; - -// if (attribute != QLatin1String("filter")) -// return; - -// QList<MaterialPropertyEdit *> editors = theCreatedEditors[property]; -// QListIterator<MaterialPropertyEdit *> itEditor(editors); -// while (itEditor.hasNext()) -// itEditor.next()->setFilter(value.toString()); -} void PropertyVariantFactory::slotSetValue(const MaterialProperty &value) -//void PropertyVariantFactory::slotSetValue(const QString &value) { - std::cout << "PropertyVariantFactory::slotSetValue() -> " << std::endl; QObject *object = sender(); QMap<MaterialPropertyEdit *, QtProperty *>::ConstIterator itEditor = theEditorToProperty.constBegin(); @@ -106,20 +78,17 @@ void PropertyVariantFactory::slotSetValue(const MaterialProperty &value) if (itEditor.key() == object) { QtProperty *property = itEditor.value(); QtVariantPropertyManager *manager = propertyManager(property); - if (!manager) - return; + if (!manager) return; QVariant var; - std::cout << "PropertyVariantFactory::slotSetValue() -> value " << value.getName().toStdString() << std::endl; var.setValue(value); manager->setValue(property, var); - std::cout << "PropertyVariantFactory::slotSetValue() -> done " << std::endl; - return; } itEditor++; } } + void PropertyVariantFactory::slotEditorDestroyed(QObject *object) { QMap<MaterialPropertyEdit *, QtProperty *>::ConstIterator itEditor = diff --git a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.h b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.h index ba72da9ab7d..03471900682 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.h +++ b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantFactory.h @@ -1,14 +1,14 @@ #ifndef OBJECTVARIANTFACTORY_H #define OBJECTVARIANTFACTORY_H - +//! collection of classes extending QtPropertyBrowser functionality #include <QtVariantEditorFactory> class MaterialPropertyEdit; class MaterialProperty; - +//! The PropertyVariabtFactory class provides and manages user defined QVariant based properties. class PropertyVariantFactory : public QtVariantEditorFactory { Q_OBJECT @@ -25,14 +25,11 @@ protected: virtual void disconnectPropertyManager(QtVariantPropertyManager *manager); private slots: void slotPropertyChanged(QtProperty *property, const QVariant &value); - void slotPropertyAttributeChanged(QtProperty *property, const QString &attribute, const QVariant &value); void slotSetValue(const MaterialProperty &value); -// void slotSetValue(const QString &value); void slotEditorDestroyed(QObject *object); private: QMap<QtProperty *, QList<MaterialPropertyEdit *> > theCreatedEditors; QMap<MaterialPropertyEdit *, QtProperty *> theEditorToProperty; }; - #endif // OBJECTVARIANTFACTORY_H diff --git a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.cpp b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.cpp index 6efeb0d08cd..2754254c6b0 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.cpp @@ -1,12 +1,9 @@ #include "PropertyVariantManager.h" -//#include "DesignerHelper.h" +#include "DesignerHelper.h" #include "MaterialBrowser.h" - -#include "Types.h" -Q_DECLARE_METATYPE(complex_t) - #include <iostream> + PropertyVariantManager::PropertyVariantManager(QObject *parent) : QtVariantPropertyManager(parent) { @@ -14,16 +11,6 @@ PropertyVariantManager::PropertyVariantManager(QObject *parent) } -PropertyVariantManager::~PropertyVariantManager() -{ -} - - -//int ObjectVariantManager::complexTypeId() -//{ -// return qMetaTypeId<complex_t>(); -//} - int PropertyVariantManager::materialTypeId() { return qMetaTypeId<MaterialProperty>(); @@ -37,61 +24,30 @@ bool PropertyVariantManager::isPropertyTypeSupported(int propertyType) const return QtVariantPropertyManager::isPropertyTypeSupported(propertyType); } + int PropertyVariantManager::valueType(int propertyType) const { if (propertyType == materialTypeId()) return materialTypeId(); -// return QVariant::String; return QtVariantPropertyManager::valueType(propertyType); } + QVariant PropertyVariantManager::value(const QtProperty *property) const { if (theValues.contains(property)) { QVariant v; v.setValue(theValues[property]); - std::cout << "PropertyVariantManager::value() -> " << theValues[property].getName().toStdString() << std::endl; return v; } - // return theValues[property].value; return QtVariantPropertyManager::value(property); } -//QStringList ObjectVariantManager::attributes(int propertyType) const -//{ -// if (propertyType == materialTypeId()) { -// QStringList attr; -// attr << QLatin1String("filter"); -// return attr; -// } -// return QtVariantPropertyManager::attributes(propertyType); -//} - -//int ObjectVariantManager::attributeType(int propertyType, const QString &attribute) const -//{ -// if (propertyType == materialTypeId()) { -// if (attribute == QLatin1String("filter")) -// return QVariant::String; -// return 0; -// } -// return QtVariantPropertyManager::attributeType(propertyType, attribute); -//} - -//QVariant ObjectVariantManager::attributeValue(const QtProperty *property, const QString &attribute) const -//{ -// if (theValues.contains(property)) { -// if (attribute == QLatin1String("filter")) -// return theValues[property].filter; -// return QVariant(); -// } -// return QtVariantPropertyManager::attributeValue(property, attribute); -//} QString PropertyVariantManager::valueText(const QtProperty *property) const { if (theValues.contains(property)) { return theValues[property].getName(); - //return theValues[property].value; } return QtVariantPropertyManager::valueText(property); } @@ -108,66 +64,30 @@ QIcon PropertyVariantManager::valueIcon(const QtProperty *property) const void PropertyVariantManager::setValue(QtProperty *property, const QVariant &val) { - std::cout << "ObjectVariantManager::setValue() -> XXX 1.1 " << val.type() << " " << val.userType() << " " << materialTypeId() << std::endl; if (theValues.contains(property)) { -// if (val.type() != QVariant::String && !val.canConvert(QVariant::String)) -// return; -// QString str = qVariantValue<QString>(val); -// Data d = theValues[property]; -// if (d.value == str) -// return; -// d.value = str; -// theValues[property] = d; -// emit propertyChanged(property); -// emit valueChanged(property, str); -// return; - std::cout << "ObjectVariantManager::setValue() -> XXX 1.2" << std::endl; if( val.userType() != materialTypeId() ) return; MaterialProperty mat = val.value<MaterialProperty>(); - std::cout << "ObjectVariantManager::setValue() -> XXX 1.3 " << mat.getName().toStdString()<< std::endl; theValues[property] = mat; - QVariant v2; v2.setValue(mat); emit propertyChanged(property); emit valueChanged(property, v2); - - return; } QtVariantPropertyManager::setValue(property, val); } -//void ObjectVariantManager::setAttribute(QtProperty *property, -// const QString &attribute, const QVariant &val) -//{ -// if (theValues.contains(property)) { -// if (attribute == QLatin1String("filter")) { -// if (val.type() != QVariant::String && !val.canConvert(QVariant::String)) -// return; -// QString str = qVariantValue<QString>(val); -// Data d = theValues[property]; -// if (d.filter == str) -// return; -// d.filter = str; -// theValues[property] = d; -// emit attributeChanged(property, attribute, str); -// } -// return; -// } -// QtVariantPropertyManager::setAttribute(property, attribute, val); -//} void PropertyVariantManager::initializeProperty(QtProperty *property) { if (propertyType(property) == materialTypeId()) { - std::cout << "ObjectVariantManager::initializeProperty() -> " << std::endl; MaterialProperty m; theValues[property] = m; } QtVariantPropertyManager::initializeProperty(property); } + void PropertyVariantManager::uninitializeProperty(QtProperty *property) { theValues.remove(property); diff --git a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.h b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.h index 09d841d87b4..568cdcd7ea9 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.h +++ b/GUI/coregui/Views/Components/SampleDesigner/PropertyVariantManager.h @@ -13,22 +13,14 @@ class PropertyVariantManager : public QtVariantPropertyManager Q_OBJECT public: PropertyVariantManager(QObject *parent = 0); - ~PropertyVariantManager(); virtual QVariant value(const QtProperty *property) const; virtual int valueType(int propertyType) const; virtual bool isPropertyTypeSupported(int propertyType) const; - -// virtual QStringList attributes(int propertyType) const; -// virtual int attributeType(int propertyType, const QString &attribute) const; -// virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const; - static int materialTypeId(); public slots: virtual void setValue(QtProperty *property, const QVariant &val); -// virtual void setAttribute(QtProperty *property, -// const QString &attribute, const QVariant &value); protected: virtual QString valueText(const QtProperty *property) const; QIcon valueIcon(const QtProperty *property) const; @@ -36,13 +28,7 @@ protected: virtual void initializeProperty(QtProperty *property); virtual void uninitializeProperty(QtProperty *property); private: -// struct Data { -// QString value; -// QString filter; -// }; -// QMap<const QtProperty *, Data> theValues; QMap<const QtProperty *, MaterialProperty> theValues; }; - #endif // OBJECTVARIANTMANAGER_H diff --git a/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.cpp b/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.cpp index fcd364f8ad9..3773020e9e4 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.cpp @@ -102,36 +102,36 @@ SamplePropertyEditor::SamplePropertyEditor(SampleDesignerInterface *sample_desig } -int SamplePropertyEditor::enumToInt(const QMetaEnum &metaEnum, int enumValue) const -{ - QMap<int, int> valueMap; // dont show multiple enum values which have the same values - int pos = 0; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value)) { - if (value == enumValue) - return pos; - valueMap[value] = pos++; - } - } - return -1; -} +//int SamplePropertyEditor::enumToInt(const QMetaEnum &metaEnum, int enumValue) const +//{ +// QMap<int, int> valueMap; // dont show multiple enum values which have the same values +// int pos = 0; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value)) { +// if (value == enumValue) +// return pos; +// valueMap[value] = pos++; +// } +// } +// return -1; +//} -int SamplePropertyEditor::intToEnum(const QMetaEnum &metaEnum, int intValue) const -{ - QMap<int, bool> valueMap; // dont show multiple enum values which have the same values - QList<int> values; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value)) { - valueMap[value] = true; - values.append(value); - } - } - if (intValue >= values.count()) - return -1; - return values.at(intValue); -} +//int SamplePropertyEditor::intToEnum(const QMetaEnum &metaEnum, int intValue) const +//{ +// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values +// QList<int> values; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value)) { +// valueMap[value] = true; +// values.append(value); +// } +// } +// if (intValue >= values.count()) +// return -1; +// return values.at(intValue); +//} bool SamplePropertyEditor::isSubValue(int value, int subValue) const { @@ -149,60 +149,60 @@ bool SamplePropertyEditor::isSubValue(int value, int subValue) const return true; } -bool SamplePropertyEditor::isPowerOf2(int value) const -{ - while (value) { - if (value & 1) { - return value == 1; - } - value = value >> 1; - } - return false; -} +//bool SamplePropertyEditor::isPowerOf2(int value) const +//{ +// while (value) { +// if (value & 1) { +// return value == 1; +// } +// value = value >> 1; +// } +// return false; +//} -int SamplePropertyEditor::flagToInt(const QMetaEnum &metaEnum, int flagValue) const -{ - if (!flagValue) - return 0; - int intValue = 0; - QMap<int, int> valueMap; // dont show multiple enum values which have the same values - int pos = 0; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value) && isPowerOf2(value)) { - if (isSubValue(flagValue, value)) - intValue |= (1 << pos); - valueMap[value] = pos++; - } - } - return intValue; -} +//int SamplePropertyEditor::flagToInt(const QMetaEnum &metaEnum, int flagValue) const +//{ +// if (!flagValue) +// return 0; +// int intValue = 0; +// QMap<int, int> valueMap; // dont show multiple enum values which have the same values +// int pos = 0; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value) && isPowerOf2(value)) { +// if (isSubValue(flagValue, value)) +// intValue |= (1 << pos); +// valueMap[value] = pos++; +// } +// } +// return intValue; +//} -int SamplePropertyEditor::intToFlag(const QMetaEnum &metaEnum, int intValue) const -{ - QMap<int, bool> valueMap; // dont show multiple enum values which have the same values - QList<int> values; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value) && isPowerOf2(value)) { - valueMap[value] = true; - values.append(value); - } - } - int flagValue = 0; - int temp = intValue; - int i = 0; - while (temp) { - if (i >= values.count()) - return -1; - if (temp & 1) - flagValue |= values.at(i); - i++; - temp = temp >> 1; - } - return flagValue; -} +//int SamplePropertyEditor::intToFlag(const QMetaEnum &metaEnum, int intValue) const +//{ +// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values +// QList<int> values; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value) && isPowerOf2(value)) { +// valueMap[value] = true; +// values.append(value); +// } +// } +// int flagValue = 0; +// int temp = intValue; +// int i = 0; +// while (temp) { +// if (i >= values.count()) +// return -1; +// if (temp & 1) +// flagValue |= values.at(i); +// i++; +// temp = temp >> 1; +// } +// return flagValue; +//} void SamplePropertyEditor::updateClassProperties(const QMetaObject *metaObject, bool recursive) @@ -223,14 +223,14 @@ void SamplePropertyEditor::updateClassProperties(const QMetaObject *metaObject, if (metaProperty.isReadable()) { if (m_classToIndexToProperty.contains(metaObject) && m_classToIndexToProperty[metaObject].contains(idx)) { QtVariantProperty *subProperty = m_classToIndexToProperty[metaObject][idx]; - if (metaProperty.isEnumType()) { - if (metaProperty.isFlagType()) - subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt())); - else - subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt())); - } else { +// if (metaProperty.isEnumType()) { +// if (metaProperty.isFlagType()) +// subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt())); +// else +// subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt())); +// } else { subProperty->setValue(metaProperty.read(m_object)); - } +// } } } } @@ -243,8 +243,8 @@ void SamplePropertyEditor::updateClassProperties(const QMetaObject *metaObject, void SamplePropertyEditor::selectionChanged() { QList<QGraphicsItem *> items = m_sample_designer->getScene()->selectedItems(); - if( !items.size() ) return; - QObject *object = items.back()->toGraphicsObject(); + QObject *object(0); + if( items.size() ) object = items.back()->toGraphicsObject(); setObject(object); } @@ -253,12 +253,11 @@ void SamplePropertyEditor::selectionChanged() void SamplePropertyEditor::setObject(QObject *object) { std::cout << "SamplePropertyEditor::setObject() -> 2.1" << std::endl; - if (m_object == object) - return; + if (m_object == object) return; std::cout << "SamplePropertyEditor::setObject() -> 2.2" << std::endl; if (m_object) { - saveExpandedState(); +// saveExpandedState(); QListIterator<QtProperty *> it(m_topLevelProperties); while (it.hasNext()) { m_browser->removeProperty(it.next()); @@ -269,22 +268,20 @@ void SamplePropertyEditor::setObject(QObject *object) std::cout << "SamplePropertyEditor::setObject() -> 2.3" << std::endl; m_object = object; - if (!m_object) - return; + if (!m_object) return; std::cout << "SamplePropertyEditor::setObject() -> 2.4" << std::endl; addClassProperties(m_object->metaObject()); std::cout << "SamplePropertyEditor::setObject() -> 2.5" << std::endl; - restoreExpandedState(); +// restoreExpandedState(); } void SamplePropertyEditor::addClassProperties(const QMetaObject *metaObject) { std::cout << "SamplePropertyEditor::addClassProperties() -> 3.1" << std::endl; - if (!metaObject) - return; + if (!metaObject) return; // complex_t aaa(1,2); // QVariant var; @@ -319,36 +316,36 @@ void SamplePropertyEditor::addClassProperties(const QMetaObject *metaObject) if (!metaProperty.isReadable()) { subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name())); subProperty->setValue(QLatin1String("< Non Readable >")); - } else if (metaProperty.isEnumType()) { - if (metaProperty.isFlagType()) { - subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name())); - QMetaEnum metaEnum = metaProperty.enumerator(); - QMap<int, bool> valueMap; - QStringList flagNames; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value) && isPowerOf2(value)) { - valueMap[value] = true; - flagNames.append(QLatin1String(metaEnum.key(i))); - } - subProperty->setAttribute(QLatin1String("flagNames"), flagNames); - subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt())); - } - } else { - subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name())); - QMetaEnum metaEnum = metaProperty.enumerator(); - QMap<int, bool> valueMap; // dont show multiple enum values which have the same values - QStringList enumNames; - for (int i = 0; i < metaEnum.keyCount(); i++) { - int value = metaEnum.value(i); - if (!valueMap.contains(value)) { - valueMap[value] = true; - enumNames.append(QLatin1String(metaEnum.key(i))); - } - } - subProperty->setAttribute(QLatin1String("enumNames"), enumNames); - subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt())); - } +// } else if (metaProperty.isEnumType()) { +// if (metaProperty.isFlagType()) { +// subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name())); +// QMetaEnum metaEnum = metaProperty.enumerator(); +// QMap<int, bool> valueMap; +// QStringList flagNames; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value) && isPowerOf2(value)) { +// valueMap[value] = true; +// flagNames.append(QLatin1String(metaEnum.key(i))); +// } +// subProperty->setAttribute(QLatin1String("flagNames"), flagNames); +// subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt())); +// } +// } else { +// subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name())); +// QMetaEnum metaEnum = metaProperty.enumerator(); +// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values +// QStringList enumNames; +// for (int i = 0; i < metaEnum.keyCount(); i++) { +// int value = metaEnum.value(i); +// if (!valueMap.contains(value)) { +// valueMap[value] = true; +// enumNames.append(QLatin1String(metaEnum.key(i))); +// } +// } +// subProperty->setAttribute(QLatin1String("enumNames"), enumNames); +// subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt())); +// } // } else if(metaProperty.typeName() == QString("complex_t")) { // subProperty = m_manager->addProperty(1024, QLatin1String(" PointF Property")); @@ -383,15 +380,15 @@ void SamplePropertyEditor::addClassProperties(const QMetaObject *metaObject) } -void SamplePropertyEditor::saveExpandedState() -{ +//void SamplePropertyEditor::saveExpandedState() +//{ -} +//} -void SamplePropertyEditor::restoreExpandedState() -{ +//void SamplePropertyEditor::restoreExpandedState() +//{ -} +//} void SamplePropertyEditor::slotValueChanged(QtProperty *property, const QVariant &value) @@ -405,14 +402,15 @@ void SamplePropertyEditor::slotValueChanged(QtProperty *property, const QVariant const QMetaObject *metaObject = m_object->metaObject(); QMetaProperty metaProperty = metaObject->property(idx); - if (metaProperty.isEnumType()) { - if (metaProperty.isFlagType()) - metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt())); - else - metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt())); - } else { +// if (metaProperty.isEnumType()) { +// if (metaProperty.isFlagType()) +// metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt())); +// else +// metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt())); +// } else { metaProperty.write(m_object, value); - } +// } + std::cout << "SamplePropertyEditor::slotValueChanged() -> 1.3" << std::endl; // updateClassProperties(metaObject, false); } diff --git a/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.h b/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.h index a5579766099..c592b946e95 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.h +++ b/GUI/coregui/Views/Components/SampleDesigner/SamplePropertyEditor.h @@ -31,17 +31,13 @@ public slots: void selectionChanged(); private slots: -// void valueChanged(QtProperty *property, const QVariant &value); void slotValueChanged(QtProperty *property, const QVariant &value); private: //! assigns objects to the property editor void setObject(QObject *object); - SampleDesignerInterface *m_sample_designer; -// QtVariantPropertyManager *m_variantManager; -// QtTreePropertyBrowser *m_propertyEditor; QObject *m_object; //! object to modify @@ -60,14 +56,14 @@ private: void addClassProperties(const QMetaObject *metaObject); void updateClassProperties(const QMetaObject *metaObject, bool recursive); - void saveExpandedState(); - void restoreExpandedState(); - int enumToInt(const QMetaEnum &metaEnum, int enumValue) const; - int intToEnum(const QMetaEnum &metaEnum, int intValue) const; - int flagToInt(const QMetaEnum &metaEnum, int flagValue) const; - int intToFlag(const QMetaEnum &metaEnum, int intValue) const; +// void saveExpandedState(); +// void restoreExpandedState(); +// int enumToInt(const QMetaEnum &metaEnum, int enumValue) const; +// int intToEnum(const QMetaEnum &metaEnum, int intValue) const; +// int flagToInt(const QMetaEnum &metaEnum, int flagValue) const; +// int intToFlag(const QMetaEnum &metaEnum, int intValue) const; bool isSubValue(int value, int subValue) const; - bool isPowerOf2(int value) const; +// bool isPowerOf2(int value) const; }; diff --git a/GUI/coregui/Views/Components/SampleDesigner/SampleToolBar.cpp b/GUI/coregui/Views/Components/SampleDesigner/SampleToolBar.cpp index f037bf21f32..8edeb4e6ae8 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/SampleToolBar.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/SampleToolBar.cpp @@ -28,7 +28,5 @@ SampleToolBar::SampleToolBar(QWidget *parent) void SampleToolBar::materialBrowserCall() { std::cout << "SampleToolBar::materialBrowserCall() ->" << std::endl; - //new MaterialBrowserView(parentWidget()); - Q_ASSERT(MaterialBrowser::instance()); - MaterialBrowser::instance()->BrowserViewCall(); + MaterialBrowser::BrowserViewCall(); } diff --git a/GUI/coregui/mainwindow/main.cpp b/GUI/coregui/mainwindow/main.cpp index 9e2d83c83ca..fb6b4cf98a2 100644 --- a/GUI/coregui/mainwindow/main.cpp +++ b/GUI/coregui/mainwindow/main.cpp @@ -3,6 +3,8 @@ int main(int argc, char *argv[]) { +// QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); + QApplication a(argc, argv); MainWindow w; w.show(); -- GitLab