- SessionPtr aSession = ModelAPI_Session::get();
- DocumentPtr aRootDoc = aSession->moduleDocument();
- int aNbFolders = foldersCount();
- int theIndexRow = theIndex.row();
-
- if (theRole == Qt::DecorationRole) {
- if (theIndex == lastHistoryIndex())
- return QIcon(":pictures/arrow.png");
- else if (theIndex.column() == 0) {
- VisibilityState aState = getVisibilityState(theIndex);
- switch (aState) {
- case NoneState:
- return QIcon();
- case Visible:
- return QIcon(":pictures/eyeopen.png");
- case SemiVisible:
- return QIcon(":pictures/eyemiclosed.png");
- case Hidden:
- return QIcon(":pictures/eyeclosed.png");
- }
- }
- }
-
- //if (theIndex.column() == 1)
- if (theIndex.column() != 1)
- return QVariant();
-
- quintptr aParentId = theIndex.internalId();
- if (aParentId == 0) { // root folders
- switch (theRole) {
- case Qt::DisplayRole:
- return QString(myXMLReader->rootFolderName(theIndexRow).c_str()) +
- QString(" (%1)").arg(rowCount(theIndex));
- case Qt::DecorationRole:
- return QIcon(myXMLReader->rootFolderIcon(theIndexRow).c_str());
- case Qt::ForegroundRole:
- {
- Qt::ItemFlags aFlags = theIndex.flags();
- if (aFlags == Qt::ItemFlags())
- return QBrush(DISABLED_COLOR);
- if (!aFlags.testFlag(Qt::ItemIsEditable))
- return QBrush(SELECTABLE_COLOR);
- }
- return ACTIVE_COLOR;
- }
- } else { // an object or sub-document
- if (theRole == Qt::ForegroundRole) {
- Qt::ItemFlags aFlags = theIndex.flags();
- if (aFlags == Qt::ItemFlags())
- return QBrush(DISABLED_COLOR);
- if (!aFlags.testFlag(Qt::ItemIsEditable))
- return QBrush(SELECTABLE_COLOR);
- return ACTIVE_COLOR;
- }
-
- ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
- if (aSubDoc) { // this is a folder of sub document
- QIntList aMissedIdx = missedFolderIndexes(aSubDoc);
- int aRow = theIndexRow;
- while (aMissedIdx.contains(aRow))
- aRow++;
- if (aRow < myXMLReader->subFoldersNumber()) {
- switch (theRole) {
- case Qt::DisplayRole:
- return QString(myXMLReader->subFolderName(aRow).c_str()) +
- QString(" (%1)").arg(rowCount(theIndex));
- case Qt::DecorationRole:
- return QIcon(myXMLReader->subFolderIcon(aRow).c_str());
- }
- }
- } else {
- ModelAPI_Object* aObj =
- dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
- if (aObj) {
- switch (theRole) {
- case Qt::DisplayRole:
- {
- if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
- ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
- AttributeDoublePtr aValueAttribute =
- aParam->data()->real(ModelAPI_ResultParameter::VALUE());
- QString aVal = QString::number(aValueAttribute->value());
- QString aTitle = QString(aObj->data()->name().c_str());
- return aTitle + " = " + aVal;
- }
- QString aSuffix;
- if (aObj->groupName() == myXMLReader->subType()) {
- ResultPartPtr aPartRes = getPartResult(aObj);
- if (aPartRes.get()) {
- if (aPartRes->partDoc().get() == NULL)
- aSuffix = " (Not loaded)";
- }
- }
- return aObj->data()->name().c_str() + aSuffix;
- }
- case Qt::DecorationRole:
- return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
- }
- } else {
- switch (theRole) {
- case Qt::DisplayRole:
- {
- ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
- dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
- ((ModelAPI_Entity*)theIndex.internalPointer());
- if (aStep) {
- return "Step " + QString::number(aStep->id() + 1) + " " +
- aStep->field()->textLine(aStep->id()).c_str();
- }
- }
- break;
- }
- }
- }