#include <ModelAPI_Iterator.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <QIcon>
-XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
+XGUI_TopDataModel::XGUI_TopDataModel(const boost::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+ : XGUI_FeaturesModel(theDocument, theParent)
{
}
switch (theRole) {
case Qt::DisplayRole:
// return a name
- if (theIndex.model() == this) {
- if (theIndex.internalId() == ParamsFolder)
- return tr("Parameters");
-
- if (theIndex.internalId() == ParamObject) {
- std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
+ return tr("Parameters");
+ case ParamObject:
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
- if (theIndex.internalId() == ConstructFolder)
+ case ConstructFolder:
return tr("Constructions");
-
- if (theIndex.internalId() == ConstructObject) {
- std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ case ConstructObject:
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
- }
+ }
break;
case Qt::DecorationRole:
// return an Icon
- if (theIndex.model() == this) {
- if (theIndex.internalId() == ParamsFolder)
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
return QIcon(":pictures/params_folder.png");
- else if (theIndex.internalId() == ConstructFolder)
+ case ConstructFolder:
return QIcon(":pictures/constr_folder.png");
+ case ConstructObject:
+ return QIcon(":pictures/point_ico.png");
}
break;
if (!theParent.isValid()) {
switch (theRow) {
case 0:
- return createIndex(theRow, theColumn, (quintptr) ParamsFolder);
+ return createIndex(theRow, theColumn, (qint32) ParamsFolder);
case 1:
- return createIndex(theRow, theColumn, (quintptr) ConstructFolder);
+ return createIndex(theRow, theColumn, (qint32) ConstructFolder);
}
} else {
if (theParent.internalId() == ParamsFolder)
- return createIndex(theRow, theColumn, (quintptr) ParamObject);
+ return createIndex(theRow, theColumn, (qint32) ParamObject);
if (theParent.internalId() == ConstructFolder)
- return createIndex(theRow, theColumn, (quintptr) ConstructObject);
+ return createIndex(theRow, theColumn, (qint32) ConstructObject);
}
return QModelIndex();
}
case ConstructFolder:
return QModelIndex();
case ParamObject:
- return createIndex(0, 0, (quintptr) ParamsFolder);
+ return createIndex(0, 0, (qint32) ParamsFolder);
case ConstructObject:
- return createIndex(1, 0, (quintptr) ConstructFolder);
+ return createIndex(1, 0, (qint32) ConstructFolder);
}
return QModelIndex();
}
bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
{
- if (!theParent.isValid())
- return true;
+ return rowCount(theParent) > 0;
+}
- int aId = (int)theParent.internalId();
- switch (aId) {
+FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
case ParamsFolder:
- return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
case ConstructFolder:
- return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
+ return FeaturePtr();
case ParamObject:
+ return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
case ConstructObject:
- return false;
- }
- return false;
+ return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ }
+ return FeaturePtr();
+}
+
+
+QModelIndex XGUI_TopDataModel::findParent(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+ QString aGroup(theFeature->getGroup().c_str());
+
+ if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ return QModelIndex();
+}
+
+QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
+{
+ if (theGroup.compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ return QModelIndex();
}
//******************************************************************
//******************************************************************
//******************************************************************
-XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
+XGUI_PartDataModel::XGUI_PartDataModel(const boost::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+ : XGUI_PartModel(theDocument, theParent)
{
}
switch (theRole) {
case Qt::DisplayRole:
// return a name
- if (theIndex.internalId() == MyRoot) {
- std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
- return aFeature->data()->getName().c_str();
- }
- if (theIndex.internalId() == ParamsFolder)
+ switch (theIndex.internalId()) {
+ case MyRoot:
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
+ }
+ case ParamsFolder:
return tr("Parameters");
- if (theIndex.internalId() == ConstructFolder)
+ case ConstructFolder:
return tr("Constructions");
+ case ParamObject:
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature =
+ featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
+ }
+ case ConstructObject:
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature =
+ featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
+ }
+ }
break;
case Qt::DecorationRole:
// return an Icon
- if (theIndex.internalId() == MyRoot)
+ switch (theIndex.internalId()) {
+ case MyRoot:
return QIcon(":pictures/part_ico.png");
- if (theIndex.internalId() == ParamsFolder)
+ case ParamsFolder:
return QIcon(":pictures/params_folder.png");
- if (theIndex.internalId() == ConstructFolder)
+ case ConstructFolder:
return QIcon(":pictures/constr_folder.png");
+ case ConstructObject:
+ return QIcon(":pictures/point_ico.png");
+ }
break;
case Qt::ToolTipRole:
// return Tooltip
return 1;
else
return 0;
- if (parent.internalId() == MyRoot)
- return 2;
+ switch (parent.internalId()) {
+ case MyRoot:
+ return 2;
+ case ParamsFolder:
+ return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
+ case ConstructFolder:
+ return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
+ }
return 0;
}
QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
{
if (!theParent.isValid())
- return createIndex(theRow, 0, (quintptr) MyRoot);
+ return createIndex(theRow, 0, (qint32) MyRoot);
int aId = (int)theParent.internalId();
switch (aId) {
case MyRoot:
switch (theRow) {
case 0:
- return createIndex(0, 0, (quintptr) ParamsFolder);
+ return createIndex(0, 0, (qint32) ParamsFolder);
case 1:
- return createIndex(1, 0, (quintptr) ConstructFolder);
+ return createIndex(1, 0, (qint32) ConstructFolder);
}
case ParamsFolder:
- return createIndex(theRow, 0, (quintptr) ParamObject);
+ return createIndex(theRow, 0, (qint32) ParamObject);
case ConstructFolder:
- return createIndex(theRow, 0, (quintptr) ConstructObject);
+ return createIndex(theRow, 0, (qint32) ConstructObject);
}
return QModelIndex();
}
QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
{
- int aId = (int)theIndex.internalId();
- switch (aId) {
+ switch (theIndex.internalId()) {
case MyRoot:
return QModelIndex();
case ParamsFolder:
case ConstructFolder:
- return createIndex(0, 0, (quintptr) MyRoot);
+ return createIndex(0, 0, (qint32) MyRoot);
case ParamObject:
- return createIndex(0, 0, (quintptr) ParamsFolder);
+ return createIndex(0, 0, (qint32) ParamsFolder);
case ConstructObject:
- return createIndex(1, 0, (quintptr) ConstructFolder);
+ return createIndex(1, 0, (qint32) ConstructFolder);
}
return QModelIndex();
}
bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
{
- if (!theParent.isValid())
- return myDocument->feature(PARTS_GROUP, myId);
+ return rowCount(theParent) > 0;
+}
- int aId = (int)theParent.internalId();
- switch (aId) {
+
+boost::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
+{
+ boost::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
+ return aFeature->data()->docRef("PartDocument")->value();
+}
+
+FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
case MyRoot:
- return true;
+ return myDocument->feature(PARTS_GROUP, myId);
case ParamsFolder:
- return false; // TODO
case ConstructFolder:
- return false; // TODO
+ return FeaturePtr();
case ParamObject:
+ return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
case ConstructObject:
- return false;
+ return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
}
- return false;
+ return FeaturePtr();
+}
+
+bool XGUI_PartDataModel::hasDocument(const boost::shared_ptr<ModelAPI_Document>& theDoc) const
+{
+ return (featureDocument() == theDoc);
+}
+
+
+QModelIndex XGUI_PartDataModel::findParent(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+ QString aGroup(theFeature->getGroup().c_str());
+
+ if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ return QModelIndex();
+}
+
+QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
+{
+ if (theGroup.compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ return QModelIndex();
}