+ setEditTriggers(QAbstractItemView::NoEditTriggers);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ 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()
+{
+}
+
+ModuleBase_IDocumentDataModel* XGUI_DataTree::dataModel() const
+{
+ return static_cast<ModuleBase_IDocumentDataModel*>(model());
+}
+
+void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
+{
+ emit contextMenuRequested(theEvent);
+}
+
+void XGUI_DataTree::commitData(QWidget* theEditor)
+{
+ QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
+ if (aEditor) {
+ QString aName = aEditor->text();
+ QModelIndexList aIndexList = selectionModel()->selectedIndexes();
+ ModuleBase_IDocumentDataModel* aModel = dataModel();
+ ObjectPtr aObj = aModel->object(aIndexList.first());
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->startOperation("Rename");
+
+ if (!XGUI_Tools::canRename(this, aObj, aName)) {
+ aMgr->abortOperation();
+ return;
+ }
+
+ aObj->data()->setName(qPrintable(aName));
+ aMgr->finishOperation();
+ }
+}
+
+void XGUI_DataTree::clear()
+{
+ ModuleBase_IDocumentDataModel* aModel = dataModel();
+ aModel->clear();
+ reset();
+}
+
+void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent)
+{
+ QSize aSize = theEvent->size();
+ if (aSize.isValid()) {
+ setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH);
+ setColumnWidth(1, SECOND_COL_WIDTH);
+ }
+}
+
+void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
+{
+ if (theIndex.column() != 1)
+ return;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ // When operation is opened then we can not change history
+ if (aMgr->isOperation())
+ return;
+ ModuleBase_IDocumentDataModel* aModel = dataModel();
+ if (aModel->flags(theIndex) == 0)
+ return;
+ ObjectPtr aObj = aModel->object(theIndex);
+
+ DocumentPtr aDoc = aMgr->activeDocument();
+
+ 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;