//---------------------------------------------------------------------------- // $Id: QtRpl/RplBlockDlg.cpp 2013/06/05 21:06:16 philw $ //---------------------------------------------------------------------------- // Prevent use of the Qt3 compatibility library #undef QT3_SUPPORT #include "RowOToggles.hpp" #include "RplBlockDlg.hpp" #include "RplFrame.hpp" #include "RplGUI.hpp" #include "RplIcons.hpp" #include "RplPrinter.hpp" // // Qt includes // #include "qt/ui_RplBlockDlgWidgets.h" #include #include // // Riverware non-GUI includes // #ifndef SelectionINCLUDED #include "Selection.hpp" #endif #ifndef RplObjINCLUDED #include "RplObj.hpp" #endif #ifndef RplBlockINCLUDED #include "RplBlock.hpp" #endif #ifndef RplSetINCLUDED #include "RplSet.hpp" #endif #ifndef PolicyGroupINCLUDED #include "PolicyGroup.hpp" #endif #ifndef VisualTokenINCLUDED #include "VisualToken.hpp" #endif #ifndef PrintStmtINCLUDED #include "PrintStmt.hpp" #endif #ifndef AssignStmtINCLUDED #include "AssignStmt.hpp" #endif #ifndef ForStmtINCLUDED #include "ForStmt.hpp" #endif #ifndef RplExpressionINCLUDED #include "RplExpression.hpp" #endif #ifndef SimWorkspaceINCLUDED #include "SimWS.hpp" #endif #ifndef SystemINCLUDED #include "System.hpp" #endif #ifndef DerivedObjStmtINCLUDED #include "DerivedObjStmt.hpp" #endif #ifndef DocumentInfoINCLUDED #include "DocumentInfo.hpp" #endif #ifndef rwErrorINCLUDED #include "rwError.hpp" //--- rwAssert #endif #ifndef RplDebuggerINCLUDED #include "RplDebugger.hpp" #endif #include "RplDlgMgr.hpp" #include "rwStr.hpp" #include "SlotGUIUtils.hpp" // Indices for items in the Set Value Flag QComboBox. static const int SET_FLAG_IS_RULE_INDEX(0); static const int SET_FLAG_IS_DMI_INPUT_INDEX(1); //-------------------------------------------------------------------------- //+class // // CLASS: // RplBlockDlg // // DESCRIPTION: // Editor dialogs for RplSet objects. // //-------------------------------------------------------------------------- RplBlockDlg::RplBlockDlg(BaseRWDlg *parent, RplBlock *rplBlock) : RplBaseDlg(parent, "RplBlockDlg"), _ui(new Ui_RplBlockDlgWidgets()), _rplBlock(rplBlock), _undoStack(), _bodyRplFrame(NULL), _constraintRplFrame(NULL) { _ui->setupUi(this); rplDlgMgr->addRplDlg(_rplBlock, this); initWidgets(); initConnections(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- RplBlockDlg::~RplBlockDlg() { // We don't want to be updating our edit actions because the stack changes. _undoStack.blockSignals(true); // We don't want the RplDlgMgr to be updating us or our frames. rplDlgMgr->removeRplFrame(_bodyRplFrame); rplDlgMgr->removeRplFrame(_constraintRplFrame); rplDlgMgr->removeRplDlg(getRplObj(), this); delete _ui; } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- bool RplBlockDlg::updateLoadStatus() { // Update the load-related widgets updateLoadWidgets(_ui->_loadStateFrame, _ui->_loadButton); return true; //--- success } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- bool RplBlockDlg::update() { updateLoadStatus(); // Update the text updateDescr(); updateNotes(); _ui->_nameEdit->setText(_rplBlock->getName()); QString dlgTypeStr = RplDlgMgr::getObjTypeString(_rplBlock); setWindowTitle (dlgTypeStr + " Editor - \"" + _rplBlock->getParent()->getParent()->getName() + QString(" : ") + _rplBlock->getParent()->getName() + QString(" : ") + QString(_rplBlock->getName()) + "\""); // Initialize Icon Button: Show External Document initExternalDocButton (_ui->_externalDocPushButton); updateExternalDocOps (_ui->_externalDocPushButton, _ui->_extDocMenu, _ui->_viewExtDocAction, _ui->_editExtDocAction); const RplSet* rplSet (_rplBlock->getSet()); if (rplSet) { // Set RplSet Type Icon Pushbutton const QPixmap setIcon (RplIcons::getObjIcon (rplSet)); const QSize setIconSize (setIcon.size()); _ui->_rplSetTypeIconButton->setText (QString::null); _ui->_rplSetTypeIconButton->setIcon (setIcon); _ui->_rplSetTypeIconButton->setIconSize (setIconSize); _ui->_rplSetTypeIconButton->setFixedSize (setIconSize + QSize (4,4)); _ui->_rplSetTypeIconButton->setAutoDefault (false); _ui->_rplSetTypeIconButton->setDefault (false); _ui->_rplSetTypeIconButton->setToolTip (rplSet->getName()); } _ui->_rplSetTypeIconButton->setVisible (rplSet != NULL); const RplUtilityGroup* rplGrp (_rplBlock->getParent()); if (rplGrp) { // Set RplUtilityGroup Type Icon Pushbutton const QPixmap grpIcon (RplIcons::getObjIcon (rplGrp)); const QSize grpIconSize (grpIcon.size()); _ui->_rplGroupTypeIconButton->setText (QString::null); _ui->_rplGroupTypeIconButton->setIcon (grpIcon); _ui->_rplGroupTypeIconButton->setIconSize (grpIconSize); _ui->_rplGroupTypeIconButton->setFixedSize (grpIconSize + QSize (4,4)); _ui->_rplGroupTypeIconButton->setAutoDefault (false); _ui->_rplGroupTypeIconButton->setDefault (false); _ui->_rplGroupTypeIconButton->setToolTip (rplGrp->getName()); } _ui->_rplGroupTypeIconButton->setVisible ( SHOW_RPL_GROUP_TYPE_ICON_BUTTON && (rplGrp != NULL)); // Set RplObj Type Icon Label _ui->_rplObjTypeIconLabel->setText (QString::null); _ui->_rplObjTypeIconLabel->setPixmap ( RplIcons::getObjIcon(_rplBlock, rplSet)); return true; //--- success } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- bool RplBlockDlg::updateDescr() { const QString objText = _rplBlock->getDescription(); const QString widText = _ui->_descrEdit->toPlainText(); if (!_inDescrEdit && (objText != widText)) { //------------------------------------------- const bool saveIsSetting = _settingDescrEdit; _settingDescrEdit = true; //------------------------------------------- const int saveVertPos = _ui->_descrEdit->verticalScrollBar()->value(); _ui->_descrEdit->setText (objText); _ui->_descrEdit->verticalScrollBar()->setValue (saveVertPos); //------------------------------------------- _settingDescrEdit = saveIsSetting; //------------------------------------------- } updateDescriptionToggleRelevance(); return true; } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- bool RplBlockDlg::updateNotes() { const QString objText = _rplBlock->getNotes(); const QString widText = _ui->_notesEdit->toPlainText(); if (!_inNotesEdit && (objText != widText)) { const bool saveIsSetting = _settingNotesEdit; _settingNotesEdit = true; const int saveVertPos = _ui->_notesEdit->verticalScrollBar()->value(); _ui->_notesEdit->setText(objText); _ui->_notesEdit->verticalScrollBar()->setValue(saveVertPos); _settingDescrEdit = saveIsSetting; } updateNotesToggleRelevance(); return true; } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- bool RplBlockDlg::rebuild() { update(); return true; //--- success } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::updateEditActions() { static const char (*mname) ("RplBlockDlg::updateEditActions"); // std::cout << mname << std::endl; bool editsOkGlobally(rplDlgMgr->objEditsAllowed()); bool addElseIfPossible(_bodyRplFrame->selSupportsAddIfStmtBranch(false)); bool addElsePossible(_bodyRplFrame->selSupportsAddIfStmtBranch(true)); _ui->_nameEdit -> setReadOnly (!editsOkGlobally); _ui->_descrEdit -> setReadOnly (!editsOkGlobally); _ui->_notesEdit -> setReadOnly (!editsOkGlobally); _ui->_preDmiEdit -> setEnabled (editsOkGlobally); _ui->_postDmiEdit -> setEnabled (editsOkGlobally); _ui->_newSetAction -> setEnabled (editsOkGlobally); _ui->_newGlobFuncSetAction -> setEnabled (editsOkGlobally); _ui->_saveSetAction -> setEnabled (editsOkGlobally); _ui->_saveSetAsAction -> setEnabled (editsOkGlobally); _ui->_addAssignmentAction -> setEnabled (editsOkGlobally); _ui->_addPrintAction -> setEnabled (editsOkGlobally); _ui->_addAssignmentAction -> setEnabled (editsOkGlobally); _ui->_addForEachAction -> setEnabled (editsOkGlobally); _ui->_addWithStmtAction -> setEnabled (editsOkGlobally); _ui->_addIfAction -> setEnabled (editsOkGlobally); _ui->_addIfElseAction -> setEnabled (editsOkGlobally); _ui->_addElseIfBranchAction -> setEnabled (editsOkGlobally && addElseIfPossible); _ui->_addElseBranchAction -> setEnabled (editsOkGlobally && addElsePossible); _ui->_addConstraintAction -> setEnabled (editsOkGlobally); _ui->_addFreezeAction -> setEnabled (editsOkGlobally); _ui->_addRewardTableAction -> setEnabled (editsOkGlobally); _ui->_addStopRunAction -> setEnabled (editsOkGlobally); _ui->_addWarningAction -> setEnabled (editsOkGlobally); _ui->_addPreDmiAction -> setEnabled (editsOkGlobally); _ui->_addPostDmiAction -> setEnabled (editsOkGlobally); _ui->_undoAction -> setEnabled (editsOkGlobally && _undoStack.canUndo()); _ui->_redoAction -> setEnabled (editsOkGlobally && _undoStack.canRedo()); // We update our frames before we start asking them questions // (most edit actions apply to the frame with the selection, // which might be neither of our frames). _bodyRplFrame->updateEditActions(); _constraintRplFrame->updateEditActions(); _ui->_cutAction ->setEnabled(editsOkGlobally && (_bodyRplFrame ->deleteEnabled() || _constraintRplFrame->deleteEnabled())); _ui->_copyAction ->setEnabled(editsOkGlobally && (_bodyRplFrame ->copyEnabled() || _constraintRplFrame->copyEnabled())); _ui->_pasteAction ->setEnabled(editsOkGlobally && (_bodyRplFrame ->pasteEnabled() || _constraintRplFrame->pasteEnabled())); _ui->_deleteAction->setEnabled(editsOkGlobally && (_bodyRplFrame ->deleteEnabled() || _constraintRplFrame->deleteEnabled())); _ui->_enableAction->setEnabled(editsOkGlobally && (_bodyRplFrame ->enableEnabled() || _constraintRplFrame->enableEnabled())); _ui->_insertAction->setEnabled(editsOkGlobally && (_bodyRplFrame ->insertEnabled() || _constraintRplFrame->insertEnabled())); _ui->_appendAction->setEnabled(editsOkGlobally && (_bodyRplFrame ->appendEnabled() || _constraintRplFrame->appendEnabled())); // I figure we might as well always provide access to the palette, // even if they might not currently be able to edit with it. _ui->_paletteAction->setEnabled(true); _ui->_loadButton->setEnabled(!rplDebugger->isExecutionPaused()); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::rplSetTypeIconButton_clicked() { static const char (*mname) ("RplBlockDlg::rplSetTypeIconButton_clicked"); // std::cout << mname << std::endl; RplSet* rplSet (_rplBlock->getSet()); if (rplSet) { // NOTE: Using the BaseRWDlg parenting on these dialog doesn't work, // because we don't want the deletion behavior. rplDlgMgr->openRplDlgSelectRplObjViewRow (rplSet, _rplBlock, NULL); } } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::rplGroupTypeIconButton_clicked() { static const char (*mname) ("RplBlockDlg::rplGroupTypeIconButton_clicked"); // std::cout << mname << std::endl; RplUtilityGroup* rplGrp (_rplBlock->getParent()); if (rplGrp) { // NOTE: Using the BaseRWDlg parenting on these dialog doesn't work, // because we don't want the deletion behavior. rplDlgMgr->openRplDlgSelectRplObjViewRow (rplGrp, _rplBlock, NULL); } } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::preDmiHandler() { if (_rplBlock->hasPreExecDmiObj()) _rplBlock->setPreExecDmiObjName(_ui->_preDmiEdit->text()); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::postDmiHandler() { if (_rplBlock->hasPostExecDmiObj()) _rplBlock->setPostExecDmiObjName(_ui->_postDmiEdit->text()); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::togglePreDmiObj() { _rplBlock->setHasPreExecDmiObj(!_rplBlock->hasPreExecDmiObj()); updateDmiDisplay(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::togglePostDmiObj() { _rplBlock->setHasPostExecDmiObj(!_rplBlock->hasPostExecDmiObj()); updateDmiDisplay(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // // Set a breakpoint before the currently selected statement. // Breakpoints are associated with statements. If this dialog contains the // selection and it is a statement or is within a statement, use that // statement as the breakpoint location, otherwise go with the first // statement. If there are no statements, do nothing. // void RplBlockDlg::setBreakBeforeExec(bool doBreak) { if (_rplBlock->statementCount() == 0) { return; } // If the selection is or is contained within one of our statements, // then set the breakpoint for that statement, otherwise go with // the first statement. const RplStmtList* statements(_rplBlock->getStatements()); const RplStatement* statement(statements->get(0)); if (RplFrame::selection()->getFrame() == _bodyRplFrame) { VisualToken* selectedItem(RplFrame::selection()->getSelectedItem()); const RplObj* obj(selectedItem->getRplObj()); if (obj->isA(Rpl::RPL_STATEMENT)) { statement = static_cast(obj); } } RplDebugger::Location where(statement, NULL, RplDebugger::BEFORE_EXEC); RplDebugger::Breakpoint breakpoint(where, true); if (doBreak) { rplDebugger->addBreakpoint(breakpoint); } else { rplDebugger->removeBreakpoint(breakpoint); } _bodyRplFrame->reformat(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::setBreakAfterExec(bool doBreak) { if (_rplBlock->statementCount() == 0) { return; } // Always added to last statement. const RplStmtList* statements(_rplBlock->getStatements()); RplDebugger::Location where(statements->get(_rplBlock->statementCount()-1), NULL, RplDebugger::AFTER_EXEC); RplDebugger::Breakpoint breakpoint(where, true); if (doBreak) { rplDebugger->addBreakpoint(breakpoint); } else { rplDebugger->removeBreakpoint(breakpoint); } _bodyRplFrame->reformat(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::showOptionalFrames() { _ui->_descrGroupBox->setVisible( _ui->_showDescriptionAction->isChecked()); _ui->_notesGroupBox->setVisible( _ui->_showNotesAction->isChecked()); _ui->_execConstraintGroupBox->setVisible( _ui->_showConstraintAction->isChecked()); if (_ui->_showConstraintAction->isChecked()) _constraintRplFrame->reformat(); _toggles->setToggleOn(_showDescriptionToggleIndex, _ui->_showDescriptionAction->isChecked()); _toggles->setToggleOn(_showNotesToggleIndex, _ui->_showNotesAction->isChecked()); _toggles->setToggleOn(_showExecConstraintToggleIndex, _ui->_showConstraintAction->isChecked()); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::initConnections() { connect(_ui->_rplSetTypeIconButton, SIGNAL (clicked()), SLOT (rplSetTypeIconButton_clicked())); connect(_ui->_rplGroupTypeIconButton, SIGNAL (clicked()), SLOT (rplGroupTypeIconButton_clicked())); // Now redundant with the 'config' methods in RplBaseDlg. // //-- connect(_ui->_newSetAction, SIGNAL(triggered()), //-- SLOT(newRplSetHandler())); //-- connect(_ui->_openSetAction, SIGNAL(triggered()), //-- SLOT(openRplSetHandler())); //-- connect(_ui->_saveSetAction, SIGNAL(triggered()), //-- SLOT(saveRplSetHandler())); //-- connect(_ui->_saveSetAsAction, SIGNAL(triggered()), //-- SLOT(saveRplSetAsHandler())); connect (_ui->_newGlobFuncSetAction, SIGNAL(triggered()), SLOT (newGlobFuncSetHandler())); connect (_ui->_openGlobFuncSetAction, SIGNAL(triggered()), SLOT (openGlobFuncSetHandler())); connect(_ui->_printRplSetAction, SIGNAL(triggered()), SLOT(printHandler())); connect(_ui->_closeAction, SIGNAL(triggered()), SLOT(close())); connect(_ui->_refreshAction, SIGNAL(triggered()), SLOT(refreshHandler())); connect(_ui->_showDescriptionAction, SIGNAL(triggered(bool)), SLOT(showOptionalFrames())); connect(_ui->_showNotesAction, SIGNAL(triggered(bool)), SLOT(showOptionalFrames())); connect(_ui->_showConstraintAction, SIGNAL(triggered(bool)), SLOT(showOptionalFrames())); connect(_ui->_showCommentsAction, SIGNAL(triggered(bool)), _bodyRplFrame, SLOT(setShowComments(bool))); connect(_ui->_showCommentsAction, SIGNAL(triggered(bool)), _constraintRplFrame, SLOT(setShowComments(bool))); connect(_ui->_addIfAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addIfStmt())); connect(_ui->_addIfElseAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addIfElseStmt())); connect(_ui->_addElseIfBranchAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addElseIfBranchToIfStmt())); connect(_ui->_addElseBranchAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addElseBranchToIfStmt())); connect(_ui->_addForEachAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addForEachStmt())); connect(_ui->_addWithStmtAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addWithStmt())); connect(_ui->_addAssignmentAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addAssignStmt())); connect(_ui->_addPrintAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addPrintStmt())); connect(_ui->_addExecScriptAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addExecScriptStmt())); connect(_ui->_addObjectiveMaxAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addMaxObjectiveStmt())); connect(_ui->_addObjectiveMinAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addMinObjectiveStmt())); connect(_ui->_addSummationAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addSummationStmt())); connect(_ui->_addMaximinRepeatAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addMaximinRepeatStmt())); connect(_ui->_addMaximinSingleAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addMaximinSingleStmt())); connect(_ui->_addConstraintAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addConstraintStmt())); connect(_ui->_addFreezeAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addFreezeStmt())); connect(_ui->_addRewardTableAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addRewardTableStmt())); connect(_ui->_addStopRunAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addStopRunStmt())); connect(_ui->_addWarningAction,SIGNAL(triggered()), _bodyRplFrame, SLOT(addWarningStmt())); // Some menus need to be updated before they are shown. connect(_ui->_editMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu())); connect(_ui->_viewMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowViewMenu())); connect(_ui->_ruleMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowRuleMenu())); // Connect most edit action signals to both frames. The // frame's slot will do a no-op if the frame does not // contain the current selection. connect(_ui->_cutAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(cut())); connect(_ui->_copyAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(copy())); connect(_ui->_pasteAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(paste())); connect(_ui->_deleteAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(deleteHandler())); connect(_ui->_enableAction, SIGNAL(triggered(bool)), _bodyRplFrame, SLOT(enableHandler(bool))); connect(_ui->_insertAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(insertStmt())); connect(_ui->_appendAction, SIGNAL(triggered()), _bodyRplFrame, SLOT(appendStmt())); connect(_ui->_cutAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(cut())); connect(_ui->_copyAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(copy())); connect(_ui->_pasteAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(paste())); connect(_ui->_deleteAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(deleteHandler())); connect(_ui->_enableAction, SIGNAL(triggered(bool)), _constraintRplFrame, SLOT(enableHandler(bool))); connect(_ui->_insertAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(insertStmt())); connect(_ui->_appendAction, SIGNAL(triggered()), _constraintRplFrame, SLOT(appendStmt())); connect(_ui->_undoAction, SIGNAL(triggered()), &_undoStack, SLOT(undo())); connect(_ui->_redoAction, SIGNAL(triggered()), &_undoStack, SLOT(redo())); connect(_ui->_paletteAction, SIGNAL(triggered()), SLOT(openPaletteHandler())); connect(_ui->_checkValidityAction, SIGNAL(triggered()), SLOT(checkValidityHandler())); connect(_ui->_displaySettingsAction, SIGNAL(triggered()), SLOT(openDisplaySettingsDlgHandler())); connect(_ui->_setAnalysisAction, SIGNAL(triggered()), SLOT(openAnalysisDlgHandler())); connect(_ui->_compareSetAction, SIGNAL(triggered()), SLOT(compareSetHandler())); _ui->_openDebuggerDlgAction->setIcon(RplIcons::bug()); connect(_ui->_openDebuggerDlgAction, SIGNAL(triggered()), SLOT(openDebuggerDlgHandler())); connect(_ui->_closeAllEditorsAction, SIGNAL(triggered()), SLOT(closeOtherEditors())); connect(_ui->_setEditorAction, SIGNAL(triggered()), SLOT(openRplSetDlg())); connect(_ui->_addPreDmiAction, SIGNAL(triggered()), SLOT(togglePreDmiObj())); connect(_ui->_addPostDmiAction, SIGNAL(triggered()), SLOT(togglePostDmiObj())); connect(_ui->_externalDocPushButton, SIGNAL(clicked()), SLOT(externalDocButtonHandler())); connect(_ui->_loadButton, SIGNAL(clicked()), SLOT(loadButtonHandler())); connect(_ui->_nameEdit, SIGNAL(returnPressed()), SLOT(nameHandler())); connect(_ui->_nameEdit, SIGNAL(editingFinished()), SLOT(nameHandler())); connect(_ui->_preDmiEdit, SIGNAL(returnPressed()), SLOT(preDmiHandler())); connect(_ui->_preDmiEdit, SIGNAL(editingFinished()), SLOT(preDmiHandler())); connect(_ui->_postDmiEdit, SIGNAL(returnPressed()), SLOT(postDmiHandler())); connect(_ui->_postDmiEdit, SIGNAL(editingFinished()), SLOT(postDmiHandler())); connect(_ui->_descrEdit, SIGNAL(textChanged()), SLOT(descriptionHandler())); connect(_ui->_notesEdit, SIGNAL(textChanged()), SLOT(notesHandler())); connect(_ui->_searchReplaceAction, SIGNAL(triggered()), SLOT(openSearchReplaceDlgHandler())); connect(&_undoStack, SIGNAL(canUndoChanged(bool)), this , SLOT(updateEditActions())); connect(&_undoStack, SIGNAL(canRedoChanged(bool)), this, SLOT(updateEditActions())); connect(_ui->_viewExtDocAction, SIGNAL(triggered()), SLOT(viewExternalDocHandler())); connect(_ui->_editExtDocAction, SIGNAL(triggered()), SLOT(editExternalDocHandler())); connect(_ui->_configExtDocAction, SIGNAL(triggered()), SLOT(configureExternalDocHandler())); connect(_ui->_fileTypeAssocAction, SIGNAL(triggered()), SLOT(fileTypeAssocHandler())); connect(_ui->_breakBeforeExecAction, SIGNAL(toggled(bool)), SLOT(setBreakBeforeExec(bool))); connect(_ui->_breakAfterExecAction, SIGNAL(toggled(bool)), SLOT(setBreakAfterExec(bool))); connect(_ui->_stopOnNaNAction, SIGNAL(triggered(bool)), this, SLOT(stopOnNaNHandler(bool))); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::initWidgets() { resize(QSize(485, 300).expandedTo(minimumSizeHint())); // // Initialize the body RplFrame // _bodyRplFrame = new RplFrame(_undoStack, _rplBlock, true, _ui->_bodyPlaceholderWidget); // We want the frame to take up all available space. _bodyRplFrame->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(_bodyRplFrame); layout->setContentsMargins(0, 0, 0, 0); _ui->_bodyPlaceholderWidget->setLayout(layout); // // Initialize the execution constraints frame // _constraintRplFrame = new RplFrame(_undoStack, _rplBlock, false, _ui->_execConstraintGroupBox); _constraintRplFrame->setCanShowDebuggingDecorations(false); layout = new QVBoxLayout; layout->addWidget(_constraintRplFrame); layout->setContentsMargins(9, 5, 9, 5); _ui->_execConstraintGroupBox->setLayout(layout); // Update the optional frame menu items based on whether their // contents are non-trivial. _ui->_showConstraintAction->setChecked( !_rplBlock->execConstraintIsTrivial()); configureCloseDlgsButton (_ui->_closeDlgsButton); initForApplication(); initVisibilityToggles(); showOptionalFrames(); updateDmiDisplay(); update(); updateEditActions(); // Conditionally enable External Document menu and actions. const bool supportsDoc = DocumentInfo::supportsExternalDoc (_rplBlock); _ui->_extDocMenu->setEnabled (supportsDoc); // For testing, display the undo command stack. // QUndoView* undoView = new QUndoView(&_undoStack); // undoView->setWindowTitle(tr("Undo/Redo Command List")); // undoView->show(); // undoView->setAttribute(Qt::WA_QuitOnClose, false); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- extern bool rwPermitGoalAssignments; void RplBlockDlg::initForApplication() { const RplApplication::Type appType = _rplBlock->getLocalAppType(); _ui->_loadButton->setVisible ( appType == RplApplication::RBS || appType == RplApplication::OPT ); configNewSetAction (appType, _ui->_newSetAction); configOpenSetAction (appType, _ui->_openSetAction); configSaveSetAction (appType, _ui->_saveSetAction); configSaveSetAsAction (appType, _ui->_saveSetAsAction); configReopenSetMenu (appType, _ui->_reopenSetMenu); if (appType == RplApplication::GLOBAL) { // The New/Open/Reopen menu items are redundant with the menu items // already customized to the current RplApplication::Type. _ui->_newGlobFuncSetAction -> setVisible (false); _ui->_openGlobFuncSetAction -> setVisible (false); _ui->_reopenGlobFuncSetMenu -> setVisible (false); QAction* mAction (_ui->_reopenGlobFuncSetMenu->menuAction()); if (mAction) mAction -> setVisible (false); } else { configReopenGlobFuncSetMenu (_ui->_reopenGlobFuncSetMenu); } // How we refer to blocks varies with application (default is "Rule"). if (_rplBlock->appIsUDAM()) { // Modify the text of the "Rule" menu _ui->_ruleMenu->setTitle (tr ("Method")); _ui->_execConstraintGroupBox->setTitle("Execute Method Only When"); _ui->_descrGroupBox->setTitle("Method Description"); } else if (_rplBlock->appIsOpt()) { // Modify the text of the "Rule" menu _ui->_ruleMenu->setTitle (tr ("Goal")); _ui->_execConstraintGroupBox->setTitle("Execute Goal Only When"); _ui->_descrGroupBox->setTitle("Goal Description"); } // Some actions are only permitted within optimization goal sets. const bool isOpt (_rplBlock->appIsOpt()); _ui->_addConstraintAction->setVisible(isOpt); _ui->_addFreezeAction->setVisible(isOpt); _ui->_addRewardTableAction->setVisible(isOpt); // Hide non-optimization menus and menu-items for non-optimization // applications. if (!isOpt) { _ui->_addObjectiveMenu->menuAction()->setVisible (false); _ui->_softConstraintMenu->menuAction()->setVisible (false); } // Assignment statements are not permitted within an optimization goal set, // unless an unadvertised riverware command line argument was present. _ui->_addAssignmentAction->setVisible(!isOpt || rwPermitGoalAssignments); updateFileMenuAppText(_ui->_printRplSetAction, _ui->_closeAction); QString setEditorText = RplDlgMgr::getObjTypeString(_rplBlock->getSet()) + " Editor..."; _ui->_setEditorAction->setText(setEditorText); // For the Initialization Rules application only, the user can // select among a few set value flag options. const bool isInitRule (_rplBlock->appIsInitRules()); _ui->_setValueFlagWidget->setVisible(isInitRule); if (isInitRule) { static const QString flag("%1 (%2)"); QString ruleFlagText( flag.arg(ValueState::flagAsString(ValueState::RULE)) .arg(SlotGUIUtils::getFlagStr(RULE_VALUE_STATE))); QString dmiInputFlagText( flag.arg(ValueState::flagAsString(ValueState::DMI_INPUT)) .arg(SlotGUIUtils::getFlagStr(DMI_INPUT_VALUE_STATE))); // Items are appended, so we should add them in index order // as defined at the top of the file. _ui->_setValueFlagComboBox-> addItem(ruleFlagText, QVariant(int(ValueState::RULE))); _ui->_setValueFlagComboBox-> addItem(dmiInputFlagText, QVariant(int(ValueState::DMI_INPUT))); if (_rplBlock->getSetValueFlag() == ValueState::DMI_INPUT) { _ui->_setValueFlagComboBox-> setCurrentIndex(SET_FLAG_IS_DMI_INPUT_INDEX); } else if (_rplBlock->getSetValueFlag() == ValueState::RULE) { _ui->_setValueFlagComboBox-> setCurrentIndex(SET_FLAG_IS_RULE_INDEX); } else { rwAssert(false); } connect(_ui->_setValueFlagComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setValueFlagChangedHandler(int))); } // Executing scripts is only allowed in the MRM application if (appType == RplApplication::MRM) { _ui->_addExecScriptAction->setVisible(true); } else { _ui->_addExecScriptAction->setVisible(false); } } void RplBlockDlg::setValueFlagChangedHandler(int index) { switch(index) { case SET_FLAG_IS_RULE_INDEX: _rplBlock->setSetValueFlag(ValueState::RULE); break; case SET_FLAG_IS_DMI_INPUT_INDEX: _rplBlock->setSetValueFlag(ValueState::DMI_INPUT); break; default: rwAssert(false); } } // // Add a horizontal row of visibility toggles (check boxes which // control the display of optionally displayed aspects of this dialog). // void RplBlockDlg::initVisibilityToggles() { _toggles = new RowOToggles(this, tr("Show: ")); _ui->_bodyPlaceholderWidget->layout()->addWidget(_toggles); _showExecConstraintToggleIndex = _toggles->addToggle(tr("Execution Constraint")); _showDescriptionToggleIndex = _toggles->addToggle(tr("Description")); _showNotesToggleIndex = _toggles->addToggle(tr("Notes")); _showCommentsToggleIndex = _toggles->addToggle(tr("Comments")); _toggles->setToggleOn(_showDescriptionToggleIndex, _ui->_showDescriptionAction->isChecked()); _toggles->setToggleOn(_showNotesToggleIndex, _ui->_showNotesAction->isChecked()); _toggles->setToggleOn(_showExecConstraintToggleIndex, _ui->_showConstraintAction->isChecked()); _toggles->setToggleOn(_showCommentsToggleIndex, _bodyRplFrame->showComments()); // Notice when the user clicks a toggle. connect(_toggles, SIGNAL(stateChanged(int, bool)), this, SLOT(visibilityToggleChangedHandler(int, bool))); // The state of most toggles are updated in showOptionalFrames(), // but inline comments are different. connect(_bodyRplFrame, SIGNAL(showCommentsChanged(bool)), this, SLOT(showCommentsChangedHandler(bool))); // Each toggle provides a visual indication of whether there is non-trivial // content in the item whose display is controlled by the toggle. updateDescriptionToggleRelevance(); updateNotesToggleRelevance(); updateExecConstraintToggleRelevance(); updateCommentsToggleRelevance(); // Note: we maintain the appearance of some toggles using signals // directly, but others are updated in signal handler methods. connect(_bodyRplFrame, SIGNAL(editted()), this, SLOT(updateCommentsToggleRelevance())); connect(_constraintRplFrame, SIGNAL(editted()), this, SLOT(updateCommentsToggleRelevance())); connect(_constraintRplFrame, SIGNAL(editted()), this, SLOT(updateExecConstraintToggleRelevance())); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::loadSettings() { } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::saveSettings() const { } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- void RplBlockDlg::updateDmiDisplay() { const bool hasPreDmiObj = _rplBlock->hasPreExecDmiObj(); const bool hasPostDmiObj = _rplBlock->hasPostExecDmiObj(); // Update the text in the action if (hasPreDmiObj) _ui->_preDmiEdit->setText(_rplBlock->preExecDmiObjName()); if (hasPostDmiObj) _ui->_postDmiEdit->setText(_rplBlock->postExecDmiObjName()); // Show/hide the frame _ui->_preDmiWidget->setVisible(hasPreDmiObj); _ui->_postDmiWidget->setVisible(hasPostDmiObj); QString preDmiStr; if (!hasPreDmiObj) preDmiStr = "Add"; else preDmiStr = "Remove"; QString postDmiStr; if (!hasPostDmiObj) postDmiStr = "Add"; else postDmiStr = "Remove"; _ui->_addPreDmiAction->setText(preDmiStr + " Pre-execution DMI Group"); _ui->_addPostDmiAction->setText(postDmiStr + " Post-execution DMI Group"); } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // public, virtual from RplBaseDlg void RplBlockDlg::updateExternalDocButton() { initExternalDocButton (_ui->_externalDocPushButton); } //---------------------------------------------------------------------------- // Update actions in the edit menu. //---------------------------------------------------------------------------- void RplBlockDlg::aboutToShowEditMenu() { // Which edit actions are available is fairly dynamic, depending for // example on the state of the run and the current selection, so we // update the enabled state of the edit actions every time. updateEditActions(); // Also the toggle state of the enabled action depends on the selection. _ui->_enableAction->setChecked(true); _bodyRplFrame ->updateEnableAction(_ui->_enableAction); _constraintRplFrame->updateEnableAction(_ui->_enableAction); } //---------------------------------------------------------------------------- // Update actions in the view menu. //---------------------------------------------------------------------------- void RplBlockDlg::aboutToShowViewMenu() { _ui->_showCommentsAction->setChecked(_bodyRplFrame->showComments()); updateExternalDocOps (_ui->_externalDocPushButton, _ui->_extDocMenu, _ui->_viewExtDocAction, _ui->_editExtDocAction); } //---------------------------------------------------------------------------- // Update actions in the Rule menu. //---------------------------------------------------------------------------- void RplBlockDlg::aboutToShowRuleMenu() { // Breakpoint actions apply to a particular statement; which statement // depends on the action and the RPL selection. If one of our statements // contains the RPL selection, breakpoint actions apply to that statement. // Otherwise (in the absence of a statement selection), "Break Before" // applies to the first statement and "Break After" applies to the last // statement bool debuggingEnabled(rplDebugger->isDebuggingEnabled()); const RplStmtList* stmts(_rplBlock->getStatements()); bool aStmtExists(_rplBlock && (_rplBlock->statementCount() > 0)); bool breakBeforeExists(false); bool breakAfterExists(false); bool breakAfterStmtIsLast(false); if (aStmtExists) { const RplStatement* firstStmt(stmts->get(0)); const RplStatement* lastStmt(stmts->get(_rplBlock->statementCount()-1)); // Does one of our statements contain the RPL selection? const RplStatement* selectionStmt(NULL); VisualToken* selectedItem(RplFrame::selection()->getSelectedItem()); const RplObj* obj(selectedItem ? selectedItem->getRplObj() : NULL); if (obj && obj->isA(Rpl::RPL_STATEMENT) && (RplFrame::selection()->getFrame() == _bodyRplFrame)) { selectionStmt = static_cast(obj); } // To which statement does each action apply? const RplStatement* breakBeforeStmt; const RplStatement* breakAfterStmt; if (selectionStmt) { breakBeforeStmt = selectionStmt; breakAfterStmt = selectionStmt; } else { breakBeforeStmt = firstStmt; breakAfterStmt = lastStmt; } breakAfterStmtIsLast = (breakAfterStmt == lastStmt); // Are there already breakpoints at these statements? RplDebugger::Location beforeLocation(breakBeforeStmt, NULL, RplDebugger::BEFORE_EXEC); breakBeforeExists = rplDebugger->hasBreakpoint(beforeLocation); RplDebugger::Location afterLocation(breakAfterStmt, NULL, RplDebugger::AFTER_EXEC); breakAfterExists = rplDebugger->hasBreakpoint(afterLocation); } _ui->_breakBeforeExecAction->setChecked(breakBeforeExists); _ui->_breakAfterExecAction ->setChecked(breakAfterExists); _ui->_breakBeforeExecAction->setEnabled(debuggingEnabled && aStmtExists); _ui->_breakAfterExecAction ->setEnabled(debuggingEnabled && aStmtExists && breakAfterStmtIsLast); _ui->_stopOnNaNAction->setChecked(_rplBlock->stopOnNaN()); } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // The GUI's idea of the object's name (as opposed to the object's name). QString RplBlockDlg::nameEditorText() const { return _ui->_nameEdit->text(); } // // If our body frame includes the debug cursor (location at which debugging // is currently paused), scroll that cursor into view. // // Note: it's not possible to pause in our execution constraint frame. // void RplBlockDlg::scrollToDebugCursor() { if (_bodyRplFrame) { _bodyRplFrame->scrollToDebugCursor(); } } void RplBlockDlg::stopOnNaNHandler(bool stop) { _rplBlock->setStopOnNaN(stop); } void RplBlockDlg::updateDescriptionToggleRelevance() { bool emptyDescription(_ui->_descrEdit->toPlainText().isEmpty()); _toggles->setToggleRelevant(_showDescriptionToggleIndex, !emptyDescription); if ( !emptyDescription ) { QString desc = _ui->_descrEdit->toPlainText(); _toggles->setToggleToolTip( _showDescriptionToggleIndex, desc ); } else { _toggles->setToggleToolTip( _showDescriptionToggleIndex, QString() ); } } void RplBlockDlg::updateNotesToggleRelevance() { bool emptyNotes(_ui->_notesEdit->toPlainText().isEmpty()); _toggles->setToggleRelevant(_showNotesToggleIndex, !emptyNotes); if (!emptyNotes) { QString notes = _ui->_notesEdit->toPlainText(); _toggles->setToggleToolTip(_showNotesToggleIndex, notes); } else { _toggles->setToggleToolTip(_showNotesToggleIndex, QString()); } } void RplBlockDlg::updateExecConstraintToggleRelevance() { _toggles->setToggleRelevant(_showExecConstraintToggleIndex, !_rplBlock->execConstraintIsTrivial()); } void RplBlockDlg::updateCommentsToggleRelevance() { bool aCommentExists((_bodyRplFrame && _bodyRplFrame->containsAComment()) || (_constraintRplFrame && _constraintRplFrame->containsAComment())); _toggles->setToggleRelevant(_showCommentsToggleIndex, aCommentExists); } void RplBlockDlg::visibilityToggleChangedHandler(int toggleIndex, bool on) { if (toggleIndex == _showDescriptionToggleIndex) { _ui->_showDescriptionAction->setChecked(on); showOptionalFrames(); } else if (toggleIndex == _showExecConstraintToggleIndex) { _ui->_showConstraintAction->setChecked(on); showOptionalFrames(); } else if (toggleIndex == _showNotesToggleIndex) { _ui->_showNotesAction->setChecked(on); showOptionalFrames(); } else if (toggleIndex == _showCommentsToggleIndex) { _bodyRplFrame->setShowComments(on); if (_constraintRplFrame) { _constraintRplFrame->setShowComments(on); } // Note: we don't really need to update the state of the View menu // action because it is updated before the menu is shown, but what // the heck. _ui->_showCommentsAction->setChecked(on); } else { rwDebugAssert(false); } } void RplBlockDlg::showCommentsChangedHandler(bool show) { _toggles->setToggleOn(_showCommentsToggleIndex, show); } // virtual void RplBlockDlg::selectRplStatement(RplStatement* statement) { VisualToken* token(NULL); token = _bodyRplFrame->findRplObjToken(statement); if (!token) { return; } RplFrame::selection()->clear(); RplFrame::selection()->setSelectedItem(token, _bodyRplFrame, true); _bodyRplFrame->updateLayout(); } // virtual override of BaseRWDlg method void RplBlockDlg::showDescription(bool) { if (!_ui->_showDescriptionAction->isChecked()) { _ui->_showDescriptionAction->activate(QAction::Trigger); } } // virtual override of BaseRWDlg method void RplBlockDlg::showNotes(bool) { if (!_ui->_showNotesAction->isChecked()) { _ui->_showNotesAction->activate(QAction::Trigger); } } // virtual override void RplBlockDlg::selectStringInDescription( const Rpl::SearchSpec& searchSpec) { RplGUI::selectSearchSpecInQTextEdit(searchSpec, _ui->_descrEdit); } // virtual override void RplBlockDlg::selectStringInNotes( const Rpl::SearchSpec& searchSpec) { RplGUI::selectSearchSpecInQTextEdit(searchSpec, _ui->_notesEdit); } //--- (end RplBlockDlg.cpp) ---