From: vsv Date: Fri, 4 Apr 2014 07:07:49 +0000 (+0400) Subject: Models for object browser created X-Git-Tag: V_0.1~39^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa27aa821a63e70446a5342d0692679042eaa220;p=modules%2Fshaper.git Models for object browser created --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index c6dfa0f7e..eca79ac1a 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -34,3 +34,5 @@ INCLUDE_DIRECTORIES( ../Config ${CAS_INCLUDE_DIRS} ) + +INSTALL(TARGETS Model DESTINATION bin) diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 017acf05d..c9afbc7ab 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -52,6 +52,7 @@ IF(WIN32) ENDIF(WIN32) INSTALL(TARGETS _ModelAPI DESTINATION swig) +INSTALL(TARGETS ModelAPI DESTINATION bin) #INSTALL(TARGETS ${SWIG_SCRIPTS} DESTINATION swig) diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index 0f2a9be5a..b2ece1f92 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -13,7 +13,8 @@ class PyConsole_Editor; class PyConsole_EnhInterp; class QMenu; -class PYCONSOLE_EXPORT PyConsole_Console : public QWidget//, public SUIT_PopupClient +//PYCONSOLE_EXPORT +class PyConsole_Console : public QWidget//, public SUIT_PopupClient { Q_OBJECT @@ -76,7 +77,8 @@ protected: * Similar to PyConsole_Console except that an enhanced interpreter and enhanced editor * are encapsulated. */ -class PYCONSOLE_EXPORT PyConsole_EnhConsole: public PyConsole_Console +//PYCONSOLE_EXPORT +class PyConsole_EnhConsole: public PyConsole_Console { Q_OBJECT diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index f3324dc25..8c17a5bc7 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -10,7 +10,8 @@ class PyConsole_Interp; class PyInterp_Request; class QEventLoop; -class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit +//PYCONSOLE_EXPORT +class PyConsole_Editor : public QTextEdit { Q_OBJECT; diff --git a/src/PyConsole/PyConsole_EnhEditor.h b/src/PyConsole/PyConsole_EnhEditor.h index 03b5e19a1..defa59060 100644 --- a/src/PyConsole/PyConsole_EnhEditor.h +++ b/src/PyConsole/PyConsole_EnhEditor.h @@ -14,7 +14,8 @@ class PyConsole_EnhInterp; /** * Enhanced Python editor handling tab completion. */ -class PYCONSOLE_EXPORT PyConsole_EnhEditor: public PyConsole_Editor +//PYCONSOLE_EXPORT +class PyConsole_EnhEditor: public PyConsole_Editor { Q_OBJECT; diff --git a/src/PyConsole/PyConsole_EnhInterp.h b/src/PyConsole/PyConsole_EnhInterp.h index 1af977cc0..b01f68973 100644 --- a/src/PyConsole/PyConsole_EnhInterp.h +++ b/src/PyConsole/PyConsole_EnhInterp.h @@ -15,7 +15,8 @@ * Enhanced Python interpreter used for auto-completion. * This extends PyConsole_Interp with an API wrapping the Python dir() command nicely. */ -class PYCONSOLE_EXPORT PyConsole_EnhInterp: public PyConsole_Interp +//PYCONSOLE_EXPORT +class PyConsole_EnhInterp: public PyConsole_Interp { public: PyConsole_EnhInterp() diff --git a/src/PyConsole/PyConsole_Interp.h b/src/PyConsole/PyConsole_Interp.h index d65c9e620..5dfa7f78c 100644 --- a/src/PyConsole/PyConsole_Interp.h +++ b/src/PyConsole/PyConsole_Interp.h @@ -6,7 +6,8 @@ #include /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! -class PYCONSOLE_EXPORT PyConsole_Interp : public PyInterp_Interp +//PYCONSOLE_EXPORT +class PyConsole_Interp : public PyInterp_Interp { public: PyConsole_Interp(); diff --git a/src/PyEvent/PyEvent_Event.h b/src/PyEvent/PyEvent_Event.h index ed1ea7b74..76340b94b 100644 --- a/src/PyEvent/PyEvent_Event.h +++ b/src/PyEvent/PyEvent_Event.h @@ -9,7 +9,8 @@ //! SALOME custom event type #define PyEvent_EVENT QEvent::Type( QEvent::User + 10000 ) -class PYEVENT_EXPORT PyEvent_CustomEvent : public QEvent +// PYEVENT_EXPORT +class PyEvent_CustomEvent : public QEvent { public: PyEvent_CustomEvent( int type ); @@ -24,7 +25,8 @@ private: class QSemaphore; -class PYEVENT_EXPORT PyEvent_Event +//PYEVENT_EXPORT +class PyEvent_Event { public: PyEvent_Event(); diff --git a/src/PyEvent/PyEvent_EventFilter.h b/src/PyEvent/PyEvent_EventFilter.h index 23132de7e..d115a2802 100644 --- a/src/PyEvent/PyEvent_EventFilter.h +++ b/src/PyEvent/PyEvent_EventFilter.h @@ -17,7 +17,8 @@ class PyEvent_Event; This event filter can be installed by any application that intends to use PyEvent_Event mechanism asynchronously. This class replaced SalomeApp_EventFilter. */ -class PYEVENT_EXPORT PyEvent_EventFilter: public QObject +//PYEVENT_EXPORT +class PyEvent_EventFilter: public QObject { public: static void Init(); diff --git a/src/PyInterp/PyInterp_Dispatcher.h b/src/PyInterp/PyInterp_Dispatcher.h index fa98d30b0..cb5da2e8a 100644 --- a/src/PyInterp/PyInterp_Dispatcher.h +++ b/src/PyInterp/PyInterp_Dispatcher.h @@ -14,7 +14,8 @@ class QObject; class PyInterp_Watcher; -class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread +//PYINTERP_EXPORT +class PyInterp_Dispatcher : protected QThread { PyInterp_Dispatcher(); // private constructor diff --git a/src/PyInterp/PyInterp_Event.h b/src/PyInterp/PyInterp_Event.h index 01bab92c1..b08c34246 100644 --- a/src/PyInterp/PyInterp_Event.h +++ b/src/PyInterp/PyInterp_Event.h @@ -27,7 +27,8 @@ protected: * Events thrown by the interpreter having executed a command and indicating * the return status. */ -class PYINTERP_EXPORT PyInterp_Event : public QEvent +//PYINTERP_EXPORT +class PyInterp_Event : public QEvent { PyInterp_Event(); PyInterp_Event( const PyInterp_Event& ); diff --git a/src/PyInterp/PyInterp_Interp.h b/src/PyInterp/PyInterp_Interp.h index d92bc4fc9..b93c6475a 100644 --- a/src/PyInterp/PyInterp_Interp.h +++ b/src/PyInterp/PyInterp_Interp.h @@ -7,7 +7,8 @@ #include #include -class PYINTERP_EXPORT PyLockWrapper +//PYINTERP_EXPORT +class PyLockWrapper { PyThreadState* myThreadState; PyThreadState* mySaveThreadState; @@ -19,7 +20,8 @@ public: typedef void PyOutChanged(void* data,char * c); -class PYINTERP_EXPORT PyInterp_Interp +//PYINTERP_EXPORT +class PyInterp_Interp { public: static int _argc; @@ -62,7 +64,8 @@ protected: virtual bool initContext() = 0; }; -class PYINTERP_EXPORT PyObjWrapper +//PYINTERP_EXPORT +class PyObjWrapper { PyObject* myObject; public: diff --git a/src/PyInterp/PyInterp_Request.h b/src/PyInterp/PyInterp_Request.h index 9cc3a68ac..b96cd1dc2 100644 --- a/src/PyInterp/PyInterp_Request.h +++ b/src/PyInterp/PyInterp_Request.h @@ -15,7 +15,8 @@ class PyInterp_Dispatcher; class PyInterp_ExecuteEvent; class PyConsole_Editor; -class PYINTERP_EXPORT PyInterp_Request +// PYINTERP_EXPORT +class PyInterp_Request { friend class PyInterp_Dispatcher; friend class PyInterp_ExecuteEvent; @@ -61,7 +62,8 @@ private: QObject* myListener; }; -class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request +//PYINTERP_EXPORT +class PyInterp_LockRequest : public PyInterp_Request { public: diff --git a/src/PyInterp/PyInterp_Watcher.h b/src/PyInterp/PyInterp_Watcher.h index 91126b7e9..3f110c1e2 100644 --- a/src/PyInterp/PyInterp_Watcher.h +++ b/src/PyInterp/PyInterp_Watcher.h @@ -9,7 +9,8 @@ #include // Private class that keeps track of destructions of request listeners -class PYINTERP_EXPORT PyInterp_Watcher : public QObject +//PYINTERP_EXPORT +class PyInterp_Watcher : public QObject { Q_OBJECT diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 5093a6167..7d38c58d1 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -18,6 +18,9 @@ SET(PROJECT_HEADERS XGUI_RubberBand.h XGUI_Constants.h XGUI_ViewBackground.h + XGUI_DocumentDataModel.h + XGUI_DataModel.h + XGUI_ObjectsBrowser.h ) SET(PROJECT_AUTOMOC @@ -38,6 +41,9 @@ SET(PROJECT_SOURCES XGUI_Viewer.cpp XGUI_RubberBand.cpp XGUI_ViewBackground.cpp + XGUI_DocumentDataModel.cpp + XGUI_DataModel.cpp + XGUI_ObjectsBrowser.cpp ) SET(PROJECT_RESOURCES @@ -58,6 +64,7 @@ SET(PROJECT_LIBRARIES PyConsole PyInterp PyEvent + ModelAPI ) QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES}) @@ -72,6 +79,7 @@ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Event ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/PyInterp ${PROJECT_SOURCE_DIR}/src/PyConsole + ${PROJECT_SOURCE_DIR}/src/ModelAPI ${CAS_INCLUDE_DIRS}) LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR}) @@ -84,6 +92,8 @@ ADD_EXECUTABLE(XGUI WIN32 ${QM_RESOURCES} ) +ADD_DEPENDENCIES(XGUI ModelAPI) + # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore TARGET_LINK_LIBRARIES(XGUI ${PROJECT_LIBRARIES}) diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp new file mode 100644 index 000000000..7dc78aa87 --- /dev/null +++ b/src/XGUI/XGUI_DataModel.cpp @@ -0,0 +1,12 @@ +#include "XGUI_DataModel.h" + + +XGUI_DataModel::XGUI_DataModel(QObject* theParent) + : QAbstractItemModel(theParent) +{ +} + + +XGUI_DataModel::~XGUI_DataModel() +{ +} diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h new file mode 100644 index 000000000..106a7f0cc --- /dev/null +++ b/src/XGUI/XGUI_DataModel.h @@ -0,0 +1,15 @@ + +#ifndef XGUI_DataModel_H +#define XGUI_DataModel_H + +#include + +class XGUI_DataModel : public QAbstractItemModel +{ + Q_OBJECT +public: + XGUI_DataModel(QObject* theParent); + virtual ~XGUI_DataModel(); +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp new file mode 100644 index 000000000..f65545188 --- /dev/null +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -0,0 +1,102 @@ +#include "XGUI_DocumentDataModel.h" + +#include +#include +#include + + + + +XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) + : QAbstractItemModel(theParent), + myParamsFolder(0), + myConstructFolder(0) +{ + //std::shared_ptr myRoot = aMgr->createFeature("Point"); + std::shared_ptr aMgr = ModelAPI_PluginManager::get(); + myDocument = aMgr->currentDocument(); +} + + +XGUI_DocumentDataModel::~XGUI_DocumentDataModel() +{ +} + + +QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) { + case Qt::DisplayRole: + // return a name + if (theIndex.internalId() == quintptr(&myParamsFolder)) + return "Parameters"; + else if (theIndex.internalId() == quintptr(&myConstructFolder)) + return "Constructions"; + else if (theIndex.internalId() == 0) { + return "Part"; + } + break; + case Qt::DecorationRole: + // return an Icon + break; + case Qt::ToolTipRole: + // return Tooltip + break; + } + return QVariant(); +} + + +QVariant XGUI_DocumentDataModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + +int XGUI_DocumentDataModel::rowCount(const QModelIndex &parent) const +{ + std::shared_ptr aIt = myDocument->featuresIterator(PARTS_GROUP); + return aIt->numIterationsLeft() + 2; +} + +int XGUI_DocumentDataModel::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const +{ + switch (theRow) { + case 0: + return createIndex(theRow, theColumn, (quintptr) &myParamsFolder); + case 1: + return createIndex(theRow, theColumn, (quintptr) &myConstructFolder); + default: + { + std::shared_ptr aIt = myDocument->featuresIterator(PARTS_GROUP); + if (aIt->numIterationsLeft() <= (theRow - 1)) { + return createIndex(theRow, theColumn, (quintptr) 0); + } + } + } + return QModelIndex(); +} + + +QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} + +bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const +{ + if (!theParent.isValid()) + return true; + + if (theParent.internalId() == quintptr(&myParamsFolder)) + return myDocument->featuresIterator(PARAMETERS_GROUP)->more(); + if (theParent.internalId() == quintptr(&myConstructFolder)) + return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more(); + if (theParent.internalId() == 0) + return false; + return false; +} \ No newline at end of file diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h new file mode 100644 index 000000000..e6f8a787e --- /dev/null +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -0,0 +1,39 @@ + +#ifndef XGUI_DocumentDataModel_H +#define XGUI_DocumentDataModel_H + +#include + +class ModelAPI_Document; + +class XGUI_DocumentDataModel : public QAbstractItemModel +{ + Q_OBJECT +public: + XGUI_DocumentDataModel(QObject* theParent); + virtual ~XGUI_DocumentDataModel(); + + + virtual QVariant data(const QModelIndex& theIndex, int theRole) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex index(int theRow, int theColumn, + const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex parent(const QModelIndex &index) const; + + virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const; + +private: + //std::shared_ptr myRoot; + short myParamsFolder; + short myConstructFolder; + + std::shared_ptr myDocument; +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 15f36010c..3fd85eca5 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -2,6 +2,7 @@ #include "XGUI_MainMenu.h" #include "XGUI_ViewWindow.h" #include "XGUI_Viewer.h" +#include "XGUI_ObjectsBrowser.h" #include #include @@ -34,9 +35,10 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) QDockWidget* aDoc = new QDockWidget(this); aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE")); - myObjectBrowser = new QTreeWidget(aDoc); - myObjectBrowser->setColumnCount(1); - myObjectBrowser->setHeaderHidden(true); + + myObjectBrowser = new XGUI_ObjectsBrowser(aDoc); + //myObjectBrowser->setColumnCount(1); + //myObjectBrowser->setHeaderHidden(true); aDoc->setWidget(myObjectBrowser); addDockWidget(Qt::LeftDockWidgetArea, aDoc); //aDoc->hide(); @@ -107,7 +109,7 @@ void XGUI_MainWindow::hidePythonConsole() // TEST FUNCTIONS //****************************************************** -void XGUI_MainWindow::fillObjectBrowser() +/*void XGUI_MainWindow::fillObjectBrowser() { QStringList aNames; aNames << "Parameters" << "Constructions"; @@ -151,7 +153,7 @@ void XGUI_MainWindow::fillObjectBrowser() aItem->setText(0, "Features"); aItem->setIcon(0, QIcon(":pictures/features.png")); } -} +}*/ void XGUI_MainWindow::addPropertyPanel() { diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index ec5da26a6..2f85d1c01 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -5,7 +5,7 @@ class XGUI_MainMenu; class XGUI_Viewer; -class QTreeWidget; +class XGUI_ObjectsBrowser; class QMdiArea; class PyConsole_EnhConsole; @@ -22,7 +22,7 @@ public: return myMenuBar; } - QTreeWidget* objectBrowser() const + XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; } @@ -42,11 +42,11 @@ public: private: //!! For test purposes only - void fillObjectBrowser(); + //void fillObjectBrowser(); void addPropertyPanel(); XGUI_MainMenu* myMenuBar; - QTreeWidget* myObjectBrowser; + XGUI_ObjectsBrowser* myObjectBrowser; XGUI_Viewer* myViewer; diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp new file mode 100644 index 000000000..926929063 --- /dev/null +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -0,0 +1,17 @@ +#include "XGUI_ObjectsBrowser.h" +#include "XGUI_DocumentDataModel.h" + + +XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) + : QTreeView(theParent) +{ + setHeaderHidden(true); + myDocModel = new XGUI_DocumentDataModel(this); + setModel(myDocModel); +} + + +XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() +{ +} + diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h new file mode 100644 index 000000000..75d12e5b6 --- /dev/null +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -0,0 +1,23 @@ + +#ifndef XGUI_ObjectsBrowser_H +#define XGUI_ObjectsBrowser_H + +#include + +class XGUI_DocumentDataModel; + +class XGUI_ObjectsBrowser : public QTreeView +{ + Q_OBJECT +public: + XGUI_ObjectsBrowser(QWidget* theParent); + virtual ~XGUI_ObjectsBrowser(); + + XGUI_DocumentDataModel* dataModel() const { return myDocModel; } + +private: + + XGUI_DocumentDataModel* myDocModel; +}; + +#endif \ No newline at end of file