X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_PartDataModel.cpp;h=fff14f9d4b0ae97eae84c6443eff4f5511391caa;hb=020e7187ee88afbd18286f149536cdef61d9f61e;hp=9265e983e874ba641d82964dc7558b253bbf0d04;hpb=d87cf0f183f8e92d99a060fe5ef2a06f607a4e11;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_PartDataModel.cpp b/src/PartSet/PartSet_PartDataModel.cpp index 9265e983e..fff14f9d4 100644 --- a/src/PartSet/PartSet_PartDataModel.cpp +++ b/src/PartSet/PartSet_PartDataModel.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -25,229 +26,6 @@ #include -PartSet_TopDataModel::PartSet_TopDataModel(QObject* theParent) - : PartSet_FeaturesModel(theParent) -{ -} - -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 - switch (theIndex.internalId()) { - case ParamsFolder: - return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); - case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); - if (aObject) { - ResultParameterPtr aParam = std::dynamic_pointer_cast(aObject); - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); - QString aVal = QString::number(aValueAttribute->value()); - QString aTitle = QString(aObject->data()->name().c_str()); - return aTitle + " = " + aVal; - } - } - break; - case ConstructFolder: - return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); - case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), - theIndex.row()); - if (aObject) - return aObject->data()->name().c_str(); - } - break; - //case GroupsFolder: - // return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); - //case GroupObject: { - // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultGroup::group(), - // theIndex.row()); - // if (aObject) - // return aObject->data()->name().c_str(); - //} - // break; - } - break; - - case Qt::DecorationRole: - { - // return an Icon - switch (theIndex.internalId()) { - case ParamsFolder: - return QIcon(":pictures/params_folder.png"); - case ConstructFolder: - return QIcon(":pictures/constr_folder.png"); - case ConstructObject: - return QIcon(":pictures/constr_object.png"); - //case GroupsFolder: - // return QIcon(":pictures/constr_folder.png"); - } - } - break; - - case Qt::ToolTipRole: - // return Tooltip - break; - case Qt::ForegroundRole: - return QBrush(myItemsColor); - break; - } - return QVariant(); -} - -QVariant PartSet_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - return QVariant(); -} - -int PartSet_TopDataModel::rowCount(const QModelIndex& theParent) const -{ - if (!theParent.isValid()) - return 2; // In case of groups using it has to be +1 - - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - if (theParent.internalId() == ParamsFolder) - return aRootDoc->size(ModelAPI_ResultParameter::group()); - - if (theParent.internalId() == ConstructFolder) - return aRootDoc->size(ModelAPI_ResultConstruction::group()); - - //if (theParent.internalId() == GroupsFolder) - // return aRootDoc->size(ModelAPI_ResultGroup::group()); - - return 0; -} - -int PartSet_TopDataModel::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -QModelIndex PartSet_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const -{ - if (!theParent.isValid()) { - switch (theRow) { - case 0: - return createIndex(theRow, theColumn, (qint32) ParamsFolder); - case 1: - return createIndex(theRow, theColumn, (qint32) ConstructFolder); - //case 2: - // return createIndex(theRow, theColumn, (qint32) GroupsFolder); - } - } else { - if (theParent.internalId() == ParamsFolder) - return createIndex(theRow, theColumn, (qint32) ParamObject); - - if (theParent.internalId() == ConstructFolder) - return createIndex(theRow, theColumn, (qint32) ConstructObject); - - //if (theParent.internalId() == GroupsFolder) - // return createIndex(theRow, theColumn, (qint32) GroupObject); - } - return QModelIndex(); -} - -QModelIndex PartSet_TopDataModel::parent(const QModelIndex& theIndex) const -{ - int aId = (int) theIndex.internalId(); - switch (aId) { - case ParamsFolder: - case ConstructFolder: - //case GroupsFolder: - return QModelIndex(); - case ParamObject: - return createIndex(0, 0, (qint32) ParamsFolder); - case ConstructObject: - return createIndex(1, 0, (qint32) ConstructFolder); - //case GroupObject: - // return createIndex(2, 0, (qint32) GroupsFolder); - } - return QModelIndex(); -} - -bool PartSet_TopDataModel::hasChildren(const QModelIndex& theParent) const -{ - return rowCount(theParent) > 0; -} - -ObjectPtr PartSet_TopDataModel::object(const QModelIndex& theIndex) const -{ - switch (theIndex.internalId()) { - case ParamsFolder: - case ConstructFolder: - return ObjectPtr(); - case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); - } - case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - } - //case GroupObject: { - // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - // return aRootDoc->object(ModelAPI_ResultGroup::group(), theIndex.row()); - //} - } - return ObjectPtr(); -} - -QModelIndex PartSet_TopDataModel::findParent(const ObjectPtr& theObject) const -{ - return findGroup(theObject->groupName().c_str()); -} - -QModelIndex PartSet_TopDataModel::findGroup(const std::string& theGroup) const -{ - if (theGroup == ModelAPI_ResultParameter::group()) - return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup == ModelAPI_ResultConstruction::group()) - return createIndex(1, 0, (qint32) ConstructFolder); - //if (theGroup == ModelAPI_ResultGroup::group()) - // return createIndex(2, 0, (qint32) ConstructFolder); - return QModelIndex(); -} - -QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const -{ - QModelIndex aIndex; - if (theObject) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - std::string aGroup = theObject->groupName(); - int aNb = aRootDoc->size(aGroup); - int aRow = -1; - for (int i = 0; i < aNb; i++) { - if (aRootDoc->object(aGroup, i) == theObject) { - aRow = i; - break; - } - } - if (aRow != -1) { - if (aGroup == ModelAPI_ResultParameter::group()) - return createIndex(aRow, 0, (qint32) ParamObject); - if (aGroup == ModelAPI_ResultConstruction::group()) - return createIndex(aRow, 0, (qint32) ConstructObject); - //if (aGroup == ModelAPI_ResultGroup::group()) - // return createIndex(aRow, 0, (qint32) GroupObject); - } - } - return aIndex; -} - -//****************************************************************** -//****************************************************************** -//****************************************************************** PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent) : PartSet_PartModel(theParent) { @@ -275,6 +53,25 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c return QVariant(); } + if (theIndex.internalId() >= 0) { + ObjectPtr aObj = object(theIndex); + switch (theRole) { + case Qt::DisplayRole: + return aObj->data()->name().c_str(); + case Qt::DecorationRole: + { + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature) + return PartSet_DocumentDataModel::featureIcon(aFeature); + } + break; + case Qt::ForegroundRole: + if (theIndex.internalId() > lastHistoryRow()) + return QBrush(Qt::lightGray); + return QBrush(myItemsColor); + } + } + switch (theRole) { case Qt::DisplayRole: // return a name @@ -343,12 +140,19 @@ QVariant PartSet_PartDataModel::data(const QModelIndex& theIndex, int theRole) c case ConstructObject: case GroupObject: case BodiesObject: { - std::string aGroup = theIndex.internalId() == ConstructObject ? - ModelAPI_ResultConstruction::group() : ModelAPI_ResultBody::group(); - ObjectPtr anObject = aPartDoc->object(aGroup, theIndex.row()); - if (anObject && anObject->data() && - anObject->data()->execState() == ModelAPI_StateMustBeUpdated) { - return QIcon(":pictures/constr_object_modified.png"); + std::string aGroup; + if (theIndex.internalId() == ConstructObject) + aGroup = ModelAPI_ResultConstruction::group(); + else if (theIndex.internalId() == BodiesObject) + aGroup = ModelAPI_ResultBody::group(); + else if (theIndex.internalId() == GroupObject) + aGroup = ModelAPI_ResultGroup::group(); + if (aGroup.length() > 0) { + ObjectPtr anObject = aPartDoc->object(aGroup, theIndex.row()); + if (anObject && anObject->data() && + anObject->data()->execState() == ModelAPI_StateMustBeUpdated) { + return QIcon(":pictures/constr_object_modified.png"); + } } return QIcon(":pictures/constr_object.png"); } @@ -396,6 +200,15 @@ int PartSet_PartDataModel::rowCount(const QModelIndex& parent) const return partDocument()->size(ModelAPI_ResultBody::group()); case GroupsFolder: return partDocument()->size(ModelAPI_ResultGroup::group()); + case HistoryObject: + { + ObjectPtr aObj = object(parent); + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(aObj); + if (aCompFeature.get()) { + return aCompFeature->numberOfSubs(true); + } + } } return 0; } @@ -437,6 +250,10 @@ QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModel return createIndex(theRow, theColumn, (qint32) BodiesObject); case GroupsFolder: return createIndex(theRow, theColumn, (qint32) GroupObject); + case HistoryObject: + { + return createIndex(theRow, theColumn, (qint32) theParent.row()); + } } } return QModelIndex(); @@ -444,6 +261,10 @@ QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModel QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const { + if (theIndex.internalId() >= 0) { + int aPRow = theIndex.internalId(); + return createIndex(aPRow, 0, (qint32) HistoryObject); + } switch (theIndex.internalId()) { case ParamsFolder: case ConstructFolder: @@ -479,6 +300,17 @@ DocumentPtr PartSet_PartDataModel::partDocument() const ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const { + if (theIndex.internalId() >= 0) { + int aPRow = theIndex.internalId(); + ObjectPtr aObj = + partDocument()->object(ModelAPI_Feature::group(), aPRow - getRowsNumber()); + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(aObj); + if (aCompFeature.get()) { + return aCompFeature->subFeature(theIndex.row(), true); + } + return ObjectPtr(); + } switch (theIndex.internalId()) { case ParamsFolder: case ConstructFolder: @@ -577,12 +409,6 @@ int PartSet_PartDataModel::lastHistoryRow() const void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex) { - // the viewer update should be blocked in order to avoid the features blinking before they are - // hidden - std::shared_ptr aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED))); - Events_Loop::loop()->send(aMsg); - SessionPtr aMgr = ModelAPI_Session::get(); DocumentPtr aDoc = partDocument(); std::string aOpName = tr("History change").toStdString(); @@ -596,12 +422,6 @@ void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex) aDoc->setCurrentFeature(FeaturePtr(), true); aMgr->finishOperation(); } - // the viewer update should be unblocked in order to avoid the features blinking before they are - // hidden - aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED))); - - Events_Loop::loop()->send(aMsg); } QModelIndex PartSet_PartDataModel::lastHistoryItem() const @@ -611,10 +431,15 @@ QModelIndex PartSet_PartDataModel::lastHistoryItem() const Qt::ItemFlags PartSet_PartDataModel::flags(const QModelIndex& theIndex) const { + // Disable sub-features at column 1 + if ((theIndex.column() == 1) && (theIndex.internalId() >= 0)) + return 0; + Qt::ItemFlags aFlags = Qt::ItemIsSelectable; if (object(theIndex)) { aFlags |= Qt::ItemIsEditable; } + if (theIndex.internalId() == HistoryObject) { if (theIndex.row() <= lastHistoryRow() || (theIndex.column() == 1)) aFlags |= Qt::ItemIsEnabled;