#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Feature.h>
#include <Config_FeatureMessage.h>
insertRow(aRow + aNbSubFolders, aDocRoot);
} else {
// List of objects under a folder
- int aFolderId = myXMLReader.subFolderId(aObjType);
- if (aFolderId != -1) {
- insertRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
+ if (aRow != -1) {
+ int aFolderId = myXMLReader.subFolderId(aObjType);
+ if (aFolderId != -1) {
+ insertRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
+ }
}
}
}
int aNbFolders = foldersCount();
int theIndexRow = theIndex.row();
- if ((theIndex.column() == 1) ) {
- //if (theIndexRow >= aNbFolders) {
- // if (theRole == Qt::DecorationRole) {
- // return QIcon(":pictures/arrow.png");
- // }
- //}
+ if ((theRole == Qt::DecorationRole) && (theIndex == lastHistoryIndex()))
+ return QIcon(":pictures/arrow.png");
+
+ if (theIndex.column() == 1)
return QVariant();
- }
int aParentId = theIndex.internalId();
if (aParentId == -1) { // root folders
case Qt::DecorationRole:
return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
case Qt::ForegroundRole:
- if (aRootDoc->isActive())
+ if (aSession->activeDocument() == aRootDoc)
return QBrush(ACTIVE_COLOR);
else
return QBrush(PASSIVE_COLOR);
}
- } else {
+ } else { // an object or sub-document
ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
if (theRole == Qt::ForegroundRole) {
bool aIsActive = false;
if (aSubDoc)
- aIsActive = aSubDoc->isActive();
+ aIsActive = (aSession->activeDocument().get() == aSubDoc);
else {
ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
- aIsActive = aObj->document()->isActive();
+ if (aObj->isDisabled())
+ return QBrush(Qt::lightGray);
+ aIsActive = (aSession->activeDocument() == aObj->document());
}
if (aIsActive)
return QBrush(ACTIVE_COLOR);
//******************************************************
Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
{
- Qt::ItemFlags aFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
- if (theIndex.internalId() > -1) {
- aFlags |= Qt::ItemIsEditable;
+ Qt::ItemFlags aFlags = Qt::ItemIsSelectable;
+
+ ModelAPI_Object* aObj = 0;
+ if (theIndex.internalId() != -1) {
+ if (!getSubDocument(theIndex.internalPointer()))
+ aObj = (ModelAPI_Object*) theIndex.internalPointer();
}
+ if (aObj) {
+ aFlags |= Qt::ItemIsEditable;
+
+ if (!aObj->isDisabled())
+ aFlags |= Qt::ItemIsEnabled;
+ } else
+ aFlags |= Qt::ItemIsEnabled;
return aFlags;
}
}
}
return aResult;
+}
+
+//******************************************************
+QModelIndex XGUI_DataModel::lastHistoryIndex() const
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aCurDoc = aSession->activeDocument();
+ FeaturePtr aFeature = aCurDoc->currentFeature(true);
+ if (aFeature.get()) {
+ QModelIndex aInd = objectIndex(aFeature);
+ return createIndex(aInd.row(), 1, aInd.internalPointer());
+ } else {
+ if (aCurDoc == aSession->moduleDocument())
+ return createIndex(foldersCount() - 1, 1, -1);
+ else
+ return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());
+ }
}
\ No newline at end of file
setSelectionMode(QAbstractItemView::ExtendedSelection);
setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this));
+
+#ifndef ModuleDataModel
+ connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+ SLOT(onDoubleClick(const QModelIndex&)));
+#endif
}
XGUI_DataTree::~XGUI_DataTree()
}
}
+void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
+{
+ if (theIndex.column() != 1)
+ return;
+ ModuleBase_IDocumentDataModel* aModel = dataModel();
+ if (aModel->flags(theIndex) == 0)
+ return;
+ ObjectPtr aObj = aModel->object(theIndex);
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+
+ QModelIndex aOldIndex = aModel->lastHistoryIndex();
+
+ std::string aOpName = tr("History change").toStdString();
+ if (aObj.get()) {
+ if (aObj->document() != aDoc)
+ return;
+ aMgr->startOperation(aOpName);
+ aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObj), true);
+ aMgr->finishOperation();
+ } else {
+ // Ignore clicks on folders outside current document
+ if ((theIndex.internalId() == -1) && (aDoc != aMgr->moduleDocument()))
+ // Clicked folder under root but active document is another
+ return;
+ if ((theIndex.internalId() != -1) && (aDoc.get() != theIndex.internalPointer()))
+ // Cliced not on active document folder
+ return;
+
+ aMgr->startOperation(aOpName);
+ aDoc->setCurrentFeature(FeaturePtr(), true);
+ aMgr->finishOperation();
+ }
+ QModelIndex aNewIndex = aModel->lastHistoryIndex();
+ QModelIndex aParent = theIndex.parent();
+ int aStartRow = std::min(aOldIndex.row(), aNewIndex.row());
+ int aEndRow = std::max(aOldIndex.row(), aNewIndex.row());
+ for (int i = aStartRow; i <= aEndRow; i++) {
+ update(aModel->index(i, 0, aParent));
+ }
+ update(aOldIndex);
+ update(aNewIndex);
+}
//********************************************************************
//********************************************************************