#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Tools.h>
-#include <Events_Error.h>
#include <ModuleBase_Tools.h>
void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent)
{
+ QTreeView::resizeEvent(theEvent);
QSize aSize = theEvent->size();
if (aSize.isValid()) {
- setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH);
+ setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH - 6);
setColumnWidth(1, SECOND_COL_WIDTH);
}
- QTreeView::resizeEvent(theEvent);
}
void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
aLabelWgt->setPalette(aPalet);
myDocModel = new XGUI_DataModel(this);
- myTreeView->setModel(myDocModel);
-
- // It has to be done after setting of model
- myActiveDocLbl->setTreeView(myTreeView);
-
- QItemSelectionModel* aSelMod = myTreeView->selectionModel();
- connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
- this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+ connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+ connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
SLOT(onContextMenuRequested(QContextMenuEvent*)));
{
}
+void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader)
+{
+ myDocModel->setXMLReader(theReader);
+ myTreeView->setModel(myDocModel);
+
+ // It has to be done after setting of model
+ myActiveDocLbl->setTreeView(myTreeView);
+
+ QItemSelectionModel* aSelMod = myTreeView->selectionModel();
+ connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+}
//***************************************************
void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
{
QObjectPtrList aSelectedData = selectedObjects();
if (aSelectedData.size() > 0) {
- ObjectPtr aFeature = aSelectedData.first();
- if (aFeature) { // Selection happens in TreeView
- QObjectPtrList aList;
- aList.append(aFeature);
- // check whether the object can be deleted. There should not be parts which are not loaded
- if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aList))
+ ObjectPtr anObject = aSelectedData.first();
+ if (anObject.get()) { // Selection happens in TreeView
+ // check whether the object can be renamed. There should not be parts which are not loaded
+ std::set<FeaturePtr> aFeatures;
+ aFeatures.insert(ModelAPI_Feature::feature(anObject));
+ if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
return;
// Find index which corresponds the feature
QModelIndex aIndex;
foreach(QModelIndex aIdx, selectedIndexes()) {
ObjectPtr aFea = dataModel()->object(aIdx);
- if (dataModel()->object(aIdx)->isSame(aFeature)) {
+ if (dataModel()->object(aIdx)->isSame(anObject)) {
aIndex = aIdx;
break;
}
}
}
+//***************************************************
+QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
+{
+ QModelIndexList aIndexes;
+ QModelIndex aIndex;
+ for (int i = 0; i < myDocModel->rowCount(theParent); i++) {
+ aIndex = myDocModel->index(i, 0, theParent);
+ if (myDocModel->hasChildren(aIndex)) {
+ if (myTreeView->isExpanded(aIndex)) {
+ aIndexes.append(aIndex);
+ QModelIndexList aSubIndexes = expandedItems(aIndex);
+ if (!aSubIndexes.isEmpty())
+ aIndexes.append(aSubIndexes);
+ }
+ }
+ }
+ return aIndexes;
+}
+
//***************************************************
void XGUI_ObjectsBrowser::rebuildDataTree()
{
}
}
return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+ myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+ foreach(QModelIndex aIndex, myExpandedItems) {
+ myTreeView->setExpanded(aIndex, true);
+ }
+}