From: vsv Date: Mon, 12 May 2014 13:29:33 +0000 (+0400) Subject: Issue #22: History branch for parts and icons of features X-Git-Tag: V_0.2~74 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2e7a22952a8ff5259ac1e6702af4c66e0a186d26;p=modules%2Fshaper.git Issue #22: History branch for parts and icons of features --- diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 719b6f466..16a56174e 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -1,5 +1,6 @@ #include "XGUI_DocumentDataModel.h" #include "XGUI_PartDataModel.h" +#include "XGUI_Workshop.h" #include #include @@ -9,6 +10,7 @@ #include +#include #include #include @@ -40,7 +42,7 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel() void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) { // Created object event ******************* - if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) { + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) { const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); boost::shared_ptr aFeature = aUpdMsg->feature(); boost::shared_ptr aDoc = aFeature->document(); @@ -77,7 +79,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } // Deleted object event *********************** - } else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_DELETED) { + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) { const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); boost::shared_ptr aDoc = aUpdMsg->document(); @@ -110,11 +112,12 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } // Deleted object event *********************** - } else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED) { - const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - boost::shared_ptr aFeature = aUpdMsg->feature(); - boost::shared_ptr aDoc = aFeature->document(); + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) { + //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + //boost::shared_ptr aFeature = aUpdMsg->feature(); + //boost::shared_ptr aDoc = aFeature->document(); + // TODO: Identify the necessary index by the modified feature QModelIndex aIndex; emit dataChanged(aIndex, aIndex); @@ -168,15 +171,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) else return QVariant(); case Qt::DecorationRole: - { - std::string aType = aFeature->getKind(); - if (aType.compare("Point") == 0) - return QIcon(":pictures/point_ico.png"); - if (aType.compare("Part") == 0) - return QIcon(":pictures/part_ico.png"); - if (aType.compare("Sketch") == 0) - return QIcon(":icons/sketch.png"); - } + return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); case Qt::ToolTipRole: return tr("Feature object"); default: diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index 3c90dcf1f..7214c82f4 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -97,6 +97,7 @@ private: //! List of saved QModelIndexes created by sub-models QList myIndexes; + }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 0e31dd7fd..cc5b7395c 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -1,4 +1,5 @@ #include "XGUI_PartDataModel.h" +#include "XGUI_Workshop.h" #include #include @@ -47,11 +48,15 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const // return an Icon switch (theIndex.internalId()) { case ParamsFolder: - return QIcon(":pictures/params_folder.png"); + return QIcon(":pictures/params_folder.png"); case ConstructFolder: - return QIcon(":pictures/constr_folder.png"); + return QIcon(":pictures/constr_folder.png"); case ConstructObject: - return QIcon(":pictures/point_ico.png"); + { + FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + if (aFeature) + return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + } } break; @@ -206,6 +211,13 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons if (aFeature) return aFeature->data()->getName().c_str(); } + case HistoryObject: + { + boost::shared_ptr aFeature = + featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + if (aFeature) + return aFeature->data()->getName().c_str(); + } } break; case Qt::DecorationRole: @@ -219,7 +231,18 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case BodiesFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: - return QIcon(":pictures/point_ico.png"); + { + FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + if (aFeature) + return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + } + case HistoryObject: + { + boost::shared_ptr aFeature = + featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + if (aFeature) + return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); + } } break; case Qt::ToolTipRole: @@ -243,7 +266,7 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const return 0; switch (parent.internalId()) { case MyRoot: - return 3; + return 3 + featureDocument()->size(FEATURES_GROUP); case ParamsFolder: return featureDocument()->size(PARAMETERS_GROUP); case ConstructFolder: @@ -273,7 +296,9 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd case 1: return createIndex(1, 0, (qint32) ConstructFolder); case 2: - return createIndex(1, 0, (qint32) BodiesFolder); + return createIndex(2, 0, (qint32) BodiesFolder); + default: + return createIndex(theRow, theColumn, (qint32) HistoryObject); } case ParamsFolder: return createIndex(theRow, 0, (qint32) ParamObject); @@ -293,6 +318,7 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const case ParamsFolder: case ConstructFolder: case BodiesFolder: + case HistoryObject: return createIndex(0, 0, (qint32) MyRoot); case ParamObject: return createIndex(0, 0, (qint32) ParamsFolder); @@ -318,7 +344,10 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: - return myDocument->feature(PARTS_GROUP, myId); + if (theIndex.row() < 3) + return myDocument->feature(PARTS_GROUP, myId); + else + return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); case ParamsFolder: case ConstructFolder: return FeaturePtr(); diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index ace36a743..abda0bfde 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -105,7 +105,8 @@ private: ConstructFolder, ConstructObject, BodiesFolder, - BodieswObject + BodieswObject, + HistoryObject }; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 14d4c9459..48a4615d2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -52,6 +52,17 @@ #include #endif + +QMap XGUI_Workshop::myIcons; + +QString XGUI_Workshop::featureIcon(const std::string& theId) +{ + QString aId(theId.c_str()); + if (myIcons.contains(aId)) + return myIcons[aId]; + return QString(); +} + XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), myCurrentFile(QString()), @@ -270,6 +281,9 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) #endif return; } + // Remember features icons + myIcons[QString(theMessage->id().c_str())] = QString(theMessage->icon().c_str()); + //Find or create Workbench QString aWchName = QString::fromStdString(theMessage->workbenchId()); QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures()); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 0d6c8ff3d..922a4dd89 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -90,6 +90,10 @@ public: XGUI_ViewerProxy* viewer() const { return myViewerProxy; } + //! Returns icon name according to feature Id + static QString featureIcon(const std::string& theId); + + signals: void salomeViewerSelection(); @@ -154,6 +158,9 @@ private: XGUI_SalomeConnector* mySalomeConnector; XGUI_ErrorDialog* myErrorDlg; XGUI_ViewerProxy* myViewerProxy; + + static QMap myIcons; + }; #endif