X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_DataModel.cpp;h=df1eeb932abd91568afe64fe4d0c08feebd17f2c;hb=233ea105d41ced0d7d9fbf27c89e3f770c586497;hp=196957cc5f871da697a783a2a8074f3697645cf9;hpb=6fb5a58743556b877d64129002572de4116abd96;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 196957cc5..df1eeb932 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -130,37 +131,45 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Check that new folders could appear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1)) + if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) > 0)) { // Appears first object in folder which can not be shown empty - insertRow(myXMLReader->rootFolderId(aObjType)); + if (!hasShownFolder(aRootDoc, aNotEmptyFolder)) { + insertRow(myXMLReader->rootFolderId(aObjType)); + addShownFolder(aRootDoc, aNotEmptyFolder); + } + } } // Insert new object int aRow = aRootDoc->size(aObjType) - 1; if (aRow != -1) { - if (aObjType == aRootType) { + if ((aObjType == aRootType) || (aObjType == ModelAPI_Folder::group())) { insertRow(aRow + aNbFolders + 1); } else { int aFolderId = myXMLReader->rootFolderId(aObjType); if (aFolderId != -1) { - insertRow(aRow, createIndex(aFolderId, 1, (void*)Q_NULLPTR)); + insertRow(aRow, createIndex(aFolderId, 0, (void*)Q_NULLPTR)); } } } } else { // Object created in sub-document - QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get()); + QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0); if (aDocRoot.isValid()) { // Check that new folders could appear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1)) + if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) > 0)) { // Appears first object in folder which can not be shown empty - insertRow(myXMLReader->subFolderId(aObjType), aDocRoot); - } - int aRow = aDoc->index(aObject); + if (!hasShownFolder(aDoc, aNotEmptyFolder)) { + insertRow(myXMLReader->subFolderId(aObjType), aDocRoot); + addShownFolder(aDoc, aNotEmptyFolder); + } + } + } + int aRow = aDoc->index(aObject, true); if (aRow != -1) { int aNbSubFolders = foldersCount(aDoc.get()); - if (aObjType == aSubType) { + if ((aObjType == aSubType) || (aObjType == ModelAPI_Folder::group())) { // List of objects under document root insertRow(aRow + aNbSubFolders, aDocRoot); } else { @@ -168,7 +177,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess if (aRow != -1) { int aFolderId = folderId(aObjType, aDoc.get()); if (aFolderId != -1) { - QModelIndex aParentFolder = createIndex(aFolderId, 1, aDoc.get()); + QModelIndex aParentFolder = createIndex(aFolderId, 0, aDoc.get()); insertRow(aRow, aParentFolder); emit dataChanged(aParentFolder, aParentFolder); } @@ -207,8 +216,8 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { std::string aGroup = (*aIt); if (aDoc == aRootDoc) { // If root objects - int aRow = aRootDoc->size(aGroup); - if (aGroup == aRootType) { + int aRow = aRootDoc->size(aGroup, true); + if ((aGroup == aRootType) || (aGroup == ModelAPI_Folder::group())) { // Process root folder removeRow(aRow + aNbFolders); rebuildBranch(aNbFolders, aRow); @@ -216,7 +225,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Process root sub-folder int aFolderId = myXMLReader->rootFolderId(aGroup); if (aFolderId != -1) { - QModelIndex aFolderIndex = createIndex(aFolderId, 1, (void*)Q_NULLPTR); + QModelIndex aFolderIndex = createIndex(aFolderId, 0, (void*)Q_NULLPTR); removeRow(aRow, aFolderIndex); //rebuildBranch(0, aRow); } @@ -224,20 +233,21 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Check that some folders could erased QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0)) { + if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup, true) == 0)) { // Appears first object in folder which can not be shown empty removeRow(myXMLReader->rootFolderId(aGroup)); + removeShownFolder(aRootDoc, aNotEmptyFolder); //rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader->rootType())); break; } } } else { // Remove row for sub-document - QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get()); + QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0); if (aDocRoot.isValid()) { - int aRow = aDoc->size(aGroup); + int aRow = aDoc->size(aGroup, true); int aNbSubFolders = foldersCount(aDoc.get()); - if (aGroup == aSubType) { + if ((aGroup == aSubType) || (aGroup == ModelAPI_Folder::group())) { // List of objects under document root removeRow(aRow + aNbSubFolders, aDocRoot); rebuildBranch(aNbSubFolders, aRow, aDocRoot); @@ -245,18 +255,19 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // List of objects under a folder int aFolderId = folderId(aGroup, aDoc.get()); if (aFolderId != -1) { - QModelIndex aFolderRoot = createIndex(aFolderId, 1, aDoc.get()); + QModelIndex aFolderRoot = createIndex(aFolderId, 0, aDoc.get()); removeRow(aRow, aFolderRoot); //rebuildBranch(0, aRow, aFolderRoot); } } // Check that some folders could disappear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false); - int aSize = aDoc->size(aGroup); + int aSize = aDoc->size(aGroup, true); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) { // Appears first object in folder which can not be shown empty removeRow(myXMLReader->subFolderId(aGroup), aDocRoot); + removeShownFolder(aDoc, aNotEmptyFolder); //rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader->subType()), aDocRoot); break; } @@ -282,10 +293,10 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess && (aFeature->firstResult()->groupName() == ModelAPI_ResultField::group())) { ResultFieldPtr aResult = std::dynamic_pointer_cast(aFeature->firstResult()); - QModelIndex aIndex = objectIndex(aResult); + QModelIndex aIndex = objectIndex(aResult, 0); removeRows(0, aResult->stepsSize(), aIndex); } else { - QModelIndex aIndex = objectIndex(aObject); + QModelIndex aIndex = objectIndex(aObject, 0); if (aIndex.isValid()) { emit dataChanged(aIndex, aIndex); } @@ -309,16 +320,16 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess if (aGroup == myXMLReader->rootType()) // Update objects under root aStartId = foldersCount(); else // Update objects in folder under root - aParent = createIndex(folderId(aGroup), 1, (void*)Q_NULLPTR); + aParent = createIndex(folderId(aGroup), 0, (void*)Q_NULLPTR); } else { // Update a sub-document if (aGroup == myXMLReader->subType()) { // Update sub-document root - aParent = findDocumentRootIndex(aDoc.get()); + aParent = findDocumentRootIndex(aDoc.get(), 0); aStartId = foldersCount(aDoc.get()); } else // update folder in sub-document - aParent = createIndex(folderId(aGroup, aDoc.get()), 1, aDoc.get()); + aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get()); } int aChildNb = rowCount(aParent); rebuildBranch(aStartId, aChildNb - aStartId, aParent); @@ -328,7 +339,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); if (aDoc != aRootDoc) { - QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get()); + QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0); if (aDocRoot.isValid()) emit dataChanged(aDocRoot, aDocRoot); else @@ -373,7 +384,7 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn { std::string aType = theObject->groupName(); DocumentPtr aDoc = theObject->document(); - int aRow = aDoc->index(theObject); + int aRow = aDoc->index(theObject, true); if (aRow == -1) { // it could be a part of complex object FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); @@ -392,12 +403,7 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn if (aResult.get()) { ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult); if (aCompRes.get()) { - for (int i = 0; i < aCompRes->numberOfSubs(true); i++) { - if (aCompRes->subResult(i, true) == theObject) { - aRow = i; - break; - } - } + aRow = ModelAPI_Tools::compSolidIndex(aResult); } } } @@ -408,10 +414,11 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn } SessionPtr aSession = ModelAPI_Session::get(); DocumentPtr aRootDoc = aSession->moduleDocument(); - if (aDoc == aRootDoc && myXMLReader->rootType() == aType) { + if (aDoc == aRootDoc && + ((myXMLReader->rootType() == aType) || (aType == ModelAPI_Folder::group()))) { // The object from root document aRow += foldersCount(); - } else if (myXMLReader->subType() == aType) { + } else if ((myXMLReader->subType() == aType) || (aType == ModelAPI_Folder::group())) { // The object from sub document aRow += foldersCount(aDoc.get()); } @@ -492,14 +499,13 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const } } } else { - ModelAPI_Object* aObj = - dynamic_cast((ModelAPI_Entity*)theIndex.internalPointer()); + ObjectPtr aObj = object(theIndex); if (aObj) { switch (theRole) { case Qt::DisplayRole: { if (aObj->groupName() == ModelAPI_ResultParameter::group()) { - ModelAPI_ResultParameter* aParam = dynamic_cast(aObj); + ResultParameterPtr aParam = std::dynamic_pointer_cast(aObj); AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); QString aVal = QString::number(aValueAttribute->value()); @@ -508,7 +514,7 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const } QString aSuffix; if (aObj->groupName() == myXMLReader->subType()) { - ResultPartPtr aPartRes = getPartResult(aObj); + ResultPartPtr aPartRes = getPartResult(aObj.get()); if (aPartRes.get()) { if (aPartRes->partDoc().get() == NULL) aSuffix = " (Not loaded)"; @@ -517,7 +523,12 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const return aObj->data()->name().c_str() + aSuffix; } case Qt::DecorationRole: - return ModuleBase_IconFactory::get()->getIcon(object(theIndex)); + { + if (aObj->groupName() == ModelAPI_Folder::group()) + return QIcon(":pictures/features_folder.png"); + else + return ModuleBase_IconFactory::get()->getIcon(aObj); + } } } else { switch (theRole) { @@ -559,7 +570,7 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const int aNbItems = 0; std::string aType = myXMLReader->rootType(); if (!aType.empty()) - aNbItems = aRootDoc->size(aType); + aNbItems = aRootDoc->size(aType, true); return aNbFolders + aNbItems; } @@ -596,7 +607,7 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const int aNbSubItems = 0; std::string aSubType = myXMLReader->subType(); if (!aSubType.empty()) - aNbSubItems = aSubDoc->size(aSubType); + aNbSubItems = aSubDoc->size(aSubType, true); return aNbSubItems + aNbSubFolders; } else { // Check for composite object @@ -636,8 +647,8 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & else { // return object under root index std::string aType = myXMLReader->rootType(); int aObjId = theRow - aNbFolders; - if (aObjId < aRootDoc->size(aType)) { - ObjectPtr aObj = aRootDoc->object(aType, aObjId); + if (aObjId < aRootDoc->size(aType, true)) { + ObjectPtr aObj = aRootDoc->object(aType, aObjId, true); aIndex = objectIndex(aObj, theColumn); } } @@ -647,7 +658,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & if (aId == 0) { // return object index inside of first level of folders std::string aType = myXMLReader->rootFolderType(aParentPos); if (theRow < aRootDoc->size(aType)) { - ObjectPtr aObj = aRootDoc->object(aType, theRow); + ObjectPtr aObj = aRootDoc->object(aType, theRow, true); aIndex = objectIndex(aObj, theColumn); } } else { @@ -680,7 +691,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & } else { // this is an object under sub document root std::string aType = myXMLReader->subType(); - ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders); + ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders, true); aIndex = objectIndex(aObj, theColumn); } } else { @@ -768,7 +779,7 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const DocumentPtr aRootDoc = aSession->moduleDocument(); DocumentPtr aSubDoc = aObj->document(); if (aSubDoc == aRootDoc) { - if (aType == myXMLReader->rootType()) + if ((aType == myXMLReader->rootType()) || (aType == ModelAPI_Folder::group())) return QModelIndex(); else { // return first level of folder index @@ -777,7 +788,7 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const return createIndex(aFolderId, 1, (void*)Q_NULLPTR); } } else { - if (aType == myXMLReader->subType()) + if ((aType == myXMLReader->subType()) || (aType == ModelAPI_Folder::group())) return findDocumentRootIndex(aSubDoc.get()); else { // return first level of folder index @@ -886,7 +897,8 @@ Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const } //****************************************************** -QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn) const +QModelIndex + XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn) const { SessionPtr aSession = ModelAPI_Session::get(); DocumentPtr aRootDoc = aSession->moduleDocument(); @@ -906,11 +918,11 @@ QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDo } } } else { // If document is attached to feature - int aNb = aRootDoc->size(ModelAPI_Feature::group()); + int aNb = aRootDoc->size(ModelAPI_Feature::group(), true); ObjectPtr aObj; ResultPartPtr aPartRes; for (int i = 0; i < aNb; i++) { - aObj = aRootDoc->object(ModelAPI_Feature::group(), i); + aObj = aRootDoc->object(ModelAPI_Feature::group(), i, true); aPartRes = getPartResult(aObj.get()); if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) { int aRow = i; @@ -1077,6 +1089,10 @@ void XGUI_DataModel::rebuildBranch(int theRow, int theCount, const QModelIndex& XGUI_DataModel::VisibilityState XGUI_DataModel::getVisibilityState(const QModelIndex& theIndex) const { + Qt::ItemFlags aFlags = theIndex.flags(); + if (aFlags == Qt::ItemFlags()) + return NoneState; + ObjectPtr aObj = object(theIndex); if (aObj.get()) { ResultPtr aResObj = std::dynamic_pointer_cast(aObj); @@ -1084,7 +1100,8 @@ XGUI_DataModel::VisibilityState XGUI_Displayer* aDisplayer = myWorkshop->displayer(); ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(aResObj); if (aCompRes.get()) { - VisibilityState aState = NoneState; + VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ? + (aDisplayer->isVisible(aCompRes)? Visible : Hidden) : NoneState; for (int i = 0; i < aCompRes->numberOfSubs(true); i++) { ResultPtr aSubRes = aCompRes->subResult(i, true); VisibilityState aS = aDisplayer->isVisible(aSubRes)? Visible : Hidden;