From: vsv Date: Thu, 7 May 2015 13:09:59 +0000 (+0300) Subject: Currently active feature pointer in Object Browser is created X-Git-Tag: V_1.2.0~171 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c460f1b3b61f9c29ac1199c39013f5ce204afd5b;p=modules%2Fshaper.git Currently active feature pointer in Object Browser is created --- diff --git a/src/PartSet/PartSet_DocumentDataModel.cpp b/src/PartSet/PartSet_DocumentDataModel.cpp index bb1c4ac90..3205baedd 100644 --- a/src/PartSet/PartSet_DocumentDataModel.cpp +++ b/src/PartSet/PartSet_DocumentDataModel.cpp @@ -58,6 +58,7 @@ void PartSet_DocumentDataModel::processEvent(const std::shared_ptrmoduleDocument(); + // Created object event ******************* if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { std::shared_ptr aUpdMsg = @@ -81,7 +82,6 @@ void PartSet_DocumentDataModel::processEvent(const std::shared_ptrindex(aPartFeature); aModel->setPartId(anId); - //aModel->setPartId(aRootDoc->index(aObject)); myPartModels[anId] = aModel; insertRow(aStart, partFolderNode(0)); } @@ -197,18 +197,38 @@ void PartSet_DocumentDataModel::rebuildDataTree() beginResetModel(); clearModelIndexes(); - int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group()); - //if (myPartModels.size() != aNbParts) { // resize internal models - // while (myPartModels.size() > aNbParts) { - // delete myPartModels.last(); - // myPartModels.removeLast(); - // } - // while (myPartModels.size() < aNbParts) { - // myPartModels.append(new PartSet_PartDataModel(this)); - // } - // for (int i = 0; i < myPartModels.size(); i++) - // myPartModels.at(i)->setPartId(i); - //} + // Delete extra models + ObjectPtr aObj; + FeaturePtr aFeature; + QIntList aDelList; + foreach (int aId, myPartModels.keys()) { + aObj = aRootDoc->object(ModelAPI_Feature::group(), aId); + if (aObj.get()) { + aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature.get()) { + if (aFeature->getKind() == PartSetPlugin_Part::ID()) + continue; + } + } + aDelList.append(aId); + break; + } + foreach (int aId, aDelList) { + removeSubModel(aId); + } + // Add non existing models + int aHistNb = aRootDoc->size(ModelAPI_Feature::group()); + for (int i = 0; i < aHistNb; i++) { + aObj = aRootDoc->object(ModelAPI_Feature::group(), i); + aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature->getKind() == PartSetPlugin_Part::ID()) { + if (!myPartModels.contains(i)) { + PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this); + aModel->setPartId(i); + myPartModels[i] = aModel; + } + } + } endResetModel(); } @@ -217,18 +237,29 @@ QVariant PartSet_DocumentDataModel::data(const QModelIndex& theIndex, int theRol if (!theIndex.isValid()) return QVariant(); - //if ((theIndex.column() == 1) ) { - // if ((theIndex.internalId() == HistoryNode) && (!aParent.isValid())) { - // switch (theRole) { - // case Qt::DecorationRole: - // if (theIndex.row() == lastHistoryRow()) - // return QIcon(":pictures/arrow.png"); - // } - // } - // return QVariant(); - //} - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + QModelIndex aParent = theIndex.parent(); + if ((theIndex.column() == 1) ) { + if ((theIndex.internalId() >= PartsFolder) && (theIndex.internalId() <= PartResult)) { + if (ModelAPI_Session::get()->activeDocument() == aRootDoc) { + if ((theIndex.internalId() == HistoryNode) && (!aParent.isValid())) { + switch (theRole) { + case Qt::DecorationRole: + if (theIndex.row() == lastHistoryRow()) + return QIcon(":pictures/arrow.png"); + } + } + } + } else { + QModelIndex* aIndex = toSourceModelIndex(theIndex); + const QAbstractItemModel* aModel = aIndex->model(); + if (isPartSubModel(aModel)) { + return aModel->data(*aIndex, theRole); + } + } + return QVariant(); + } + switch (theIndex.internalId()) { case PartsFolder: switch (theRole) { @@ -301,7 +332,6 @@ QVariant PartSet_DocumentDataModel::data(const QModelIndex& theIndex, int theRol } break; } - QModelIndex aParent = theIndex.parent(); if (aParent.internalId() == HistoryNode) { int aId = aParent.row() - historyOffset(); QModelIndex* aIndex = toSourceModelIndex(theIndex); @@ -354,7 +384,7 @@ int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const int PartSet_DocumentDataModel::columnCount(const QModelIndex& theParent) const { - return 1; + return 2; } QModelIndex PartSet_DocumentDataModel::index(int theRow, int theColumn, @@ -370,12 +400,8 @@ QModelIndex PartSet_DocumentDataModel::index(int theRow, int theColumn, if (theRow == aOffs) // Create Parts node aIndex = partFolderNode(theColumn); else { - // create history node or a part sub-tree - int aId = theRow - historyOffset(); + // create history node aIndex = createIndex(theRow, theColumn, HistoryNode); - //if (myPartModels.contains(aId)) { - // aIndex = myPartModels[aId]->index(theRow, theColumn, QModelIndex()); - //} } } } else { @@ -401,7 +427,7 @@ QModelIndex PartSet_DocumentDataModel::parent(const QModelIndex& theIndex) const return QModelIndex(); if (theIndex.internalId() == PartResult) - return partFolderNode(theIndex.column()); + return partFolderNode(0); QModelIndex* aIndex = toSourceModelIndex(theIndex); const QAbstractItemModel* aModel = aIndex->model(); @@ -412,11 +438,11 @@ QModelIndex PartSet_DocumentDataModel::parent(const QModelIndex& theIndex) const if (isPartSubModel(aModel) && (!aIndex1.isValid())) { int aId = myPartModels.key((PartSet_PartModel*) aModel); int aRow = aId + historyOffset(); - return createIndex(aRow, theIndex.column(), (qint32) HistoryNode); + return createIndex(aRow, 0, (qint32) HistoryNode); } if (aIndex1.isValid()) - return createIndex(aIndex1.row(), aIndex1.column(), (void*) getModelIndex(aIndex1)); + return createIndex(aIndex1.row(), 0, (void*) getModelIndex(aIndex1)); return aIndex1; } @@ -633,7 +659,7 @@ void PartSet_DocumentDataModel::deactivatePart() Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const { - Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); //Qt::ItemIsSelectable; + Qt::ItemFlags aFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; //QAbstractItemModel::flags(theIndex); if (object(theIndex)) { aFlags |= Qt::ItemIsEditable; } @@ -690,7 +716,7 @@ QModelIndex PartSet_DocumentDataModel::objectIndex(const ObjectPtr theObject) co QModelIndex aIndex = myModel->objectIndex(theObject); return aIndex.isValid() ? - createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : + createIndex(aIndex.row(), 0, (void*) getModelIndex(aIndex)) : QModelIndex(); } } else { @@ -704,7 +730,7 @@ QModelIndex PartSet_DocumentDataModel::objectIndex(const ObjectPtr theObject) co if (aPartModel) { QModelIndex aIndex = aPartModel->objectIndex(theObject); return aIndex.isValid() ? - createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) : + createIndex(aIndex.row(), 0, (void*) getModelIndex(aIndex)) : QModelIndex(); } } diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index 14308ab40..1f30ed2b2 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -33,6 +33,9 @@ PartSet_TopDataModel::~PartSet_TopDataModel() QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const { + if (theIndex.column() == 1) + return QVariant(); + switch (theRole) { case Qt::DisplayRole: // return a name @@ -243,7 +246,7 @@ QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const //****************************************************************** //****************************************************************** PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent) - : PartSet_PartModel(theParent) + : PartSet_PartModel(theParent), myHistoryBackOffset(0) { } @@ -253,6 +256,22 @@ PartSet_PartDataModel::~PartSet_PartDataModel() QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) const { + DocumentPtr aPartDoc = partDocument(); + if (theIndex.column() == 1) { + DocumentPtr aActiveDoc = ModelAPI_Session::get()->activeDocument(); + QModelIndex aParent = theIndex.parent(); + if (aActiveDoc == aPartDoc) { + if ((theIndex.internalId() == HistoryObject) && (!aParent.isValid())) { + switch (theRole) { + case Qt::DecorationRole: + if (theIndex.row() == lastHistoryRow()) + return QIcon(":pictures/arrow.png"); + } + } + } + return QVariant(); + } + switch (theRole) { case Qt::DisplayRole: // return a name @@ -272,8 +291,7 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c case GroupsFolder: return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(), - theIndex.row()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); if (aObject) { ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); @@ -284,25 +302,24 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c } break; case ConstructObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), - theIndex.row()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); if (aObject) return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); } break; case BodiesObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); if (aObject) return aObject->data()->name().c_str(); } break; case GroupObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultGroup::group(), theIndex.row()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultGroup::group(), theIndex.row()); if (aObject) return aObject->data()->name().c_str(); } case HistoryObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); if (aObject) return aObject->data()->name().c_str(); } @@ -325,7 +342,7 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c case BodiesObject: { std::string aGroup = theIndex.internalId() == ConstructObject ? ModelAPI_ResultConstruction::group() : ModelAPI_ResultBody::group(); - ObjectPtr anObject = partDocument()->object(aGroup, theIndex.row()); + ObjectPtr anObject = aPartDoc->object(aGroup, theIndex.row()); if (anObject && anObject->data() && anObject->data()->execState() == ModelAPI_StateMustBeUpdated) { return QIcon(":pictures/constr_object_modified.png"); @@ -333,7 +350,7 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c return QIcon(":pictures/constr_object.png"); } case HistoryObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); + ObjectPtr aObject = aPartDoc->object(ModelAPI_Feature::group(), theIndex.row() - getRowsNumber()); FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); if (aFeature) return PartSet_DocumentDataModel::featureIcon(aFeature); @@ -358,11 +375,6 @@ QVariant PartSet_PartDataModel::headerData(int section, Qt::Orientation orientat int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { - //DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - //if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) - // return 1; - //else - // return 0; DocumentPtr aDoc = partDocument(); if (aDoc.get()) { return getRowsNumber() + aDoc->size(ModelAPI_Feature::group()); @@ -370,14 +382,6 @@ int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const return 0; } switch (parent.internalId()) { - //case MyRoot: - // { - // DocumentPtr aDoc = partDocument(); - // if (aDoc) { - // return getRowsNumber() + aDoc->size(ModelAPI_Feature::group()); - // } else - // return 0; - // } case ParamsFolder: return partDocument()->size(ModelAPI_ResultParameter::group()); case ConstructFolder: @@ -392,13 +396,12 @@ int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const int PartSet_PartDataModel::columnCount(const QModelIndex &parent) const { - return 1; + return 2; } QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const { if (!theParent.isValid()) { - // return createIndex(theRow, 0, (qint32) MyRoot); switch (theRow) { case 0: return createIndex(theRow, theColumn, (qint32) ParamsFolder); @@ -420,25 +423,6 @@ QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModel } else { int aId = (int) theParent.internalId(); switch (aId) { - //case MyRoot: - // switch (theRow) { - // case 0: - // return createIndex(theRow, 0, (qint32) ParamsFolder); - // case 1: - // return createIndex(theRow, 0, (qint32) ConstructFolder); - // case 2: - // return createIndex(theRow, 0, (qint32) BodiesFolder); - // case 3: - // { - // int aSize = partDocument()->size(ModelAPI_ResultGroup::group()); - // if (aSize > 0) - // return createIndex(theRow, 0, (qint32) GroupsFolder); - // else - // return createIndex(theRow, theColumn, (qint32) HistoryObject); - // } - // default: - // return createIndex(theRow, theColumn, (qint32) HistoryObject); - // } case ParamsFolder: return createIndex(theRow, theColumn, (qint32) ParamObject); case ConstructFolder: @@ -455,24 +439,21 @@ QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModel QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { - //case MyRoot: - // return QModelIndex(); case ParamsFolder: case ConstructFolder: case BodiesFolder: case GroupsFolder: case HistoryObject: return QModelIndex(); - //return createIndex(0, 0, (qint32) MyRoot); case ParamObject: - return createIndex(0, theIndex.column(), (qint32) ParamsFolder); + return createIndex(0, 0, (qint32) ParamsFolder); case ConstructObject: - return createIndex(1, theIndex.column(), (qint32) ConstructFolder); + return createIndex(1, 0, (qint32) ConstructFolder); case BodiesObject: - return createIndex(2, theIndex.column(), (qint32) BodiesFolder); + return createIndex(2, 0, (qint32) BodiesFolder); case GroupObject: - return createIndex(3, theIndex.column(), (qint32) GroupsFolder); + return createIndex(3, 0, (qint32) GroupsFolder); } return QModelIndex(); } @@ -485,21 +466,15 @@ bool PartSet_PartDataModel::hasChildren(const QModelIndex& theParent) const DocumentPtr PartSet_PartDataModel::partDocument() const { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - //ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); ObjectPtr aObject = aRootDoc->object(ModelAPI_Feature::group(), myId); FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); ResultPartPtr aPart = std::dynamic_pointer_cast(aFeature->firstResult()); - //std::dynamic_pointer_cast(aObject); return aPart->partDoc(); } ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { - //case MyRoot: { - // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // return aRootDoc->object(ModelAPI_ResultPart::group(), myId); - //} case ParamsFolder: case ConstructFolder: case BodiesFolder: @@ -590,4 +565,9 @@ int PartSet_PartDataModel::getRowsNumber() const if (aSize == 0) // If there are no groups then do not show group folder return 3; return 4; -} \ No newline at end of file +} + +int PartSet_PartDataModel::lastHistoryRow() const +{ + return rowCount() - 1 - myHistoryBackOffset; +} diff --git a/src/PartSet/PartSet_PartDataModel.h b/src/PartSet/PartSet_PartDataModel.h index de1ef2274..6e6e47a76 100644 --- a/src/PartSet/PartSet_PartDataModel.h +++ b/src/PartSet/PartSet_PartDataModel.h @@ -171,6 +171,8 @@ Q_OBJECT //! Returns defult number of rows int getRowsNumber() const; + int lastHistoryRow() const; + //! Types of QModelIndexes enum DataIds { @@ -186,6 +188,7 @@ Q_OBJECT HistoryObject }; + int myHistoryBackOffset; }; #endif