/// Constructor
/// \param theParent a parent object
PartSet_PartModel(QObject* theParent)
- : PartSet_FeaturesModel(theParent)
+ : PartSet_FeaturesModel(theParent), myId(-1)
{
}
myId = theId;
}
+ /// Returns Id of the part
+ int partId() const { return myId; }
+
//! Returns true if the given document is a sub-document of this tree
//! \param theDoc a document to check
virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
#include <ModuleBase_Tools.h>
#include <ModuleBase_ActionInfo.h>
+#include <PartSetPlugin_Part.h>
+
#include <QIcon>
#include <QString>
#include <QBrush>
PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent)
: ModuleBase_IDocumentDataModel(theParent),
- myActivePart(0), myHistoryBackOffset(0)
+ myActivePartId(-1), myHistoryBackOffset(0)
{
// Create a top part of data tree model
myModel = new PartSet_TopDataModel(this);
if (aDoc == aRootDoc) { // If root objects
if (aObject->groupName() == ModelAPI_ResultPart::group()) { // Update only Parts group
// Add a new part
- int aStart = myPartModels.size();
- PartSet_PartDataModel* aModel = new PartSet_PartDataModel(this);
- aModel->setPartId(myPartModels.count());
- myPartModels.append(aModel);
- insertRow(aStart, partFolderNode(0));
+ int aStart = aRootDoc->size(ModelAPI_ResultPart::group());
+ if (aStart > 0) {
+ FeaturePtr aPartFeature = ModelAPI_Feature::feature(aObject);
+ 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));
+ }
} else { // Update top groups (other except parts
QModelIndex aIndex = myModel->findParent(aObject);
int aStart = myModel->rowCount(aIndex) - 1;
std::string aGroup = (*aIt);
if (aDoc == aRootDoc) { // If root objects
if (aGroup == ModelAPI_ResultPart::group()) { // Update only Parts group
- int aStart = myPartModels.size() - 1;
- if (aStart >= 0) {// MPV: this could be reproduced on close
- removeSubModel(aStart);
- removeRow(aStart, partFolderNode(0));
- if (myActivePart && (!isPartSubModel(myActivePart))) {
- myActivePart = 0;
- myActivePartIndex = QModelIndex();
- myModel->setItemsColor(ACTIVE_COLOR);
+ ObjectPtr aObj;
+ FeaturePtr aFeature;
+ int aDelId = -1;
+ foreach (int aId, myPartModels.keys()) {
+ aObj = aDoc->object(ModelAPI_Feature::group(), aId);
+ if (aObj.get()) {
+ aFeature = ModelAPI_Feature::feature(aObj);
+ if (aFeature.get()) {
+ if (aFeature->getKind() == PartSetPlugin_Part::ID())
+ continue;
+ }
}
+ aDelId = aId;
+ break;
+ }
+ if (aDelId != -1) {
+ deactivatePart();
+ int aStart = myPartModels.size() - 1;
+ removeSubModel(aDelId);
+ removeRow(aStart, partFolderNode(0));
}
} else { // Update top groups (other except parts
QModelIndex aIndex = myModel->findGroup(aGroup);
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);
- }
+ //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);
+ //}
endResetModel();
}
{
if (!theIndex.isValid())
return QVariant();
- QModelIndex aParent = theIndex.parent();
- 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();
- }
+ //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();
switch (theIndex.internalId()) {
case PartsFolder:
switch (theRole) {
case Qt::ToolTipRole:
return tr("Parts folder");
case Qt::ForegroundRole:
- if (myActivePart)
+ if (myActivePartIndex.isValid())
return QBrush(PASSIVE_COLOR);
else
return QBrush(ACTIVE_COLOR);
case HistoryNode:
{
int aOffset = historyOffset();
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
if (!aFeature)
if (theIndex.row() > lastHistoryRow())
return QBrush(Qt::lightGray);
else {
- if (myActivePart)
+ if (myActivePartIndex.isValid())
return QBrush(PASSIVE_COLOR);
else
return QBrush(ACTIVE_COLOR);
}
}
break;
+ case PartResult:
+ {
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), theIndex.row());
+ if (aObject) {
+ switch (theRole) {
+ case Qt::DisplayRole:
+ return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
+ case Qt::DecorationRole:
+ return QIcon(":pictures/part_ico.png");
+ case Qt::ForegroundRole:
+ {
+ if (theIndex == myActivePartIndex)
+ return QBrush(ACTIVE_COLOR);
+ else
+ return QBrush(PASSIVE_COLOR);
+ }
+ default:
+ return QVariant();
+ }
+ }
+ }
+ break;
}
- if (aParent.isValid() && (aParent.internalId() == PartsFolder)) {
- return myPartModels.at(theIndex.row())->data(QModelIndex(), theRole);
+ QModelIndex aParent = theIndex.parent();
+ if (aParent.internalId() == HistoryNode) {
+ int aId = aParent.row() - historyOffset();
+ QModelIndex* aIndex = toSourceModelIndex(theIndex);
+ return myPartModels[aId]->data(*aIndex, theRole);
}
return toSourceModelIndex(theIndex)->data(theRole);
}
int PartSet_DocumentDataModel::rowCount(const QModelIndex& theParent) const
{
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
if (!theParent.isValid()) {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
// Size of external models
int aVal = historyOffset();
// Plus history size
return aVal;
}
if (theParent.internalId() == PartsFolder) {
- int aSize = myPartModels.size();
- return myPartModels.size();
+ return aRootDoc->size(ModelAPI_ResultPart::group());
+ //int aSize = myPartModels.size();
+ //return myPartModels.size();
}
if (theParent.internalId() == HistoryNode) {
+ int aId = theParent.row() - historyOffset();
+ if (myPartModels.contains(aId))
+ return myPartModels[aId]->rowCount(QModelIndex());
return 0;
}
+ if (theParent.internalId() == PartResult)
+ return 0;
+
QModelIndex* aParent = toSourceModelIndex(theParent);
const QAbstractItemModel* aModel = aParent->model();
if (!isSubModel(aModel))
} else {
if (theRow == aOffs) // Create Parts node
aIndex = partFolderNode(theColumn);
- else
- // create history node
+ else {
+ // create history node or a part sub-tree
+ int aId = theRow - historyOffset();
aIndex = createIndex(theRow, theColumn, HistoryNode);
+ //if (myPartModels.contains(aId)) {
+ // aIndex = myPartModels[aId]->index(theRow, theColumn, QModelIndex());
+ //}
+ }
}
} else {
if (theParent.internalId() == PartsFolder) {
- aIndex = myPartModels.at(theRow)->index(0, theColumn, QModelIndex());
- } else {
- QModelIndex* aParent = (QModelIndex*) theParent.internalPointer();
- aIndex = aParent->model()->index(theRow, theColumn, (*aParent));
+ aIndex = createIndex(theRow, theColumn, PartResult);
+ } else {
+ if (theParent.internalId() == HistoryNode) {
+ int aId = theParent.row() - historyOffset();
+ aIndex = myPartModels[aId]->index(theRow, theColumn, QModelIndex());
+ } else {
+ QModelIndex* aParent = (QModelIndex*) theParent.internalPointer();
+ aIndex = aParent->model()->index(theRow, theColumn, (*aParent));
+ }
+ aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex));
}
- aIndex = createIndex(theRow, theColumn, (void*) getModelIndex(aIndex));
}
return aIndex;
}
if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
return QModelIndex();
+ if (theIndex.internalId() == PartResult)
+ return partFolderNode(theIndex.column());
+
QModelIndex* aIndex = toSourceModelIndex(theIndex);
const QAbstractItemModel* aModel = aIndex->model();
if (!isSubModel(aModel))
return QModelIndex();
- if (isPartSubModel(aModel)) {
- if (!aModel->parent(*aIndex).isValid()) {
- return partFolderNode(theIndex.column());
- }
+ QModelIndex aIndex1 = aModel->parent(*aIndex);
+ if (isPartSubModel(aModel) && (!aIndex1.isValid())) {
+ int aId = myPartModels.key((PartSet_PartModel*) aModel);
+ int aRow = aId + historyOffset();
+ return createIndex(aRow, theIndex.column(), (qint32) HistoryNode);
}
- QModelIndex aIndex1 = aModel->parent(*aIndex);
if (aIndex1.isValid())
return createIndex(aIndex1.row(), aIndex1.column(), (void*) getModelIndex(aIndex1));
return aIndex1;
{
if (theIndex.internalId() == PartsFolder)
return ObjectPtr();
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
if (theIndex.internalId() == HistoryNode) {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
int aOffset = historyOffset();
return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
}
+ if (theIndex.internalId() == PartResult) {
+ return aRootDoc->object(ModelAPI_ResultPart::group(), theIndex.row());
+ }
QModelIndex* aIndex = toSourceModelIndex(theIndex);
if (!isSubModel(aIndex->model()))
return ObjectPtr();
void PartSet_DocumentDataModel::removeSubModel(int theModelId)
{
- PartSet_PartModel* aModel = myPartModels.at(theModelId);
+ PartSet_PartModel* aModel = myPartModels[theModelId];
QIntList aToRemove;
for (int i = 0; i < myIndexes.size(); i++) {
if (myIndexes.at(i)->model() == aModel)
aToRemove.removeLast();
}
delete aModel;
- myPartModels.removeAt(theModelId);
+ myPartModels.remove(theModelId);
}
bool PartSet_DocumentDataModel::isSubModel(const QAbstractItemModel* theModel) const
bool PartSet_DocumentDataModel::isPartSubModel(const QAbstractItemModel* theModel) const
{
- return myPartModels.contains((PartSet_PartModel*) theModel);
+ return myPartModels.key((PartSet_PartModel*) theModel, -1) != -1;
}
QModelIndex PartSet_DocumentDataModel::partFolderNode(int theColumn) const
if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
return false;
- QModelIndex* aIndex = toSourceModelIndex(theIndex);
- if (!aIndex)
- return false;
-
- const QAbstractItemModel* aModel = aIndex->model();
-
- if (isPartSubModel(aModel)) {
- // if this is root node (Part item index)
- if (!aIndex->parent().isValid()) {
- if (myActivePart)
- myActivePart->setItemsColor(PASSIVE_COLOR);
-
- if (myActivePart == aModel) {
- myActivePart = 0;
- myActivePartIndex = QModelIndex();
- } else {
- myActivePart = (PartSet_PartModel*)aModel;
- myActivePartIndex = theIndex;
- }
-
- if (myActivePart) {
- myActivePart->setItemsColor(ACTIVE_COLOR);
- myModel->setItemsColor(PASSIVE_COLOR);
- } else
- myModel->setItemsColor(ACTIVE_COLOR);
- return true;
- }
- }
- return false;
+ if (theIndex.isValid() && (theIndex.internalId() == PartResult)) {
+ myActivePartIndex = theIndex;
+ myModel->setItemsColor(PASSIVE_COLOR);
+ if (myActivePartId != -1)
+ myPartModels[myActivePartId]->setItemsColor(PASSIVE_COLOR);
+
+ // Find activated part feature by its ID
+ ResultPartPtr aPartRes = activePart();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aPartRes);
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ myActivePartId = aRootDoc->index(aFeature);
+ myPartModels[myActivePartId]->setItemsColor(ACTIVE_COLOR);
+ }
+ //QModelIndex* aIndex = toSourceModelIndex(theIndex);
+ //if (!aIndex)
+ // return false;
+
+ //const QAbstractItemModel* aModel = aIndex->model();
+
+ //if (isPartSubModel(aModel)) {
+ // // if this is root node (Part item index)
+ // if (!aIndex->parent().isValid()) {
+ // if (myActivePart)
+ // myActivePart->setItemsColor(PASSIVE_COLOR);
+
+ // if (myActivePart == aModel) {
+ // myActivePart = 0;
+ // myActivePartIndex = QModelIndex();
+ // } else {
+ // myActivePart = (PartSet_PartModel*)aModel;
+ // myActivePartIndex = theIndex;
+ // }
+
+ // if (myActivePart) {
+ // myActivePart->setItemsColor(ACTIVE_COLOR);
+ // myModel->setItemsColor(PASSIVE_COLOR);
+ // } else
+ // myModel->setItemsColor(ACTIVE_COLOR);
+ // return true;
+ // }
+ // }
+ return true;
}
ResultPartPtr PartSet_DocumentDataModel::activePart() const
{
- if (myActivePart)
- return myActivePart->part();
+ if (myActivePartIndex.isValid()) {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myActivePartIndex.row());
+ return std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ }
return ResultPartPtr();
}
+QModelIndex PartSet_DocumentDataModel::activePartTree() const
+{
+ if (myActivePartId != -1) {
+ return createIndex(myActivePartId + historyOffset(), 0, HistoryNode);
+ }
+ return QModelIndex();
+}
+
void PartSet_DocumentDataModel::deactivatePart()
{
- if (myActivePart)
- myActivePart->setItemsColor(PASSIVE_COLOR);
- myActivePart = 0;
+ if (myActivePartIndex.isValid()) {
+ if (myActivePartId != -1)
+ myPartModels[myActivePartId]->setItemsColor(PASSIVE_COLOR);
+ myActivePartId = -1;
myActivePartIndex = QModelIndex();
myModel->setItemsColor(ACTIVE_COLOR);
}
+}
Qt::ItemFlags PartSet_DocumentDataModel::flags(const QModelIndex& theIndex) const
{
QModelIndex PartSet_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const
{
- int aRow = -1;
- PartSet_PartModel* aModel = 0;
- foreach (PartSet_PartModel* aPartModel, myPartModels)
- {
- aRow++;
- if (aPartModel->part() == theObject) {
- aModel = aPartModel;
- break;
- }
- }
- if (aModel) {
- return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex())));
+ //int aRow = -1;
+ //PartSet_PartModel* aModel = 0;
+ //foreach (PartSet_PartModel* aPartModel, myPartModels)
+ //{
+ // aRow++;
+ // if (aPartModel->part() == theObject) {
+ // aModel = aPartModel;
+ // break;
+ // }
+ //}
+ //if (aModel) {
+ // return createIndex(aRow, 0, (void*) getModelIndex(aModel->index(0, 0, QModelIndex())));
+ //}
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
+ for (int aId = 0; aId < aNb; aId++) {
+ if (theObject == aRootDoc->object(ModelAPI_ResultPart::group(), aId))
+ return createIndex(aId, 0, PartResult);
}
return QModelIndex();
}
}
} else {
PartSet_PartModel* aPartModel = 0;
- foreach(PartSet_PartModel* aModel, myPartModels)
- {
+ foreach(PartSet_PartModel* aModel, myPartModels) {
if (aModel->hasDocument(aDoc)) {
aPartModel = aModel;
break;
}
if (aPartModel) {
QModelIndex aIndex = aPartModel->objectIndex(theObject);
- return
- aIndex.isValid() ?
+ return aIndex.isValid() ?
createIndex(aIndex.row(), aIndex.column(), (void*) getModelIndex(aIndex)) :
QModelIndex();
}
{
clearModelIndexes();
clearSubModels();
- myActivePart = 0;
+ //myActivePart = 0;
myActivePartIndex = QModelIndex();
myModel->setItemsColor(ACTIVE_COLOR);
}
#include <Events_Listener.h>
#include <QList>
+#include <QMap>
class ModelAPI_Document;
class PartSet_PartModel;
return myActivePartIndex;
}
+ //! Returns parent index of active part tree (index of Part feature)
+ QModelIndex activePartTree() const;
+
//! Deactivates a Part
void deactivatePart();
enum
{
- PartsFolder,
- HistoryNode
+ PartsFolder = -100,
+ HistoryNode,
+ PartResult
};
//! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
PartSet_TopDataModel* myModel;
//! Data models for Parts data tree representation (one data model per a one part)
- QList<PartSet_PartModel*> myPartModels;
+ QMap<int, PartSet_PartModel*> myPartModels;
//! Active part in part editing mode
- PartSet_PartModel* myActivePart;
+ int myActivePartId;
QModelIndex myActivePartIndex;
#include "PartSet_WidgetEditor.h"
#include "PartSet_SketcherMgr.h"
#include "PartSet_MenuMgr.h"
-#include "PartSet_DocumentDataModel.h"
#include <PartSetPlugin_Remove.h>
#include <PartSetPlugin_Part.h>
FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID());
aFeature->execute();
aMgr->finishOperation();
- }
- }
+ } else
+ return false;
+ } else
+ return false;
}
return true;
}
aDisplayer->updateViewer();
}
-ModuleBase_IDocumentDataModel* PartSet_Module::dataModel() const
-{
- return myDataModel;
-}
-
void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
{
QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
int aSelected = aObjects.size();
+ SessionPtr aMgr = ModelAPI_Session::get();
if (aSelected == 1) {
bool hasResult = false;
bool hasFeature = false;
bool hasParameter = false;
ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
- SessionPtr aMgr = ModelAPI_Session::get();
ObjectPtr aObject = aObjects.first();
if (aObject) {
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
if (aMgr->activeDocument() != aMgr->moduleDocument())
theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
}
+ } else if (aSelected == 0) {
+ // if there is no selection then it means that upper label is selected
+ if (aMgr->activeDocument() != aMgr->moduleDocument())
+ theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
}
}
SessionPtr aMgr = ModelAPI_Session::get();
DocumentPtr aActiveDoc = aMgr->activeDocument();
DocumentPtr aDoc = aMgr->moduleDocument();
- QModelIndex aOldIndex = myDataModel->activePartIndex();
+ QModelIndex aOldIndex = myDataModel->activePartTree();
if (aActiveDoc == aDoc) {
if (aOldIndex.isValid())
aTreeView->setExpanded(aOldIndex, false);
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
if (aPart->partDoc() == aActiveDoc) {
QModelIndex aIndex = myDataModel->partIndex(aPart);
- if ((aOldIndex != aIndex) && aOldIndex.isValid()) {
- aTreeView->setExpanded(aOldIndex, false);
- }
if (myDataModel->activatePart(aIndex)) {
- aTreeView->setExpanded(aIndex.parent(), true);
- aTreeView->setExpanded(aIndex, true);
+ aTreeView->setExpanded(aOldIndex, false);
+ aTreeView->setExpanded(myDataModel->activePartTree(), true);
aPalet.setColor(QPalette::Text, Qt::black);
}
break;
#include "PartSet.h"
#include "PartSet_Filters.h"
+#include "PartSet_DocumentDataModel.h"
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
class ModuleBase_IViewWindow;
class PartSet_MenuMgr;
class PartSet_SketcherMgr;
-class PartSet_DocumentDataModel;
class QAction;
PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
/// Returns data model object for representation of data tree in Object browser
- virtual ModuleBase_IDocumentDataModel* dataModel() const;
+ virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
/// Event Listener method
/// \param theMessage an event message
case Qt::DisplayRole:
// return a name
switch (theIndex.internalId()) {
- case MyRoot: {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
- if (aObject)
- return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
- }
+ //case MyRoot: {
+ // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ // if (aObject)
+ // return std::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
+ //}
case ParamsFolder:
return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
case ConstructFolder:
case Qt::DecorationRole:
// return an Icon
switch (theIndex.internalId()) {
- case MyRoot:
- return QIcon(":pictures/part_ico.png");
+ //case MyRoot:
+ // return QIcon(":pictures/part_ico.png");
case ParamsFolder:
return QIcon(":pictures/params_folder.png");
case ConstructFolder:
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
+ //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());
+ } else
return 0;
}
switch (parent.internalId()) {
- case MyRoot:
- {
- DocumentPtr aDoc = partDocument();
- if (aDoc) {
- return getRowsNumber() + aDoc->size(ModelAPI_Feature::group());
- } else
- return 0;
- }
+ //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:
QModelIndex PartSet_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
{
- if (!theParent.isValid())
- return createIndex(theRow, 0, (qint32) MyRoot);
-
- 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:
+ if (!theParent.isValid()) {
+ // return createIndex(theRow, 0, (qint32) MyRoot);
+ 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) BodiesFolder);
+ case 3:
+ {
+ int aSize = partDocument()->size(ModelAPI_ResultGroup::group());
+ if (aSize > 0)
+ return createIndex(theRow, theColumn, (qint32) GroupsFolder);
+ else
return createIndex(theRow, theColumn, (qint32) HistoryObject);
- }
- case ParamsFolder:
- return createIndex(theRow, 0, (qint32) ParamObject);
- case ConstructFolder:
- return createIndex(theRow, 0, (qint32) ConstructObject);
- case BodiesFolder:
- return createIndex(theRow, 0, (qint32) BodiesObject);
- case GroupsFolder:
- return createIndex(theRow, 0, (qint32) GroupObject);
+ }
+ default:
+ return createIndex(theRow, theColumn, (qint32) HistoryObject);
+ }
+ } 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:
+ return createIndex(theRow, theColumn, (qint32) ConstructObject);
+ case BodiesFolder:
+ return createIndex(theRow, theColumn, (qint32) BodiesObject);
+ case GroupsFolder:
+ return createIndex(theRow, theColumn, (qint32) GroupObject);
+ }
}
return QModelIndex();
}
QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const
{
switch (theIndex.internalId()) {
- case MyRoot:
- return QModelIndex();
+ //case MyRoot:
+ // return QModelIndex();
case ParamsFolder:
case ConstructFolder:
case BodiesFolder:
case GroupsFolder:
case HistoryObject:
- return createIndex(0, 0, (qint32) MyRoot);
+ return QModelIndex();
+ //return createIndex(0, 0, (qint32) MyRoot);
case ParamObject:
- return createIndex(0, 0, (qint32) ParamsFolder);
+ return createIndex(0, theIndex.column(), (qint32) ParamsFolder);
case ConstructObject:
- return createIndex(1, 0, (qint32) ConstructFolder);
+ return createIndex(1, theIndex.column(), (qint32) ConstructFolder);
case BodiesObject:
- return createIndex(2, 0, (qint32) BodiesFolder);
+ return createIndex(2, theIndex.column(), (qint32) BodiesFolder);
case GroupObject:
- return createIndex(3, 0, (qint32) GroupsFolder);
+ return createIndex(3, theIndex.column(), (qint32) GroupsFolder);
}
return QModelIndex();
}
DocumentPtr PartSet_PartDataModel::partDocument() const
{
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
- if (aPart)
- return aPart->partDoc();
- return DocumentPtr(); // null if not found
+ //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 MyRoot: {
+ // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ // return aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ //}
case ParamsFolder:
case ConstructFolder:
case BodiesFolder:
//! Types of QModelIndexes
enum DataIds
{
- MyRoot,
+ //MyRoot,
ParamsFolder,
ParamObject,
ConstructFolder,
//***************************************************
void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
{
- bool toEnable = mySelectedData.size() == 1;
- foreach(QAction* aCmd, actions())
- {
+ QObjectPtrList aSelectedData = selectedObjects();
+ bool toEnable = aSelectedData.size() == 1;
+ foreach(QAction* aCmd, actions()) {
aCmd->setEnabled(toEnable);
}
emit contextMenuRequested(theEvent);
//***************************************************
void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
{
- mySelectedData.clear();
+ myTreeView->selectionModel()->clearSelection();
//Empty feature pointer means that selected root document
- mySelectedData.append(ObjectPtr());
-
- foreach(QAction* aCmd, actions())
- {
+ foreach(QAction* aCmd, actions()) {
aCmd->setEnabled(true);
}
QContextMenuEvent aEvent(QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt));
//***************************************************
void XGUI_ObjectsBrowser::onEditItem()
{
- if (mySelectedData.size() > 0) {
- ObjectPtr aFeature = mySelectedData.first();
+ QObjectPtrList aSelectedData = selectedObjects();
+ if (aSelectedData.size() > 0) {
+ ObjectPtr aFeature = aSelectedData.first();
if (aFeature) { // Selection happens in TreeView
// Find index which corresponds the feature
QModelIndex aIndex;
- foreach(QModelIndex aIdx, selectedIndexes())
- {
+ foreach(QModelIndex aIdx, selectedIndexes()) {
ObjectPtr aFea = dataModel()->object(aIdx);
if (dataModel()->object(aIdx)->isSame(aFeature)) {
aIndex = aIdx;
myTreeView->setCurrentIndex(aIndex);
myTreeView->edit(aIndex);
}
- } else { //Selection happens in Upper label
- myActiveDocLbl->setReadOnly(false);
- myActiveDocLbl->setFocus();
- myActiveDocLbl->selectAll();
- myActiveDocLbl->grabMouse();
- myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text());
+ return;
}
}
+ //Selection happens in Upper label
+ myActiveDocLbl->setReadOnly(false);
+ myActiveDocLbl->setFocus();
+ myActiveDocLbl->selectAll();
+ myActiveDocLbl->grabMouse();
+ myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text());
}
//***************************************************
//***************************************************
void XGUI_ObjectsBrowser::clearContent()
{
- mySelectedData.clear();
myTreeView->clear();
}
void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
const QItemSelection& theDeselected)
{
- mySelectedData.clear();
- QModelIndexList aIndexes = myTreeView->selectionModel()->selectedIndexes();
+ emit selectionChanged();
+}
+
+QObjectPtrList XGUI_ObjectsBrowser::selectedObjects() const
+{
+ QObjectPtrList aList;
+ QModelIndexList aIndexes = selectedIndexes();
ModuleBase_IDocumentDataModel* aModel = dataModel();
QModelIndexList::const_iterator aIt;
for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
if ((*aIt).column() == 0) {
ObjectPtr aObject = aModel->object(*aIt);
if (aObject)
- mySelectedData.append(aObject);
+ aList.append(aObject);
}
}
- emit selectionChanged();
-}
+ return aList;
+}
\ No newline at end of file
}
//! Returns list of currently selected objects
- QObjectPtrList selectedObjects() const
- {
- return mySelectedData;
- }
+ QObjectPtrList selectedObjects() const;
/// Set selected list of objects
/// \param theObjects list of objects to select
QLineEdit* myActiveDocLbl;
XGUI_DataTree* myTreeView;
-
- QObjectPtrList mySelectedData;
};
#endif
"::title { position: relative; padding-left: 5px; text-align: left center }");
myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
myObjectBrowser->setDataModel(myModule->dataModel());
- //connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
- // SLOT(changeCurrentDocument(ObjectPtr)));
aObjDock->setWidget(myObjectBrowser);
myContextMenuMgr->connectObjectBrowser();