From c3aaa69f51067f700cca4a9bf150ba5d797ec0b6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 21 Jul 2019 15:53:14 +0200 Subject: [PATCH] Fix some regressions of PR 2330 fix file chooser in macro dialog do not remove GUI text from translation remove friend class declaration, use Qt's introspection mechanism create dialogs on the stack because they are modal some minor optimizations --- src/Gui/DlgMacroExecute.ui | 3 + src/Gui/DlgMacroExecuteImp.cpp | 130 +++++++++++++++++---------------- src/Gui/DlgToolbarsImp.cpp | 2 +- src/Gui/DlgToolbarsImp.h | 2 - 4 files changed, 72 insertions(+), 65 deletions(-) diff --git a/src/Gui/DlgMacroExecute.ui b/src/Gui/DlgMacroExecute.ui index 2b6d588363..9aac7e4152 100644 --- a/src/Gui/DlgMacroExecute.ui +++ b/src/Gui/DlgMacroExecute.ui @@ -166,6 +166,9 @@ Qt::StrongFocus + + Gui::FileChooser::Directory + diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index cca56f1078..134ae169a0 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -27,7 +27,6 @@ # include # include # include -# include #endif #include "DlgMacroExecuteImp.h" @@ -421,17 +420,17 @@ void DlgMacroExecuteImp::on_deleteButton_clicked() * toolbar dialog. */ -void DlgMacroExecuteImp::on_toolbarButton_clicked(){ - +void DlgMacroExecuteImp::on_toolbarButton_clicked() +{ /** * advise user of what we are doing, offer chance to cancel * unless user already said not to show this messagebox again **/ - bool showAgain = App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/Preferences/Macro"))->GetBool("ShowWalkthroughMessage",true); + bool showAgain = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("ShowWalkthroughMessage", true); if (showAgain){ QMessageBox msgBox; - QAbstractButton* doNotShowAgainButton = msgBox.addButton(tr("Do not show again"),QMessageBox::YesRole); + QAbstractButton* doNotShowAgainButton = msgBox.addButton(tr("Do not show again"), QMessageBox::YesRole); msgBox.setText(tr("Guided Walkthrough")); msgBox.setInformativeText(tr("This will guide you in setting up this macro in a custom \ global toolbar. Instructions will be in red text inside the dialog.\n\ @@ -443,22 +442,21 @@ Note: your changes will be applied when you next switch workbenches\n")); if (result == QMessageBox::Cancel){ return; } - if (msgBox.clickedButton()==doNotShowAgainButton){ - App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/Preferences/Macro")) - ->SetBool("ShowWalkthroughMessage",false); + if (msgBox.clickedButton() == doNotShowAgainButton){ + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("ShowWalkthroughMessage",false); } } + QTreeWidgetItem* item = userMacroListBox->currentItem(); if (!item) return; QString fn = item->text(0); - QString bareFileName = fn; //for use as default menu text (filename without extension) - bareFileName.remove(QString::fromLatin1(".FCMacro").remove(QString::fromLatin1(".py"))); + QString bareFileName = QFileInfo(fn).baseName(); //for use as default menu text (filename without extension) /** check if user already has custom toolbar, so we can tailor instructions accordingly **/ bool hasCustomToolbar = true; - if (App::GetApplication().GetParameterGroupByPath(QByteArray("User parameter:BaseApp/Workbench/Global/Toolbar"))->GetGroups().size()==0){ + if (App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbench/Global/Toolbar")->GetGroups().empty()) { hasCustomToolbar=false; } @@ -468,38 +466,37 @@ Note: your changes will be applied when you next switch workbenches\n")); CommandManager & cCmdMgr = Application::Instance->commandManager(); std::vector aCmds = cCmdMgr.getGroupCommands("Macros"); for (std::vector::iterator it = aCmds.begin(); it != aCmds.end(); ++it) { - MacroCommand* mc = (MacroCommand*)(*it); - if(QString::fromLatin1(mc->getScriptName()) == fn){ + MacroCommand* mc = dynamic_cast(*it); + if (mc && fn.compare(QLatin1String(mc->getScriptName())) == 0) { hasMacroCommand = true; macroMenuText = QString::fromLatin1(mc->getMenuText()); } } - QTabWidget* tabWidget = (QTabWidget*) 0; - static QPointer dlg = 0; + QTabWidget* tabWidget = nullptr; if (!hasMacroCommand){ /** first the custom macros page dialog **/ - if (!dlg) - dlg = new Gui::Dialog::DlgCustomizeImp(this); - dlg->setAttribute(Qt::WA_DeleteOnClose); - dlg->setModal(true); - /** title is normally "Customize" **/ - dlg->setWindowTitle(tr("Walkthrough, dialog 1 of 2")); + Gui::Dialog::DlgCustomizeImp dlg(this); - tabWidget = dlg->findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); - if (!tabWidget){ + /** title is normally "Customize" **/ + dlg.setWindowTitle(tr("Walkthrough, dialog 1 of 2")); + + tabWidget = dlg.findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); + if (!tabWidget) { std::cerr << "Toolbar walkthrough error: Unable to find tabwidget" << std::endl; return; } - QWidget* setupCustomMacrosPage = tabWidget->findChild(QString::fromUtf8("Gui__Dialog__DlgCustomActions")); - if (!setupCustomMacrosPage){ + + QWidget* setupCustomMacrosPage = tabWidget->findChild(QString::fromLatin1("Gui__Dialog__DlgCustomActions")); + if (!setupCustomMacrosPage) { std::cerr << "Toolbar walkthrough error: Unable to find setupCustomMacrosPage" << std::endl; return; } tabWidget->setCurrentWidget(setupCustomMacrosPage); - QGroupBox* groupBox7 = setupCustomMacrosPage->findChild(QString::fromUtf8("GroupBox7")); - if (!groupBox7){ + + QGroupBox* groupBox7 = setupCustomMacrosPage->findChild(QString::fromLatin1("GroupBox7")); + if (!groupBox7) { Base::Console().Warning("Toolbar walkthrough: Unable to find groupBox7\n"); //just warn when not a fatal error } else { @@ -508,56 +505,56 @@ Note: your changes will be applied when you next switch workbenches\n")); groupBox7->setStyleSheet(QString::fromLatin1("QGroupBox::title {color:red}")); } - QPushButton* buttonAddAction = setupCustomMacrosPage->findChild(QString::fromUtf8("buttonAddAction")); - if (!buttonAddAction){ + QPushButton* buttonAddAction = setupCustomMacrosPage->findChild(QString::fromLatin1("buttonAddAction")); + if (!buttonAddAction) { Base::Console().Warning("Toolbar walkthrough: Unable to find buttonAddAction\n"); } else { buttonAddAction->setStyleSheet(QString::fromLatin1("color:red")); } - QComboBox* macroListBox = setupCustomMacrosPage->findChild(QString::fromUtf8("actionMacros")); - if (!macroListBox){ + QComboBox* macroListBox = setupCustomMacrosPage->findChild(QString::fromLatin1("actionMacros")); + if (!macroListBox) { Base::Console().Warning("Toolbar walkthrough: Unable to find actionMacros combo box\n"); } else { int macroIndex = macroListBox->findText(fn); //fn is the macro filename macroListBox->setCurrentIndex(macroIndex); //select it for the user so he doesn't have to } - QLineEdit* menuText = setupCustomMacrosPage->findChild(QString::fromUtf8("actionMenu")); - if (!menuText){ + + QLineEdit* menuText = setupCustomMacrosPage->findChild(QString::fromLatin1("actionMenu")); + if (!menuText) { Base::Console().Warning("Toolbar walkthrough: Unable to find actionMenu menuText\n"); } else { menuText->setText(bareFileName); //user can fill in other fields, e.g. tooltip } - dlg->exec(); + + dlg.exec(); } /** now for the toolbar selection dialog **/ - dlg = 0; - if (!dlg){ - dlg = new Gui::Dialog::DlgCustomizeImp(this); - } - dlg->setAttribute(Qt::WA_DeleteOnClose); - dlg->setModal(true); - if(hasMacroCommand){ - dlg->setWindowTitle(tr("Walkthrough, dialog 1 of 1")); + Gui::Dialog::DlgCustomizeImp dlg(this); + + if (hasMacroCommand){ + dlg.setWindowTitle(tr("Walkthrough, dialog 1 of 1")); } else { - dlg->setWindowTitle(tr("Walkthrough, dialog 2 of 2")); + dlg.setWindowTitle(tr("Walkthrough, dialog 2 of 2")); } - tabWidget = (QTabWidget*) 0; - tabWidget = dlg->findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); - if (!tabWidget){ + tabWidget = nullptr; + tabWidget = dlg.findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); + if (!tabWidget) { std::cerr << "Toolbar walkthrough: Unable to find tabWidget Gui__Dialog__TabWidget" << std::endl; return; } - DlgCustomToolbars* setupToolbarPage = tabWidget->findChild(QString::fromUtf8("Gui__Dialog__DlgCustomToolbars")); + + DlgCustomToolbars* setupToolbarPage = tabWidget->findChild(QString::fromLatin1("Gui__Dialog__DlgCustomToolbars")); if (!setupToolbarPage){ std::cerr << "Toolbar walkthrough: Unable to find setupToolbarPage Gui__Dialog__DlgCustomToolbars" << std::endl; return; } + tabWidget->setCurrentWidget(setupToolbarPage); - QPushButton* moveActionRightButton = setupToolbarPage->findChild(QString::fromUtf8("moveActionRightButton")); + QPushButton* moveActionRightButton = setupToolbarPage->findChild(QString::fromLatin1("moveActionRightButton")); if (!moveActionRightButton){ Base::Console().Warning("Toolbar walkthrough: Unable to find moveActionRightButton\n"); } else { @@ -568,21 +565,26 @@ Note: your changes will be applied when you next switch workbenches\n")); **/ QString instructions2 = tr("Walkthrough instructions: Click right arrow button (->), then Close."); - QComboBox* workbenchBox = setupToolbarPage->findChild(QString::fromUtf8("workbenchBox")); - if (!workbenchBox){ + QComboBox* workbenchBox = setupToolbarPage->findChild(QString::fromLatin1("workbenchBox")); + if (!workbenchBox) { Base::Console().Warning("Toolbar walkthrough: Unable to find workbenchBox\n"); - } else { + } + else { /** find the Global workbench and select it for the user **/ - int globalIdx = workbenchBox->findText(QString::fromLatin1("Global"));; + int globalIdx = workbenchBox->findData(QString::fromLatin1("Global")); if (globalIdx != -1){ workbenchBox->setCurrentIndex(globalIdx); - setupToolbarPage->on_workbenchBox_activated(globalIdx); + QMetaObject::invokeMethod(setupToolbarPage, "on_workbenchBox_activated", + Qt::DirectConnection, + QGenericReturnArgument(), + Q_ARG(int, globalIdx)); } else { Base::Console().Warning("Toolbar walkthrough: Unable to find Global workbench\n"); } + if (!hasCustomToolbar){ - QPushButton* newButton = setupToolbarPage->findChild(QString::fromUtf8("newButton")); + QPushButton* newButton = setupToolbarPage->findChild(QString::fromLatin1("newButton")); if (!newButton){ Base::Console().Warning("Toolbar walkthrough: Unable to find newButton\n"); } else { @@ -602,21 +604,25 @@ Note: your changes will be applied when you next switch workbenches\n")); } /** find Macros category and select it for the user **/ - QComboBox* categoryBox = setupToolbarPage->findChild(QString::fromUtf8("categoryBox")); + QComboBox* categoryBox = setupToolbarPage->findChild(QString::fromLatin1("categoryBox")); if (!categoryBox){ Base::Console().Warning("Toolbar walkthrough: Unable to find categoryBox\n"); } else { int macrosIdx = categoryBox->findText(tr("Macros")); if (macrosIdx != -1){ categoryBox->setCurrentIndex(macrosIdx); - setupToolbarPage->on_categoryBox_activated(macrosIdx); + QMetaObject::invokeMethod(setupToolbarPage, "on_categoryBox_activated", + Qt::DirectConnection, + QGenericReturnArgument(), + Q_ARG(int, macrosIdx)); } else { Base::Console().Warning("Toolbar walkthrough: Unable to find Macros in categoryBox\n"); } } + /** expand custom toolbar items **/ - QTreeWidget* toolbarTreeWidget = setupToolbarPage->findChild(QString::fromUtf8("toolbarTreeWidget")); - if (!toolbarTreeWidget){ + QTreeWidget* toolbarTreeWidget = setupToolbarPage->findChild(QString::fromLatin1("toolbarTreeWidget")); + if (!toolbarTreeWidget) { Base::Console().Warning("Toolbar walkthrough: Unable to find toolbarTreeWidget\n"); } else { toolbarTreeWidget->expandAll(); @@ -624,8 +630,8 @@ Note: your changes will be applied when you next switch workbenches\n")); /** preselect macro command for user **/ - QTreeWidget* commandTreeWidget = setupToolbarPage->findChild(QString::fromUtf8("commandTreeWidget")); - if (!commandTreeWidget){ + QTreeWidget* commandTreeWidget = setupToolbarPage->findChild(QString::fromLatin1("commandTreeWidget")); + if (!commandTreeWidget) { Base::Console().Warning("Toolbar walkthrough: Unable to find commandTreeWidget\n"); } else { if (!hasMacroCommand){ //will be the last in the list, the one just created @@ -633,13 +639,13 @@ Note: your changes will be applied when you next switch workbenches\n")); commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); } else { //pre-select it for the user (will be the macro menu text) QList items = commandTreeWidget->findItems(macroMenuText, Qt::MatchFixedString | Qt::MatchWrap,1); - if(items.size()!=0){ + if (!items.empty()) { commandTreeWidget->setCurrentItem(items[0]); commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); } } } - dlg->exec(); + dlg.exec(); } diff --git a/src/Gui/DlgToolbarsImp.cpp b/src/Gui/DlgToolbarsImp.cpp index a52ee2d7b1..062672d4d2 100644 --- a/src/Gui/DlgToolbarsImp.cpp +++ b/src/Gui/DlgToolbarsImp.cpp @@ -112,7 +112,7 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent) QStringList workbenches = Application::Instance->workbenches(); workbenches.sort(); index = 1; - workbenchBox->addItem(QApplication::windowIcon(), QString::fromLatin1("Global")); + workbenchBox->addItem(QApplication::windowIcon(), tr("Global")); workbenchBox->setItemData(0, QVariant(QString::fromLatin1("Global")), Qt::UserRole); for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { QPixmap px = Application::Instance->workbenchIcon(*it); diff --git a/src/Gui/DlgToolbarsImp.h b/src/Gui/DlgToolbarsImp.h index 5c0486be3a..ff0c4424e5 100644 --- a/src/Gui/DlgToolbarsImp.h +++ b/src/Gui/DlgToolbarsImp.h @@ -26,7 +26,6 @@ #include "ui_DlgToolbars.h" #include "PropertyPage.h" -#include "DlgMacroExecuteImp.h" namespace Gui { namespace Dialog { @@ -44,7 +43,6 @@ class DlgCustomToolbars : public CustomizeActionPage, public Ui_DlgCustomToolbar Q_OBJECT protected: - friend class DlgMacroExecuteImp; enum Type { Toolbar, Toolboxbar }; DlgCustomToolbars(Type, QWidget* parent = 0);