From 99104d9516c9b22ac489332a798ac7becc6b4314 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Wed, 12 Sep 2018 17:53:32 +0200 Subject: [PATCH] SampleView switched to SampleTreeWidget instead of bare tree. --- .../Views/SampleDesigner/SampleTreeWidget.cpp | 18 +++++++++-- .../Views/SampleDesigner/SampleTreeWidget.h | 8 +++-- GUI/coregui/Views/SampleView.cpp | 30 +++++++------------ GUI/coregui/Views/SampleView.h | 7 +++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.cpp b/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.cpp index 5ce814b808b..43a4cd651d0 100644 --- a/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.cpp +++ b/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.cpp @@ -14,11 +14,13 @@ #include "SampleTreeWidget.h" #include <QVBoxLayout> -#include <QTreeView> +#include "ItemTreeView.h" +#include "FilterPropertyProxy.h" +#include "SampleModel.h" -SampleTreeWidget::SampleTreeWidget(QWidget* parent) +SampleTreeWidget::SampleTreeWidget(QWidget* parent, SampleModel* model) : QWidget(parent) - , m_treeView(new QTreeView) + , m_treeView(new ItemTreeView) { auto mainLayout = new QVBoxLayout; mainLayout->setMargin(0); @@ -26,5 +28,15 @@ SampleTreeWidget::SampleTreeWidget(QWidget* parent) mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(m_treeView); setLayout(mainLayout); + + FilterPropertyProxy *proxy = new FilterPropertyProxy(1, parent); + proxy->setSourceModel(model); + m_treeView->setModel(proxy); + m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false); +} + +QTreeView* SampleTreeWidget::treeView() +{ + return m_treeView; } diff --git a/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.h b/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.h index fe2c2713d2b..57a03356446 100644 --- a/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.h +++ b/GUI/coregui/Views/SampleDesigner/SampleTreeWidget.h @@ -18,6 +18,8 @@ #include "WinDllMacros.h" #include <QWidget> +class ItemTreeView; +class SampleModel; class QTreeView; //! Holds tree to select top level sample items. Part of SampleView. @@ -26,10 +28,12 @@ class BA_CORE_API_ SampleTreeWidget : public QWidget { Q_OBJECT public: - SampleTreeWidget(QWidget* parent); + SampleTreeWidget(QWidget* parent, SampleModel* model); + + QTreeView* treeView(); private: - QTreeView* m_treeView; + ItemTreeView* m_treeView; }; #endif // SAMPLETREEWIDGET_H diff --git a/GUI/coregui/Views/SampleView.cpp b/GUI/coregui/Views/SampleView.cpp index 5e77130427a..61c064f0d14 100644 --- a/GUI/coregui/Views/SampleView.cpp +++ b/GUI/coregui/Views/SampleView.cpp @@ -24,25 +24,12 @@ #include "ApplicationModels.h" #include "SampleWidgetBox.h" #include "ItemTreeView.h" +#include "SampleTreeWidget.h" #include <QDockWidget> #include <QMenu> #include <QTimer> -namespace { -ItemTreeView *createTreeView(SampleModel *sampleModel, QWidget *parent) -{ - ItemTreeView *tree_view = new ItemTreeView(parent); - FilterPropertyProxy *proxy = new FilterPropertyProxy(1, parent); - proxy->setSourceModel(sampleModel); - tree_view->setModel(proxy); - tree_view->setAttribute(Qt::WA_MacShowFocusRect, false); - return tree_view; -} - -} - - SampleView::SampleView(MainWindow *mainWindow) : Manhattan::FancyMainWindow(mainWindow) , m_docks(new SampleViewDocks(this)) @@ -94,13 +81,13 @@ void SampleView::initSubWindows() m_subWindows[WIDGET_BOX] = new SampleWidgetBox(sampleDesigner(), this); - m_tree_view = createTreeView(m_models->sampleModel(), this); + m_tree_view = new SampleTreeWidget(this, m_models->sampleModel()); m_subWindows[SAMPLE_TREE] = getTreeView(); getTreeView()->expandAll(); connect(getTreeView()->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), getTreeView(), SLOT(expandAll())); - m_subWindows[PROPERTY_EDITOR] = new SamplePropertyWidget(getTreeView()->selectionModel(), this); + m_subWindows[PROPERTY_EDITOR] = new SamplePropertyWidget(selectionModel(), this); InfoWidget *infoWidget = new InfoWidget(this); connect(infoWidget, SIGNAL(widgetHeightRequest(int)), this, SLOT(setDockHeightForWidget(int))); @@ -110,7 +97,7 @@ void SampleView::initSubWindows() m_subWindows[INFO] = infoWidget; sampleDesigner()->setModels(m_models); - sampleDesigner()->setSelectionModel(getTreeView()->selectionModel(), dynamic_cast<FilterPropertyProxy*>(const_cast<QAbstractItemModel*>(getTreeView()->model()))); + sampleDesigner()->setSelectionModel(selectionModel(), dynamic_cast<FilterPropertyProxy*>(const_cast<QAbstractItemModel*>(getTreeView()->model()))); } void SampleView::createActions() @@ -268,7 +255,7 @@ void SampleView::connectSignals() connect(this, SIGNAL(resetLayout()), this, SLOT(resetToDefaultLayout())); // toolBar should be initialized after MaterialBrowser - m_toolBar = new SampleToolBar(getSampleModel(), getTreeView()->selectionModel(), this); + m_toolBar = new SampleToolBar(getSampleModel(), selectionModel(), this); connect(m_toolBar, SIGNAL(deleteItems()), sampleDesigner()->getView(), SLOT(deleteSelectedItems())); connect(m_toolBar, SIGNAL(selectionMode(int)), sampleDesigner()->getView(), SLOT(onSelectionMode(int))); @@ -323,7 +310,12 @@ SampleModel *SampleView::getSampleModel() QTreeView *SampleView::getTreeView() { - return m_tree_view; + return m_tree_view->treeView(); +} + +QItemSelectionModel* SampleView::selectionModel() +{ + return getTreeView()->selectionModel(); } SampleDesigner* SampleView::sampleDesigner() diff --git a/GUI/coregui/Views/SampleView.h b/GUI/coregui/Views/SampleView.h index 5149549ddcb..50c23cad5d3 100644 --- a/GUI/coregui/Views/SampleView.h +++ b/GUI/coregui/Views/SampleView.h @@ -26,6 +26,7 @@ class SampleDesigner; class SampleToolBar; class ApplicationModels; class SampleModel; +class SampleTreeWidget; class BA_CORE_API_ SampleView : public Manhattan::FancyMainWindow { @@ -59,14 +60,13 @@ protected slots: private: //! Stores sizes of dock widget struct DockSizeInfo { - DockSizeInfo():m_dock(0){} + DockSizeInfo():m_dock(nullptr){} QDockWidget *m_dock; QSize m_min_size; QSize m_max_size; }; void initSubWindows(); - void initSelectionModel(); void createActions(); void connectSignals(); void clearSignalMapper(); @@ -75,6 +75,7 @@ private: SampleModel *getSampleModel(); QTreeView *getTreeView(); + QItemSelectionModel* selectionModel(); SampleViewDocks* m_docks; @@ -92,7 +93,7 @@ private: QAction *m_delete_item_action; ApplicationModels* m_models; - QTreeView *m_tree_view; + SampleTreeWidget *m_tree_view; DockSizeInfo m_dock_info; }; -- GitLab