//******************************************************************
//******************************************************************
PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
- : PartSet_PartModel(theParent), myHistoryBackOffset(0)
+ : PartSet_PartModel(theParent)
{
}
DocumentPtr aActiveDoc = ModelAPI_Session::get()->activeDocument();
QModelIndex aParent = theIndex.parent();
if (aActiveDoc == aPartDoc) {
- if ((theIndex.internalId() == HistoryObject) && (!aParent.isValid())) {
+ if (!aParent.isValid()) {
switch (theRole) {
case Qt::DecorationRole:
if (theIndex.row() == lastHistoryRow())
// return Tooltip
break;
case Qt::ForegroundRole:
+ if (theIndex.internalId() == HistoryObject) {
+ if (theIndex.row() > lastHistoryRow())
+ return QBrush(Qt::lightGray);
+ }
return QBrush(myItemsColor);
- break;
}
return QVariant();
}
int PartSet_PartDataModel::lastHistoryRow() const
{
- return rowCount() - 1 - myHistoryBackOffset;
+ DocumentPtr aDoc = partDocument();
+ FeaturePtr aFeature = aDoc->currentFeature();
+ if (aFeature.get())
+ return getRowsNumber() + aDoc->index(aFeature);
+ else
+ return getRowsNumber() - 1;
+}
+
+void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = partDocument();
+ std::string aOpName = tr("History change").toStdString();
+ if (theIndex.internalId() == HistoryObject) {
+ ObjectPtr aObject = object(theIndex);
+ aMgr->startOperation(aOpName);
+ aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+ aMgr->finishOperation();
+ } else {
+ aMgr->startOperation(aOpName);
+ aDoc->setCurrentFeature(FeaturePtr());
+ aMgr->finishOperation();
+ }
+}
+
+QModelIndex PartSet_PartDataModel::lastHistoryItem() const
+{
+ return index(lastHistoryRow(), 1);
+}
+
+Qt::ItemFlags PartSet_PartDataModel::flags(const QModelIndex& theIndex) const
+{
+ 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;
+ } else
+ aFlags |= Qt::ItemIsEnabled;
+ return aFlags;
}