Skip to content

Commit

Permalink
TreeView: add menu action for manual recompute of objects
Browse files Browse the repository at this point in the history
The manual recompute is forced regardless of whether SkipRecompute is
set on the document
  • Loading branch information
realthunder committed May 10, 2018
1 parent b2576c0 commit 017da8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ TreeWidget::TreeWidget(const char *name, QWidget* parent)
connect(this->markRecomputeAction, SIGNAL(triggered()),
this, SLOT(onMarkRecompute()));

this->recomputeObjectAction = new QAction(this);
connect(this->recomputeObjectAction, SIGNAL(triggered()),
this, SLOT(onRecomputeObject()));

// Setup connections
Application::Instance->signalNewDocument.connect(boost::bind(&TreeWidget::slotNewDocument, this, _1));
Application::Instance->signalDeleteDocument.connect(boost::bind(&TreeWidget::slotDeleteDocument, this, _1));
Expand Down Expand Up @@ -298,6 +302,7 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e)
contextMenu.addAction(this->createGroupAction);

contextMenu.addAction(this->markRecomputeAction);
contextMenu.addAction(this->recomputeObjectAction);
contextMenu.addAction(this->relabelObjectAction);
}

Expand Down Expand Up @@ -463,6 +468,23 @@ void TreeWidget::onMarkRecompute()
}
}

void TreeWidget::onRecomputeObject() {
std::vector<App::DocumentObject*> objs;
for(auto ti : selectedItems()) {
if (ti->type() == ObjectType) {
DocumentObjectItem* objitem = static_cast<DocumentObjectItem*>(ti);
objs.push_back(objitem->object()->getObject());
objs.back()->touch();
}
}
if(objs.empty())
return;
App::GetApplication().setActiveTransaction("Recompute");
objs.front()->getDocument()->recompute(objs,true);
App::GetApplication().closeActiveTransaction();
}


DocumentItem *TreeWidget::getDocumentItem(const Gui::Document *doc) const {
auto it = DocumentMap.find(doc);
if(it != DocumentMap.end())
Expand Down Expand Up @@ -1216,6 +1238,9 @@ void TreeWidget::setupText() {

this->markRecomputeAction->setText(tr("Mark to recompute"));
this->markRecomputeAction->setStatusTip(tr("Mark this object to be recomputed"));

this->recomputeObjectAction->setText(tr("Recompute object"));
this->recomputeObjectAction->setStatusTip(tr("Recompute the selected object"));
}

void TreeWidget::onSyncSelection() {
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected Q_SLOTS:
void onFinishEditing();
void onSkipRecompute(bool on);
void onMarkRecompute();
void onRecomputeObject();
void onSyncSelection();
void onPreSelection();
void onPreSelectTimer();
Expand Down Expand Up @@ -163,6 +164,7 @@ private Q_SLOTS:
QAction* finishEditingAction;
QAction* skipRecomputeAction;
QAction* markRecomputeAction;
QAction* recomputeObjectAction;
QAction* preSelectionAction;
QAction* syncSelectionAction;
QAction* syncViewAction;
Expand Down

0 comments on commit 017da8a

Please sign in to comment.