{
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+
// Created object event *******************
if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this);
int anId = aRootDoc->index(aPartFeature);
aModel->setPartId(anId);
- //aModel->setPartId(aRootDoc->index(aObject));
myPartModels[anId] = aModel;
insertRow(aStart, partFolderNode(0));
}
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<ModelAPI_Feature>(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();
}
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) {
}
break;
}
- QModelIndex aParent = theIndex.parent();
if (aParent.internalId() == HistoryNode) {
int aId = aParent.row() - historyOffset();
QModelIndex* aIndex = toSourceModelIndex(theIndex);
int PartSet_DocumentDataModel::columnCount(const QModelIndex& theParent) const
{
- return 1;
+ return 2;
}
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 {
return QModelIndex();
if (theIndex.internalId() == PartResult)
- return partFolderNode(theIndex.column());
+ return partFolderNode(0);
QModelIndex* aIndex = toSourceModelIndex(theIndex);
const QAbstractItemModel* aModel = aIndex->model();
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;
}
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;
}
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 {
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();
}
}
QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
{
+ if (theIndex.column() == 1)
+ return QVariant();
+
switch (theRole) {
case Qt::DisplayRole:
// return a name
//******************************************************************
//******************************************************************
PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
- : PartSet_PartModel(theParent)
+ : PartSet_PartModel(theParent), myHistoryBackOffset(0)
{
}
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
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<ModelAPI_ResultParameter>(aObject);
AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
}
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<ModelAPI_Object>(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();
}
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");
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<ModelAPI_Feature>(aObject);
if (aFeature)
return PartSet_DocumentDataModel::featureIcon(aFeature);
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());
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:
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);
} 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:
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();
}
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<ModelAPI_ResultPart>(aFeature->firstResult());
- //std::dynamic_pointer_cast<ModelAPI_ResultPart>(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:
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;
+}