//! Returns true if the given document is a sub-document of this tree
virtual bool hasDocument(const boost::shared_ptr<ModelAPI_Document>& theDoc) const = 0;
+ //! Return a Part object
+ virtual FeaturePtr part() const = 0;
+
protected:
//! Id of the current part object in the document
int myId;
XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
+ : QAbstractItemModel(theParent), myActivePart(0)
{
// Find Document object
boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
if (aParent.isValid() && (aParent.internalId() == PartsFolder)) {
return myPartModels.at(theIndex.row())->data(QModelIndex(), theRole);
}
- return toSourceModelIndex(theIndex).data(theRole);
+ return toSourceModelIndex(theIndex)->data(theRole);
}
if (theParent.internalId() == HistoryNode) {
return 0;
}
- QModelIndex aParent = toSourceModelIndex(theParent);
- if (!isSubModel(aParent.model()))
+ QModelIndex* aParent = toSourceModelIndex(theParent);
+ const QAbstractItemModel* aModel = aParent->model();
+ if (!isSubModel(aModel))
return 0;
- return aParent.model()->rowCount(aParent);
+ if (isPartSubModel(aModel)) {
+ if (aModel != myActivePart)
+ return 0;
+ }
+ return aModel->rowCount(*aParent);
}
int XGUI_DocumentDataModel::columnCount(const QModelIndex& theParent) const
if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
return QModelIndex();
- QModelIndex aIndex = toSourceModelIndex(theIndex);
- const QAbstractItemModel* aModel = aIndex.model();
+ QModelIndex* aIndex = toSourceModelIndex(theIndex);
+ const QAbstractItemModel* aModel = aIndex->model();
if (!isSubModel(aModel))
return QModelIndex();
if (isPartSubModel(aModel)) {
- if (!aModel->parent(aIndex).isValid()) {
+ if (!aModel->parent(*aIndex).isValid()) {
return partFolderNode();
}
}
- aIndex = aModel->parent(aIndex);
- if (aIndex.isValid())
- return createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
- return aIndex;
+ QModelIndex aIndex1 = aModel->parent(*aIndex);
+ if (aIndex1.isValid())
+ return createIndex(aIndex1.row(), aIndex1.column(), (void*)getModelIndex(aIndex1));
+ return aIndex1;
}
}
-QModelIndex XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
+QModelIndex* XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
{
QModelIndex* aIndexPtr = static_cast<QModelIndex*>(theProxy.internalPointer());
- return (*aIndexPtr);
+ return aIndexPtr;
}
int aOffset = historyOffset();
return myDocument->feature(FEATURES_GROUP, theIndex.row() - aOffset);
}
- QModelIndex aIndex = toSourceModelIndex(theIndex);
- if (!isSubModel(aIndex.model()))
+ QModelIndex* aIndex = toSourceModelIndex(theIndex);
+ if (!isSubModel(aIndex->model()))
return FeaturePtr();
- const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex.model());
- return aModel->feature(aIndex);
+ const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex->model());
+ return aModel->feature(*aIndex);
}
bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
{
// Nb of rows of top model + Parts folder
return myModel->rowCount(QModelIndex()) + 1;
+}
+
+bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex)
+{
+ if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
+ return false;
+
+ QModelIndex* aIndex = toSourceModelIndex(theIndex);
+ if (!aIndex)
+ return false;
+
+ const QAbstractItemModel* aModel = aIndex->model();
+
+ if (isPartSubModel(aModel)) {
+ // if this is root node (Part item index)
+ if (!aIndex->parent().isValid()) {
+ beginResetModel();
+ myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel;
+ endResetModel();
+ return true;
+ }
+ }
+ return false;
+}
+
+FeaturePtr XGUI_DocumentDataModel::activePart() const
+{
+ if (myActivePart)
+ return myActivePart->part();
+ return FeaturePtr();
}
\ No newline at end of file
//! Returns 0 if the given index is not index of a feature
FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Activates a part data model if the index is a Part node index.
+ //! Returns true if active part changed.
+ bool activatedIndex(const QModelIndex& theIndex);
+
+ FeaturePtr activePart() const;
+
private:
enum {PartsFolder, HistoryNode};
//! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
- QModelIndex toSourceModelIndex(const QModelIndex& theProxy) const;
+ QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
//! Finds a pointer on QModelIndex which is equal to the given one
QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
//! Data models for Parts data tree representation (one data model per a one part)
QList<XGUI_PartModel*> myPartModels;
+ //! Active part in part editing mode
+ XGUI_PartModel* myActivePart;
+
//! List of saved QModelIndexes created by sub-models
QList<QModelIndex*> myIndexes;
mySelectedData.append(aFeature);
}
emit selectionChanged();
+}
+
+void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent)
+{
+ QModelIndex aIndex = currentIndex();
+ bool isChanged = myDocModel->activatedIndex(aIndex);
+ QTreeView::mouseDoubleClickEvent(theEvent);
+ if (isChanged) {
+ setExpanded(aIndex.parent(), true);
+ setExpanded(aIndex, myDocModel->hasChildren(aIndex));
+ emit activePartChanged(myDocModel->activePart());
+ }
}
\ No newline at end of file
signals:
//! Emited when selection is changed
void selectionChanged();
+ void activePartChanged(FeaturePtr thePart);
+protected:
+ virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
private slots:
//! Called when selection in Data Tree is changed
//! List of currently selected data
QFeatureList mySelectedData;
+
+ //QModelIndex myActivePartIndex;
};
#endif
\ No newline at end of file
return createIndex(1, 0, (qint32) ConstructFolder);
return QModelIndex();
}
+
+FeaturePtr XGUI_PartDataModel::part() const
+{
+ return myDocument->feature(PARTS_GROUP, myId);
+}
\ No newline at end of file
//! Returns index corresponded to the group
virtual QModelIndex findGroup(const std::string& theGroup) const;
+ //! Return a Part object
+ virtual FeaturePtr part() const;
+
private:
boost::shared_ptr<ModelAPI_Document> featureDocument() const;
myDisplayer = new XGUI_Displayer(this);
mySelector = new XGUI_SelectionMgr(this);
- connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
myOperationMgr = new XGUI_OperationMgr(this);
myActionsMgr = new XGUI_ActionsMgr(this);
aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
aObjDock->setWindowTitle(tr("Object browser"));
myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
+ connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
aObjDock->setWidget(myObjectBrowser);
return aObjDock;
}
}
//******************************************************
-void XGUI_Workshop::changeCurrentDocument()
+void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
{
- QFeatureList aFeatures = objectBrowser()->selectedFeatures();
-
- // Set current document
- if (aFeatures.size() > 0) {
- FeaturePtr aFeature = aFeatures.first();
-
- boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
- boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
+ boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ if (thePart) {
+ boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = thePart->data()->docRef("PartDocument");
if (aDocRef)
aMgr->setCurrentDocument(aDocRef->value());
+ } else {
+ aMgr->setCurrentDocument(aMgr->rootDocument());
}
}
#define XGUI_WORKSHOP_H
#include "XGUI.h"
+#include "XGUI_Constants.h"
#include <Events_Listener.h>
#include <QObject>
void hideObjectBrowser();
void onFeatureTriggered();
- void changeCurrentDocument();
+ void changeCurrentDocument(FeaturePtr thePart);
signals:
void errorOccurred(const QString&);