class XGUI_EXPORT XGUI_FeaturesModel : public QAbstractItemModel
{
public:
- XGUI_FeaturesModel(const DocumentPtr& theDocument, QObject* theParent):
- QAbstractItemModel(theParent), myDocument(theDocument), myItemsColor(Qt::black) {}
+ XGUI_FeaturesModel(QObject* theParent):
+ QAbstractItemModel(theParent), myItemsColor(Qt::black) {}
//! Returns Feature object by the given Model index.
//! Returns 0 if the given index is not index of a feature
QColor itemsColor() const { return myItemsColor; }
protected:
- boost::shared_ptr<ModelAPI_Document> myDocument;
QColor myItemsColor;
};
class XGUI_PartModel : public XGUI_FeaturesModel
{
public:
- XGUI_PartModel(const DocumentPtr& theDocument, QObject* theParent):
- XGUI_FeaturesModel(theDocument, theParent) {}
+ XGUI_PartModel(QObject* theParent):
+ XGUI_FeaturesModel(theParent) {}
void setPartId(int theId) { myId = theId; }
XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
: QAbstractItemModel(theParent), myActivePart(0)
{
- // Find Document object
- PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
- myDocument = aMgr->currentDocument();
-
// Register in event loop
Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
// Create a top part of data tree model
- myModel = new XGUI_TopDataModel(myDocument, this);
+ myModel = new XGUI_TopDataModel(this);
myModel->setItemsColor(ACTIVE_COLOR);
}
void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
{
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+
// Created object event *******************
if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
FeaturePtr aFeature = (*aIt);
DocumentPtr aDoc = aFeature->document();
- if (aDoc == myDocument) { // If root objects
+ if (aDoc == aRootDoc) { // If root objects
if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group
// Add a new part
int aStart = myPartModels.size();
- XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
+ XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this);
aModel->setPartId(myPartModels.count());
myPartModels.append(aModel);
insertRow(aStart, partFolderNode());
std::set<std::string>::const_iterator aIt;
for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
std::string aGroup = (*aIt);
- if (aDoc == myDocument) { // If root objects
+ if (aDoc == aRootDoc) { // If root objects
if (aGroup.compare(PARTS_GROUP) == 0) { // Updsate only Parts group
int aStart = myPartModels.size() - 1;
removeSubModel(aStart);
// Reset whole tree **************************
} else {
- beginResetModel();
- int aNbParts = myDocument->size(PARTS_GROUP);
- if (myPartModels.size() != aNbParts) { // resize internal models
- while (myPartModels.size() > aNbParts) {
- delete myPartModels.last();
- myPartModels.removeLast();
- }
- while (myPartModels.size() < aNbParts) {
- myPartModels.append(new XGUI_PartDataModel(myDocument, this));
- }
- for (int i = 0; i < myPartModels.size(); i++)
- myPartModels.at(i)->setPartId(i);
+ rebuildDataTree();
+ }
+}
+
+void XGUI_DocumentDataModel::rebuildDataTree()
+{
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+
+ beginResetModel();
+ clearModelIndexes();
+
+ int aNbParts = aRootDoc->size(PARTS_GROUP);
+ if (myPartModels.size() != aNbParts) { // resize internal models
+ while (myPartModels.size() > aNbParts) {
+ delete myPartModels.last();
+ myPartModels.removeLast();
+ }
+ while (myPartModels.size() < aNbParts) {
+ myPartModels.append(new XGUI_PartDataModel(this));
}
- clearModelIndexes();
- endResetModel();
+ for (int i = 0; i < myPartModels.size(); i++)
+ myPartModels.at(i)->setPartId(i);
}
+ endResetModel();
}
QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
case HistoryNode:
{
int aOffset = historyOffset();
- FeaturePtr aFeature = myDocument->feature(FEATURES_GROUP, theIndex.row() - aOffset);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset);
if (!aFeature)
return QVariant();
switch (theRole) {
int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const
{
if (!theParent.isValid()) {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
// Size of external models
int aVal = historyOffset();
// Plus history size
- aVal += myDocument->size(FEATURES_GROUP);
+ aVal += aRootDoc->size(FEATURES_GROUP);
return aVal;
}
if (theParent.internalId() == PartsFolder) {
if (theIndex.internalId() == PartsFolder)
return FeaturePtr();
if (theIndex.internalId() == HistoryNode) {
- int aOffset = historyOffset();
- return myDocument->feature(FEATURES_GROUP, theIndex.row() - aOffset);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ int aOffset = historyOffset();
+ return aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset);
}
QModelIndex* aIndex = toSourceModelIndex(theIndex);
if (!isSubModel(aIndex->model()))
//! Deactivates a Part
void deactivatePart();
+ void rebuildDataTree();
+
private:
enum {PartsFolder, HistoryNode};
int historyOffset() const;
- //! Document
- boost::shared_ptr<ModelAPI_Document> myDocument;
-
//! Data model of top part of data tree (not parts object)
XGUI_TopDataModel* myModel;
{
myFeaturesList = myTreeView->selectedFeatures();
emit selectionChanged();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::rebuildDataTree()
+{
+ myDocModel->rebuildDataTree();
+ update();
}
\ No newline at end of file
//! Activates currently selected part. Signal activePartChanged will not be sent
void activatePart(const FeaturePtr& thePart);
+ void rebuildDataTree();
+
signals:
//! Emited when selection is changed
void selectionChanged();
//}
-XGUI_TopDataModel::XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent)
- : XGUI_FeaturesModel(theDocument, theParent)
+XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
+ : XGUI_FeaturesModel(theParent)
{
}
return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
case ParamObject:
{
- FeaturePtr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(PARAMETERS_GROUP, theIndex.row());
if (aFeature)
return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
}
return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
case ConstructObject:
{
- FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row());
if (aFeature)
return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
}
return QIcon(":pictures/constr_folder.png");
case ConstructObject:
{
- FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row());
if (aFeature)
return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
}
if (!theParent.isValid())
return 2;
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
if (theParent.internalId() == ParamsFolder)
- return myDocument->size(PARAMETERS_GROUP);
+ return aRootDoc->size(PARAMETERS_GROUP);
if (theParent.internalId() == ConstructFolder)
- return myDocument->size(CONSTRUCTIONS_GROUP);
+ return aRootDoc->size(CONSTRUCTIONS_GROUP);
return 0;
}
case ConstructFolder:
return FeaturePtr();
case ParamObject:
- return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ return aRootDoc->feature(PARAMETERS_GROUP, theIndex.row());
+ }
case ConstructObject:
- return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ return aRootDoc->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ }
}
return FeaturePtr();
}
{
QModelIndex aIndex;
if (theFeature) {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
std::string aGroup = theFeature->getGroup();
- int aNb = myDocument->size(aGroup);
+ int aNb = aRootDoc->size(aGroup);
int aRow = -1;
for (int i = 0; i < aNb; i++) {
- if (myDocument->feature(aGroup, i) == theFeature) {
+ if (aRootDoc->feature(aGroup, i) == theFeature) {
aRow = i;
break;
}
//******************************************************************
//******************************************************************
//******************************************************************
-XGUI_PartDataModel::XGUI_PartDataModel(const DocumentPtr& theDocument, QObject* theParent)
- : XGUI_PartModel(theDocument, theParent)
+XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
+ : XGUI_PartModel(theParent)
{
}
switch (theIndex.internalId()) {
case MyRoot:
{
- FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId);
if (aFeature)
return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
}
int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
{
- if (!parent.isValid())
- if (myDocument->feature(PARTS_GROUP, myId))
+ if (!parent.isValid()) {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ if (aRootDoc->feature(PARTS_GROUP, myId))
return 1;
else
return 0;
+ }
switch (parent.internalId()) {
case MyRoot:
return 3 + featureDocument()->size(FEATURES_GROUP);
DocumentPtr XGUI_PartDataModel::featureDocument() const
{
- FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId, true);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ FeaturePtr aFeature = aRootDoc->feature(PARTS_GROUP, myId, true);
return aFeature->data()->docRef("PartDocument")->value();
}
{
switch (theIndex.internalId()) {
case MyRoot:
- return myDocument->feature(PARTS_GROUP, myId);
+ {
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ return aRootDoc->feature(PARTS_GROUP, myId);
+ }
case ParamsFolder:
case ConstructFolder:
case BodiesFolder:
FeaturePtr XGUI_PartDataModel::part() const
{
- return myDocument->feature(PARTS_GROUP, myId, true);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ return aRootDoc->feature(PARTS_GROUP, myId, true);
}
QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
return aIndex;
std::string aGroup = theFeature->getGroup();
- int aNb = myDocument->size(aGroup);
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ int aNb = aRootDoc->size(aGroup);
int aRow = -1;
for (int i = 0; i < aNb; i++) {
- if (myDocument->feature(aGroup, i) == theFeature) {
+ if (aRootDoc->feature(aGroup, i) == theFeature) {
aRow = i;
break;
}
{
Q_OBJECT
public:
- XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent);
+ XGUI_TopDataModel(QObject* theParent);
virtual ~XGUI_TopDataModel();
// Reimpl from QAbstractItemModel
{
Q_OBJECT
public:
- XGUI_PartDataModel(const DocumentPtr& theDocument, QObject* theParent);
+ XGUI_PartDataModel(QObject* theParent);
virtual ~XGUI_PartDataModel();
// Reimpl from QAbstractItemModel
void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
{
if (view && (view != myActiveView) && (!view->isMinimized())) {
- qDebug("onWindowActivated");
myActiveView = view;
((XGUI_ViewWindow*)myActiveView->widget())->windowActivated();
QList<QMdiSubWindow*>::iterator aIt;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
aDoc->load(myCurrentDir.toLatin1().constData());
- QApplication::restoreOverrideCursor();
updateCommandStatus();
+ myObjectBrowser->rebuildDataTree();
+ QApplication::restoreOverrideCursor();
}
//******************************************************