MODEL_EXPORT virtual void closeAll();
//! Starts a new operation (opens a tansaction)
- MODEL_EXPORT virtual void startOperation(const std::string& theId);
+ MODEL_EXPORT virtual void startOperation(const std::string& theId = "");
//! Finishes the previously started operation (closes the transaction)
MODEL_EXPORT virtual void finishOperation();
//! Aborts the operation
//! Starts a new operation (opens a tansaction)
//! \param theId of operation for history (optional)
- virtual void startOperation(const std::string& theId) = 0;
+ virtual void startOperation(const std::string& theId = "") = 0;
//! Finishes the previously started operation (closes the transaction)
virtual void finishOperation() = 0;
//! Aborts the operation
void ModuleBase_Operation::start()
{
QString anId = getDescription()->operationId();
+ if (myIsEditing) {
+ anId = anId.append(EditSuffix());
+ }
ModelAPI_Session::get()->startOperation(anId.toStdString());
if (!myIsEditing)
Q_OBJECT
public:
+
+ /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
+ static QString EditSuffix() { return "_E"; }
/// Constructor
/// \param theId the operation identifier
/// \param theParent the QObject parent
//}
}
+ QString aDescription = tr("Delete");
if (!aRefFeatures.empty()) {
QStringList aRefNames;
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
}
if (!aRefNames.empty()) {
QString aNames = aRefNames.join(", ");
+ aDescription += aNames.prepend(" ");
QMainWindow* aDesktop = aWorkshop->desktop();
QMessageBox::StandardButton aRes = QMessageBox::warning(
}
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation("DeletePartSet");
+ aMgr->startOperation(aDescription.toStdString());
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
aResult = new QAction(QIcon(":pictures/button_ok.png"), "", theParent);
break;
case Abort:
- case AbortAll:
+ case AbortAll: {
aResult = new QAction(QIcon(":pictures/button_cancel.png"), "", theParent);
- break;
+ if(theId == Abort) {
+ aResult->setShortcut(QKeySequence(Qt::Key_Escape));
+ }
+ }
+ break;
case Help:
aResult = new QAction(QIcon(":pictures/button_help.png"), "", theParent);
break;
return aResult;
}
+ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId)
+{
+ ActionInfo aResult;
+ if(myActions.contains(theId)) {
+ aResult.initFrom(myActions.value(theId));
+ } else {
+ aResult.id = theId;
+ aResult.text = theId;
+ }
+ return aResult;
+}
+
void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
{
foreach(QString eachAction, myActions.keys())
#include <Events_Listener.h>
#include <ModelAPI_Feature.h>
+#include <ModuleBase_ActionInfo.h>
+
#include <QObject>
#include <QMap>
#include <QList>
//! If there is no such action, it will be created.
QAction* operationStateAction(OperationStateActionId theId, QObject* theParent = 0);
+ ActionInfo actionInfoById(const QString& theId);
+
public slots:
//! Update workbench actions according to OperationMgr state:
//! No active operations: all actions but nested are available
}
}
+void XGUI_HistoryMenu::leaveEvent(QEvent* theEvent)
+{
+ setStackSelectedTo(NULL);
+ QMenu::leaveEvent(theEvent);
+}
void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
{
- if (!theItem)
- return;
-
QListWidgetItem* eachItem = NULL;
- bool isSelect = true;
+ bool isSelect = theItem != NULL;
for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
eachItem = myHistoryList->item(aRow);
myHistoryList->setItemSelected(eachItem, isSelect);
isSelect = false;
}
}
+ // to avoid blinking caused by QMenu paint event (paints on top of the list)
+ myHistoryList->repaint();
}
void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
int selectedSize = myHistoryList->row(theItem) + 1;
emit actionSelected(selectedSize);
hide();
- myHistoryList->clear();
}
public slots:
void setHistory(const QList<ActionInfo>&);
+ protected:
+ virtual void leaveEvent(QEvent *);
+
protected slots:
void setStackSelectedTo(QListWidgetItem *);
void onItemPressed(QListWidgetItem *);
void initMenu();
+
private:
QListWidget* myHistoryList;
};
QString aRes = aEditor->text();
ObjectPtr aFeature = mySelectedData.first();
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation("RenameFeature");
+ aMgr->startOperation("Rename");
aFeature->data()->setName(qPrintable(aRes));
aMgr->finishOperation();
}
// Enable all commands
aCmd->setEnabled(true);
}
+
aUndoCmd->setEnabled(myModule->canUndo());
aRedoCmd->setEnabled(myModule->canRedo());
-
updateHistory();
-
} else {
foreach(QAction* aCmd, aCommands) {
QString aId = aCmd->data().toString();
void XGUI_Workshop::updateHistory()
{
std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
- std::list<std::string>::iterator it = aUndoList.begin();
- QList<ActionInfo> aUndoRes;
- for ( ; it != aUndoList.end(); it++) {
- QString anId = QString::fromStdString(*it);
- QIcon aIcon;
- if (myIcons.contains(anId))
- aIcon = QIcon(myIcons[anId]);
- aUndoRes << ActionInfo(aIcon, anId);
- }
+ QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
emit updateUndoHistory(aUndoRes);
std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
- it = aRedoList.begin();
- QList<ActionInfo> aRedoRes;
- for ( ; it != aRedoList.end(); it++) {
- QString anId = QString::fromStdString(*it);
- QIcon aIcon;
- if (myIcons.contains(anId))
- aIcon = QIcon(myIcons[anId]);
- aRedoRes << ActionInfo(aIcon, anId);
- }
- emit updateRedoHistory(aUndoRes);
+ QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
+ emit updateRedoHistory(aRedoRes);
}
//******************************************************
}
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation("DeleteObjects");
+ QString aDescription = tr("Delete %1");
+ QStringList aObjectNames;
+ foreach (ObjectPtr aObj, theList) {
+ if (!aObj->data().get())
+ continue;
+ aObjectNames << QString::fromStdString(aObj->data()->name());
+ }
+ aDescription = aDescription.arg(aObjectNames.join(", "));
+ aMgr->startOperation(aDescription.toStdString());
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
myDisplayer->updateViewer();
aMgr->finishOperation();
+ updateCommandStatus();
}
//**************************************************************
}
connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
+}
+QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
+{
+ QList<ActionInfo> aResult;
+ std::list<std::string>::const_iterator it = theList.cbegin();
+ for (; it != theList.cend(); it++) {
+ QString anId = QString::fromStdString(*it);
+ bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
+ if (isEditing) {
+ anId.chop(ModuleBase_Operation::EditSuffix().size());
+ }
+ ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
+ if (isEditing) {
+ anInfo.text = anInfo.text.prepend("Modify ");
+ }
+ aResult << anInfo;
+ }
+ return aResult;
}
//! \param theSlot - onUndo(int) or onRedo(int) SLOT
void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
+ //! Creates list of actions (commands) by given history list from session
+ QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
+
private:
AppElements_MainWindow* myMainWindow;
ModuleBase_IModule* myModule;