From 16313216c747ec1c5469ce8183789ff19afc7403 Mon Sep 17 00:00:00 2001 From: Paddle Date: Wed, 22 Mar 2023 19:03:19 +0100 Subject: [PATCH 01/22] Preferences: Workbench : Add possibility to enable/disable workbench here. --- src/Gui/DlgSettingsLazyLoaded.ui | 2 +- src/Gui/DlgSettingsLazyLoadedImp.cpp | 83 +++++++++++++++++++++++++--- src/Gui/DlgSettingsLazyLoadedImp.h | 3 + 3 files changed, 79 insertions(+), 9 deletions(-) diff --git a/src/Gui/DlgSettingsLazyLoaded.ui b/src/Gui/DlgSettingsLazyLoaded.ui index 34f8232b54..ec90d14ff4 100644 --- a/src/Gui/DlgSettingsLazyLoaded.ui +++ b/src/Gui/DlgSettingsLazyLoaded.ui @@ -29,7 +29,7 @@ - <html><head/><body><p>To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.</p><p>The following workbenches are available in your installation:</p></body></html> + <html><head/><body><p>To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.</p><p>Enabling or disabling workbenches requires a restart of the application.</p><p>The following workbenches are available in your installation:</p></body></html> true diff --git a/src/Gui/DlgSettingsLazyLoadedImp.cpp b/src/Gui/DlgSettingsLazyLoadedImp.cpp index e41bb5d152..7cdda7c9e0 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.cpp +++ b/src/Gui/DlgSettingsLazyLoadedImp.cpp @@ -40,10 +40,11 @@ const uint DlgSettingsLazyLoadedImp::WorkbenchNameRole = Qt::UserRole; // this enum defines the order of the columns enum Column { - Load, - CheckBox, + Enabled, Icon, - Name + Name, + CheckBox, + Load }; /* TRANSLATOR Gui::Dialog::DlgSettingsLazyLoadedImp */ @@ -68,6 +69,30 @@ DlgSettingsLazyLoadedImp::~DlgSettingsLazyLoadedImp() void DlgSettingsLazyLoadedImp::saveSettings() { + //Save enabled + std::ostringstream enabledStr; + std::ostringstream disabledStr; + for (const auto& checkBox : _enabledCheckBoxes) { + if (checkBox.second->isChecked()) { + if (!enabledStr.str().empty()) + enabledStr << ","; + enabledStr << checkBox.first.toStdString(); + } + else { + if (!disabledStr.str().empty()) + disabledStr << ","; + disabledStr << checkBox.first.toStdString(); + } + } + + if (!enabledStr.str().empty()) //make sure that we have at least one enabled workbench. + enabledStr << "NoneWorkbench"; + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); + hGrp->SetASCII("Enabled", enabledStr.str().c_str()); + hGrp->SetASCII("Disabled", disabledStr.str().c_str()); + + //Save auto-load std::ostringstream csv; for (const auto& checkBox : _autoloadCheckBoxes) { if (checkBox.second->isChecked()) { @@ -132,22 +157,26 @@ void DlgSettingsLazyLoadedImp::buildUnloadedWorkbenchList() { QStringList workbenches = Application::Instance->workbenches(); workbenches.sort(); + QStringList enabled_wbs_list = getEnabledWorkbenches(); ui->workbenchTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); ui->workbenchTable->setRowCount(0); _autoloadCheckBoxes.clear(); // setRowCount(0) just invalidated all of these pointers - ui->workbenchTable->setColumnCount(4); + _enabledCheckBoxes.clear();// setRowCount(0) just invalidated all of these pointers + ui->workbenchTable->setColumnCount(5); ui->workbenchTable->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection); + ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Enabled, QHeaderView::ResizeMode::ResizeToContents); ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Icon, QHeaderView::ResizeMode::ResizeToContents); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Name, QHeaderView::ResizeMode::Stretch); + ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Name, QHeaderView::ResizeMode::ResizeToContents); ui->workbenchTable->horizontalHeader()->setSectionResizeMode(CheckBox, QHeaderView::ResizeMode::ResizeToContents); ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Load, QHeaderView::ResizeMode::ResizeToContents); QStringList columnHeaders; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 5; i++) { switch (i) { + case Enabled : columnHeaders << tr("Enable"); break; case Icon : columnHeaders << QString(); break; case Name : columnHeaders << tr("Workbench Name"); break; - case CheckBox: columnHeaders << tr("Autoload?"); break; + case CheckBox: columnHeaders << tr("Autoload"); break; case Load : columnHeaders << QString(); break; } } @@ -160,6 +189,19 @@ void DlgSettingsLazyLoadedImp::buildUnloadedWorkbenchList() ui->workbenchTable->insertRow(rowNumber); auto wbTooltip = Application::Instance->workbenchToolTip(wbName); + auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); + + // Column 0: Enabled checkbox. + auto enCheckWidget = new QWidget(this); + auto enableCheckBox = new QCheckBox(this); + enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); + auto enCheckLayout = new QHBoxLayout(enCheckWidget); + enCheckLayout->addWidget(enableCheckBox); + enCheckLayout->setAlignment(Qt::AlignCenter); + enCheckLayout->setContentsMargins(0, 0, 0, 0); + enableCheckBox->setChecked(enabled_wbs_list.contains(wbName)); + _enabledCheckBoxes.insert(std::make_pair(wbName, enableCheckBox)); + ui->workbenchTable->setCellWidget(rowNumber, Enabled, enCheckWidget); // Column 1: Workbench Icon auto wbIcon = Application::Instance->workbenchIcon(wbName); @@ -170,7 +212,6 @@ void DlgSettingsLazyLoadedImp::buildUnloadedWorkbenchList() ui->workbenchTable->setCellWidget(rowNumber, Icon, iconLabel); // Column 2: Workbench Display Name - auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); auto textLabel = new QLabel(wbDisplayName); textLabel->setToolTip(wbTooltip); ui->workbenchTable->setCellWidget(rowNumber, Name, textLabel); @@ -218,6 +259,32 @@ void DlgSettingsLazyLoadedImp::buildUnloadedWorkbenchList() } } +QStringList DlgSettingsLazyLoadedImp::getEnabledWorkbenches() +{ + QString enabled_wbs; + QStringList enabled_wbs_list; + ParameterGrp::handle hGrp; + QString allWorkbenches = QString::fromLatin1("ALL"); + + hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); + enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", allWorkbenches.toStdString().c_str()).c_str()); +#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) + enabled_wbs_list = enabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts); +#else + enabled_wbs_list = enabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts); +#endif + + if (enabled_wbs_list.at(0) == allWorkbenches) { + enabled_wbs_list.removeFirst(); + QStringList workbenches = Application::Instance->workbenches(); + for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { + enabled_wbs_list.append(*it); + } + enabled_wbs_list.sort(); + } + return enabled_wbs_list; +} + /** * Sets the strings of the subwidgets using the current language. */ diff --git a/src/Gui/DlgSettingsLazyLoadedImp.h b/src/Gui/DlgSettingsLazyLoadedImp.h index 75a5e65e2e..11d54757ee 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.h +++ b/src/Gui/DlgSettingsLazyLoadedImp.h @@ -50,6 +50,8 @@ public: void saveSettings() override; void loadSettings() override; + static QStringList getEnabledWorkbenches(); + protected Q_SLOTS: void onLoadClicked(const QString& wbName); @@ -64,6 +66,7 @@ private: std::vector _backgroundAutoloadedModules; std::string _startupModule; std::map _autoloadCheckBoxes; + std::map _enabledCheckBoxes; }; } // namespace Dialog From 4d1840a04ecea72893709bd1cd824e99e2a8a497 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 24 Mar 2023 08:07:30 +0100 Subject: [PATCH 02/22] Preferences: Workbench : Enable reordering workbenches with 2 buttons. --- src/Gui/DlgSettingsLazyLoaded.ui | 15 -- src/Gui/DlgSettingsLazyLoadedImp.cpp | 342 +++++++++++++++++---------- src/Gui/DlgSettingsLazyLoadedImp.h | 14 +- 3 files changed, 227 insertions(+), 144 deletions(-) diff --git a/src/Gui/DlgSettingsLazyLoaded.ui b/src/Gui/DlgSettingsLazyLoaded.ui index ec90d14ff4..3447f17d34 100644 --- a/src/Gui/DlgSettingsLazyLoaded.ui +++ b/src/Gui/DlgSettingsLazyLoaded.ui @@ -52,21 +52,6 @@ - - - - - - - - - - - - - - - diff --git a/src/Gui/DlgSettingsLazyLoadedImp.cpp b/src/Gui/DlgSettingsLazyLoadedImp.cpp index 7cdda7c9e0..2566bf5b46 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.cpp +++ b/src/Gui/DlgSettingsLazyLoadedImp.cpp @@ -30,6 +30,7 @@ #include "DlgSettingsLazyLoadedImp.h" #include "ui_DlgSettingsLazyLoaded.h" #include "Application.h" +#include "BitmapFactory.h" #include "Workbench.h" #include "WorkbenchManager.h" @@ -38,14 +39,12 @@ using namespace Gui::Dialog; const uint DlgSettingsLazyLoadedImp::WorkbenchNameRole = Qt::UserRole; -// this enum defines the order of the columns -enum Column { - Enabled, - Icon, - Name, - CheckBox, - Load -}; +const int DlgSettingsLazyLoadedImp::columnCount = 1; + +const QString DlgSettingsLazyLoadedImp::loadLabelStr = QString::fromLatin1("loadLabel"); +const QString DlgSettingsLazyLoadedImp::loadButtonStr = QString::fromLatin1("loadButton"); +const QString DlgSettingsLazyLoadedImp::enableCheckboxStr = QString::fromLatin1("enableCheckbox"); +const QString DlgSettingsLazyLoadedImp::autoloadCheckboxStr = QString::fromLatin1("autoloadCheckbox"); /* TRANSLATOR Gui::Dialog::DlgSettingsLazyLoadedImp */ @@ -69,40 +68,49 @@ DlgSettingsLazyLoadedImp::~DlgSettingsLazyLoadedImp() void DlgSettingsLazyLoadedImp::saveSettings() { - //Save enabled - std::ostringstream enabledStr; - std::ostringstream disabledStr; - for (const auto& checkBox : _enabledCheckBoxes) { - if (checkBox.second->isChecked()) { + std::ostringstream enabledStr, disabledStr, autoloadStr; + + for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { + QWidget* widget = ui->workbenchTable->cellWidget(i, 0); + if (!widget) + continue; + QCheckBox* enableBox = widget->findChild(enableCheckboxStr); + if (!enableBox) + continue; + + if (enableBox->isChecked()) { if (!enabledStr.str().empty()) enabledStr << ","; - enabledStr << checkBox.first.toStdString(); + enabledStr << widget->objectName().toStdString(); } else { if (!disabledStr.str().empty()) disabledStr << ","; - disabledStr << checkBox.first.toStdString(); + disabledStr << widget->objectName().toStdString(); + } + + QCheckBox* autoloadBox = widget->findChild(autoloadCheckboxStr); + if (!autoloadBox) + continue; + + if (autoloadBox->isChecked()) { + if (!autoloadStr.str().empty()) + autoloadStr << ","; + autoloadStr << widget->objectName().toStdString(); } } - if (!enabledStr.str().empty()) //make sure that we have at least one enabled workbench. + if (enabledStr.str().empty()) //make sure that we have at least one enabled workbench. enabledStr << "NoneWorkbench"; + else + disabledStr << "NoneWorkbench"; //Note, NoneWorkbench is not in the table so it's not added before. ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); hGrp->SetASCII("Enabled", enabledStr.str().c_str()); hGrp->SetASCII("Disabled", disabledStr.str().c_str()); - //Save auto-load - std::ostringstream csv; - for (const auto& checkBox : _autoloadCheckBoxes) { - if (checkBox.second->isChecked()) { - if (!csv.str().empty()) - csv << ","; - csv << checkBox.first.toStdString(); - } - } App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> - SetASCII("BackgroundAutoloadModules", csv.str().c_str()); + SetASCII("BackgroundAutoloadModules", autoloadStr.str().c_str()); } void DlgSettingsLazyLoadedImp::loadSettings() @@ -125,7 +133,7 @@ void DlgSettingsLazyLoadedImp::loadSettings() _backgroundAutoloadedModules.push_back(workbench); - buildUnloadedWorkbenchList(); + buildWorkbenchList(); } void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) @@ -136,129 +144,194 @@ void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) Application::Instance->activateWorkbench(originalActiveWB->name().c_str()); // replace load button with loaded indicator - auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { - QWidget* widget = ui->workbenchTable->cellWidget(i, Name); - auto textLabel = dynamic_cast(widget); - if (textLabel && textLabel->text() == wbDisplayName) { - auto label = new QLabel(tr("Loaded")); - label->setAlignment(Qt::AlignCenter); - ui->workbenchTable->setCellWidget(i, Load, label); + QWidget* widget = ui->workbenchTable->cellWidget(i, 0); + if (widget && widget->objectName() == wbName) { + QWidget* loadLabel = widget->findChild(loadLabelStr); + QWidget* loadButton = widget->findChild(loadButtonStr); + loadButton->setVisible(false); + loadLabel->setVisible(true); break; } } } +void DlgSettingsLazyLoadedImp::onUpDownClicked(const QString& wbName, bool up) +{ + int rowIndex = 0; + //find the index of the row that is moving. + for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { + QWidget* widget = ui->workbenchTable->cellWidget(i, 0); + if(widget->objectName() == wbName) { + break; + } + rowIndex++; + } + + //Check if it can move + if (((rowIndex == 0) && up) || ((rowIndex == ui->workbenchTable->rowCount() - 1) && !up)) + return; + + //Move in the _enabledCheckBoxes vector. + //std::iter_swap(_enabledCheckBoxes.begin() + rowIndex, _enabledCheckBoxes.begin() + rowIndex + (up ? -1 : 1)); + + //Move the rows in the table + auto widget = ui->workbenchTable->cellWidget(rowIndex, 0); + auto widget2 = ui->workbenchTable->cellWidget(rowIndex + (up ? -1 : 1), 0); + + auto newWidget = new QWidget(this); + newWidget->setObjectName(widget->objectName()); + newWidget->setLayout(widget->layout()); + + auto newWidget2 = new QWidget(this); + newWidget2->setObjectName(widget2->objectName()); + newWidget2->setLayout(widget2->layout()); + + ui->workbenchTable->removeCellWidget(rowIndex, 0); + ui->workbenchTable->removeCellWidget(rowIndex + (up ? -1 : 1), 0); + + ui->workbenchTable->setCellWidget(rowIndex + (up ? -1 : 1), 0, newWidget); + ui->workbenchTable->setCellWidget(rowIndex , 0, newWidget2); +} /** Build the list of unloaded workbenches. */ -void DlgSettingsLazyLoadedImp::buildUnloadedWorkbenchList() +void DlgSettingsLazyLoadedImp::buildWorkbenchList() { QStringList workbenches = Application::Instance->workbenches(); - workbenches.sort(); - QStringList enabled_wbs_list = getEnabledWorkbenches(); + QStringList enabledWbs = getEnabledWorkbenches(); + QStringList disabledWbs = getDisabledWorkbenches(); + ui->workbenchTable->setSelectionMode(QAbstractItemView::NoSelection); ui->workbenchTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); ui->workbenchTable->setRowCount(0); - _autoloadCheckBoxes.clear(); // setRowCount(0) just invalidated all of these pointers - _enabledCheckBoxes.clear();// setRowCount(0) just invalidated all of these pointers - ui->workbenchTable->setColumnCount(5); - ui->workbenchTable->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Enabled, QHeaderView::ResizeMode::ResizeToContents); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Icon, QHeaderView::ResizeMode::ResizeToContents); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Name, QHeaderView::ResizeMode::ResizeToContents); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(CheckBox, QHeaderView::ResizeMode::ResizeToContents); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(Load, QHeaderView::ResizeMode::ResizeToContents); + ui->workbenchTable->setColumnCount(columnCount); + ui->workbenchTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents); QStringList columnHeaders; - for (int i = 0; i < 5; i++) { - switch (i) { - case Enabled : columnHeaders << tr("Enable"); break; - case Icon : columnHeaders << QString(); break; - case Name : columnHeaders << tr("Workbench Name"); break; - case CheckBox: columnHeaders << tr("Autoload"); break; - case Load : columnHeaders << QString(); break; - } - } + columnHeaders << tr("Enable"); ui->workbenchTable->setHorizontalHeaderLabels(columnHeaders); - unsigned int rowNumber = 0; + + //First we add the enabled wbs in their saved order. + for (const auto& wbName : enabledWbs) { + if (workbenches.contains(wbName)) { + addWorkbench(wbName, true); + } + else { + qDebug() << "Ignoring unknown" << wbName << "workbench found in user preferences."; + } + } + //Second we add workbench in alphabetical order that are either Disabled, or !enabled && !disabled, ie newly added wb. for (const auto& wbName : workbenches) { - if (wbName.toStdString() == "NoneWorkbench") - continue; // Do not list the default empty Workbench - - ui->workbenchTable->insertRow(rowNumber); - auto wbTooltip = Application::Instance->workbenchToolTip(wbName); - auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); - - // Column 0: Enabled checkbox. - auto enCheckWidget = new QWidget(this); - auto enableCheckBox = new QCheckBox(this); - enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); - auto enCheckLayout = new QHBoxLayout(enCheckWidget); - enCheckLayout->addWidget(enableCheckBox); - enCheckLayout->setAlignment(Qt::AlignCenter); - enCheckLayout->setContentsMargins(0, 0, 0, 0); - enableCheckBox->setChecked(enabled_wbs_list.contains(wbName)); - _enabledCheckBoxes.insert(std::make_pair(wbName, enableCheckBox)); - ui->workbenchTable->setCellWidget(rowNumber, Enabled, enCheckWidget); - - // Column 1: Workbench Icon - auto wbIcon = Application::Instance->workbenchIcon(wbName); - auto iconLabel = new QLabel(); - iconLabel->setPixmap(wbIcon.scaled(QSize(20,20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); - iconLabel->setToolTip(wbTooltip); - iconLabel->setContentsMargins(5, 3, 3, 3); // Left, top, right, bottom - ui->workbenchTable->setCellWidget(rowNumber, Icon, iconLabel); - - // Column 2: Workbench Display Name - auto textLabel = new QLabel(wbDisplayName); - textLabel->setToolTip(wbTooltip); - ui->workbenchTable->setCellWidget(rowNumber, Name, textLabel); - - // Column 3: Autoloaded checkBox - // - // To get the checkBox centered, we have to jump through some hoops... - auto checkWidget = new QWidget(this); - auto autoloadCheckBox = new QCheckBox(this); - autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); - auto checkLayout = new QHBoxLayout(checkWidget); - checkLayout->addWidget(autoloadCheckBox); - checkLayout->setAlignment(Qt::AlignCenter); - checkLayout->setContentsMargins(0, 0, 0, 0); - - // Figure out whether to check and/or disable this checkBox: - if (wbName.toStdString() == _startupModule) { - autoloadCheckBox->setChecked(true); - autoloadCheckBox->setEnabled(false); - autoloadCheckBox->setToolTip(tr("This is the current startup module, and must be autoloaded. See Preferences/General/Autoload to change.")); + if (disabledWbs.contains(wbName)) { + addWorkbench(wbName, false); } - else if (std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), - wbName.toStdString()) != _backgroundAutoloadedModules.end()) { - autoloadCheckBox->setChecked(true); - _autoloadCheckBoxes.insert(std::make_pair(wbName, autoloadCheckBox)); + else if (!enabledWbs.contains(wbName)) { + qDebug() << "Adding unknown " << wbName << "workbench."; + addWorkbench(wbName, false); } - else { - _autoloadCheckBoxes.insert(std::make_pair(wbName, autoloadCheckBox)); - } - ui->workbenchTable->setCellWidget(rowNumber, CheckBox, checkWidget); - - // Column 4: Load button/loaded indicator - if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { - auto label = new QLabel(tr("Loaded")); - label->setAlignment(Qt::AlignCenter); - ui->workbenchTable->setCellWidget(rowNumber, Load, label); - } - else { - auto button = new QPushButton(tr("Load now")); - connect(button, &QPushButton::clicked, this, [this,wbName]() { onLoadClicked(wbName); }); - ui->workbenchTable->setCellWidget(rowNumber, Load, button); - } - - ++rowNumber; } } +void DlgSettingsLazyLoadedImp::addWorkbench(const QString& wbName, bool enabled) +{ + if (wbName.toStdString() == "NoneWorkbench") + return; // Do not list the default empty Workbench + + int rowNumber = ui->workbenchTable->rowCount(); + ui->workbenchTable->insertRow(rowNumber); + QWidget* widget = createWorkbenchWidget(wbName, enabled); + ui->workbenchTable->setCellWidget(rowNumber, 0, widget); +} + +QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, bool enabled) +{ + auto wbTooltip = Application::Instance->workbenchToolTip(wbName); + auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); + + // 1: Enable checkbox + auto enableCheckBox = new QCheckBox(this); + enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); + enableCheckBox->setChecked(enabled); + enableCheckBox->setObjectName(enableCheckboxStr); + if (wbName.toStdString() == _startupModule) { + enableCheckBox->setChecked(true); + enableCheckBox->setEnabled(false); + enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); + } + + // 2: Workbench Icon + auto wbIcon = Application::Instance->workbenchIcon(wbName); + auto iconLabel = new QLabel(wbDisplayName); + iconLabel->setPixmap(wbIcon.scaled(QSize(20, 20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); + iconLabel->setToolTip(wbTooltip); + iconLabel->setContentsMargins(5, 0, 0, 5); // Left, top, right, bottom + + // 3: Workbench Display Name + auto textLabel = new QLabel(wbDisplayName); + textLabel->setToolTip(wbTooltip); + + // 4: Autoloaded checkBox. + auto autoloadCheckBox = new QCheckBox(this); + autoloadCheckBox->setObjectName(autoloadCheckboxStr); + autoloadCheckBox->setText(tr("Auto-load")); + autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); + + if (wbName.toStdString() == _startupModule) { // Figure out whether to check and/or disable this checkBox: + autoloadCheckBox->setChecked(true); + autoloadCheckBox->setEnabled(false); + autoloadCheckBox->setToolTip(tr("This is the current startup module, and must be autoloaded. See Preferences/General/Autoload to change.")); + } + else if (std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), + wbName.toStdString()) != _backgroundAutoloadedModules.end()) { + autoloadCheckBox->setChecked(true); + } + + // 5: Load button/loaded indicator + auto loadLabel = new QLabel(tr("Loaded")); + loadLabel->setAlignment(Qt::AlignCenter); + loadLabel->setObjectName(loadLabelStr); + auto loadButton = new QPushButton(tr("Load")); + loadButton->setObjectName(loadButtonStr); + connect(loadButton, &QPushButton::clicked, this, [this, wbName]() { onLoadClicked(wbName); }); + if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { + loadButton->setVisible(false); + } + else { + loadLabel->setVisible(false); + } + + // 6: up down buttons + auto downButton = new QToolButton(this); + auto upButton = new QToolButton(this); + downButton->setToolTip(tr("Move %1 down").arg(wbDisplayName)); + upButton->setToolTip(tr("Move %1 up").arg(wbDisplayName)); + downButton->setIcon(Gui::BitmapFactory().iconFromTheme("button_down")); + upButton->setIcon(Gui::BitmapFactory().iconFromTheme("button_up")); + connect(upButton, &QToolButton::clicked, this, [this, wbName]() { onUpDownClicked(wbName, true); }); + connect(downButton, &QToolButton::clicked, this, [this, wbName]() { onUpDownClicked(wbName, false); }); + + + auto mainWidget = new QWidget(this); + mainWidget->setObjectName(wbName); + auto layout = new QHBoxLayout(mainWidget); + layout->addWidget(enableCheckBox); + layout->addWidget(iconLabel); + layout->addWidget(textLabel); + layout->addStretch(); + layout->addWidget(loadButton); + layout->addWidget(loadLabel); + layout->addWidget(autoloadCheckBox); + layout->addWidget(downButton); + layout->addWidget(upButton); + layout->setAlignment(Qt::AlignLeft); + layout->setContentsMargins(10, 0, 0, 0); + + return mainWidget; +} + + QStringList DlgSettingsLazyLoadedImp::getEnabledWorkbenches() { QString enabled_wbs; @@ -285,6 +358,23 @@ QStringList DlgSettingsLazyLoadedImp::getEnabledWorkbenches() return enabled_wbs_list; } +QStringList DlgSettingsLazyLoadedImp::getDisabledWorkbenches() +{ + QString disabled_wbs; + QStringList disabled_wbs_list; + ParameterGrp::handle hGrp; + + hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); + disabled_wbs = QString::fromStdString(hGrp->GetASCII("Disabled", "")); +#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) + disabled_wbs_list = disabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts); +#else + disabled_wbs_list = disabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts); +#endif + + return disabled_wbs_list; +} + /** * Sets the strings of the subwidgets using the current language. */ diff --git a/src/Gui/DlgSettingsLazyLoadedImp.h b/src/Gui/DlgSettingsLazyLoadedImp.h index 11d54757ee..e1f76c6a21 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.h +++ b/src/Gui/DlgSettingsLazyLoadedImp.h @@ -51,22 +51,30 @@ public: void loadSettings() override; static QStringList getEnabledWorkbenches(); + static QStringList getDisabledWorkbenches(); protected Q_SLOTS: void onLoadClicked(const QString& wbName); + void onUpDownClicked(const QString& wbName, bool up); protected: - void buildUnloadedWorkbenchList(); + void buildWorkbenchList(); void changeEvent(QEvent *e) override; private: + void addWorkbench(const QString& it, bool enabled); + QWidget* createWorkbenchWidget(const QString& it, bool enabled); + std::unique_ptr ui; static const uint WorkbenchNameRole; + static const int columnCount; + static const QString loadLabelStr; + static const QString loadButtonStr; + static const QString enableCheckboxStr; + static const QString autoloadCheckboxStr; std::vector _backgroundAutoloadedModules; std::string _startupModule; - std::map _autoloadCheckBoxes; - std::map _enabledCheckBoxes; }; } // namespace Dialog From 69f95fe4a45f147f5d803454957472f121a80b1e Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 24 Mar 2023 11:45:50 +0100 Subject: [PATCH 03/22] Preferences: Workbench : Enable drag and drop. Replaces the QTable by a QListWidget. --- src/Gui/CMakeLists.txt | 2 + src/Gui/DlgSettingsLazyLoaded.ui | 32 +++---- src/Gui/DlgSettingsLazyLoadedImp.cpp | 123 ++++++++++++--------------- src/Gui/DlgSettingsLazyLoadedImp.h | 6 +- src/Gui/QListWidgetDragBugFix.cpp | 58 +++++++++++++ src/Gui/QListWidgetDragBugFix.h | 42 +++++++++ 6 files changed, 171 insertions(+), 92 deletions(-) create mode 100644 src/Gui/QListWidgetDragBugFix.cpp create mode 100644 src/Gui/QListWidgetDragBugFix.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index d38d4c8644..f01bd764b8 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -528,6 +528,7 @@ SET(Dialog_Customize_CPP_SRCS DlgToolbarsImp.cpp DlgWorkbenchesImp.cpp QListWidgetCustom.cpp + QListWidgetDragBugFix.cpp ) SET(Dialog_Customize_HPP_SRCS DlgActionsImp.h @@ -539,6 +540,7 @@ SET(Dialog_Customize_HPP_SRCS DlgToolbarsImp.h DlgWorkbenchesImp.h QListWidgetCustom.h + QListWidgetDragBugFix.h ) SET(Dialog_Customize_SRCS ${Dialog_Customize_CPP_SRCS} diff --git a/src/Gui/DlgSettingsLazyLoaded.ui b/src/Gui/DlgSettingsLazyLoaded.ui index 3447f17d34..8c47ce85cb 100644 --- a/src/Gui/DlgSettingsLazyLoaded.ui +++ b/src/Gui/DlgSettingsLazyLoaded.ui @@ -29,34 +29,28 @@ - <html><head/><body><p>To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.</p><p>Enabling or disabling workbenches requires a restart of the application.</p><p>The following workbenches are available in your installation:</p></body></html> + <html><head/><body><p>To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.</p><p> +You can enable/disable and reorder workbenches (requires restart).</p><p> +Your installed workbenches(you can add more through the addon manager):</p></body></html> true - - - - false - - - false - - - false - - - - - - - + + - + + + + QListWidgetDragBugFix + QListWidget +
QListWidgetDragBugFix.h
+
+
diff --git a/src/Gui/DlgSettingsLazyLoadedImp.cpp b/src/Gui/DlgSettingsLazyLoadedImp.cpp index 2566bf5b46..9999e9c0ac 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.cpp +++ b/src/Gui/DlgSettingsLazyLoadedImp.cpp @@ -30,17 +30,14 @@ #include "DlgSettingsLazyLoadedImp.h" #include "ui_DlgSettingsLazyLoaded.h" #include "Application.h" -#include "BitmapFactory.h" #include "Workbench.h" #include "WorkbenchManager.h" using namespace Gui::Dialog; -const uint DlgSettingsLazyLoadedImp::WorkbenchNameRole = Qt::UserRole; - -const int DlgSettingsLazyLoadedImp::columnCount = 1; - +const QString DlgSettingsLazyLoadedImp::iconLabelStr = QString::fromLatin1("iconLabel"); +const QString DlgSettingsLazyLoadedImp::nameLabelStr = QString::fromLatin1("nameLabel"); const QString DlgSettingsLazyLoadedImp::loadLabelStr = QString::fromLatin1("loadLabel"); const QString DlgSettingsLazyLoadedImp::loadButtonStr = QString::fromLatin1("loadButton"); const QString DlgSettingsLazyLoadedImp::enableCheckboxStr = QString::fromLatin1("enableCheckbox"); @@ -70,8 +67,8 @@ void DlgSettingsLazyLoadedImp::saveSettings() { std::ostringstream enabledStr, disabledStr, autoloadStr; - for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { - QWidget* widget = ui->workbenchTable->cellWidget(i, 0); + for (int i = 0; i < ui->wbList->count(); i++) { + QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); if (!widget) continue; QCheckBox* enableBox = widget->findChild(enableCheckboxStr); @@ -102,8 +99,11 @@ void DlgSettingsLazyLoadedImp::saveSettings() if (enabledStr.str().empty()) //make sure that we have at least one enabled workbench. enabledStr << "NoneWorkbench"; - else + else { + if (!disabledStr.str().empty()) + disabledStr << ","; disabledStr << "NoneWorkbench"; //Note, NoneWorkbench is not in the table so it's not added before. + } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); hGrp->SetASCII("Enabled", enabledStr.str().c_str()); @@ -144,8 +144,8 @@ void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) Application::Instance->activateWorkbench(originalActiveWB->name().c_str()); // replace load button with loaded indicator - for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { - QWidget* widget = ui->workbenchTable->cellWidget(i, 0); + for (int i = 0; i < ui->wbList->count(); i++) { + QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); if (widget && widget->objectName() == wbName) { QWidget* loadLabel = widget->findChild(loadLabelStr); QWidget* loadButton = widget->findChild(loadButtonStr); @@ -156,42 +156,29 @@ void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) } } -void DlgSettingsLazyLoadedImp::onUpDownClicked(const QString& wbName, bool up) +void DlgSettingsLazyLoadedImp::onWbActivated(const QString &wbName, bool checked) { - int rowIndex = 0; - //find the index of the row that is moving. - for (int i = 0; i < ui->workbenchTable->rowCount(); i++) { - QWidget* widget = ui->workbenchTable->cellWidget(i, 0); - if(widget->objectName() == wbName) { + // activate/deactivate the widgets + for (int i = 0; i < ui->wbList->count(); i++) { + QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); + if (widget && widget->objectName() == wbName) { + QWidget* iconLabel = widget->findChild(iconLabelStr); + QWidget* nameLabel = widget->findChild(nameLabelStr); + QWidget* loadLabel = widget->findChild(loadLabelStr); + QWidget* loadButton = widget->findChild(loadButtonStr); + QCheckBox* autoloadCheckbox = widget->findChild(autoloadCheckboxStr); + if (!iconLabel || !nameLabel || !loadLabel || !loadButton || !autoloadCheckbox) + return; + iconLabel->setEnabled(checked); + nameLabel->setEnabled(checked); + loadLabel->setEnabled(checked); + loadButton->setEnabled(checked); + autoloadCheckbox->setEnabled(checked); + if (!checked) //disabling wb disable auto-load. + autoloadCheckbox->setChecked(false); break; } - rowIndex++; } - - //Check if it can move - if (((rowIndex == 0) && up) || ((rowIndex == ui->workbenchTable->rowCount() - 1) && !up)) - return; - - //Move in the _enabledCheckBoxes vector. - //std::iter_swap(_enabledCheckBoxes.begin() + rowIndex, _enabledCheckBoxes.begin() + rowIndex + (up ? -1 : 1)); - - //Move the rows in the table - auto widget = ui->workbenchTable->cellWidget(rowIndex, 0); - auto widget2 = ui->workbenchTable->cellWidget(rowIndex + (up ? -1 : 1), 0); - - auto newWidget = new QWidget(this); - newWidget->setObjectName(widget->objectName()); - newWidget->setLayout(widget->layout()); - - auto newWidget2 = new QWidget(this); - newWidget2->setObjectName(widget2->objectName()); - newWidget2->setLayout(widget2->layout()); - - ui->workbenchTable->removeCellWidget(rowIndex, 0); - ui->workbenchTable->removeCellWidget(rowIndex + (up ? -1 : 1), 0); - - ui->workbenchTable->setCellWidget(rowIndex + (up ? -1 : 1), 0, newWidget); - ui->workbenchTable->setCellWidget(rowIndex , 0, newWidget2); } /** @@ -203,15 +190,12 @@ void DlgSettingsLazyLoadedImp::buildWorkbenchList() QStringList enabledWbs = getEnabledWorkbenches(); QStringList disabledWbs = getDisabledWorkbenches(); - ui->workbenchTable->setSelectionMode(QAbstractItemView::NoSelection); - ui->workbenchTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); - ui->workbenchTable->setRowCount(0); - ui->workbenchTable->setColumnCount(columnCount); - ui->workbenchTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents); - QStringList columnHeaders; - columnHeaders << tr("Enable"); - ui->workbenchTable->setHorizontalHeaderLabels(columnHeaders); - + ui->wbList->setDragDropMode(QAbstractItemView::InternalMove); + ui->wbList->setSelectionMode(QAbstractItemView::SingleSelection); + ui->wbList->viewport()->setAcceptDrops(true); + ui->wbList->setDropIndicatorShown(true); + ui->wbList->setDragEnabled(true); + ui->wbList->setDefaultDropAction(Qt::MoveAction); //First we add the enabled wbs in their saved order. for (const auto& wbName : enabledWbs) { @@ -219,7 +203,7 @@ void DlgSettingsLazyLoadedImp::buildWorkbenchList() addWorkbench(wbName, true); } else { - qDebug() << "Ignoring unknown" << wbName << "workbench found in user preferences."; + Base::Console().Warning("Ignoring unknown %s workbench found in user preferences.", wbName.toStdString().c_str()); } } //Second we add workbench in alphabetical order that are either Disabled, or !enabled && !disabled, ie newly added wb. @@ -228,7 +212,7 @@ void DlgSettingsLazyLoadedImp::buildWorkbenchList() addWorkbench(wbName, false); } else if (!enabledWbs.contains(wbName)) { - qDebug() << "Adding unknown " << wbName << "workbench."; + Base::Console().Warning("Adding unknown %s workbench.", wbName.toStdString().c_str()); addWorkbench(wbName, false); } } @@ -239,10 +223,11 @@ void DlgSettingsLazyLoadedImp::addWorkbench(const QString& wbName, bool enabled) if (wbName.toStdString() == "NoneWorkbench") return; // Do not list the default empty Workbench - int rowNumber = ui->workbenchTable->rowCount(); - ui->workbenchTable->insertRow(rowNumber); QWidget* widget = createWorkbenchWidget(wbName, enabled); - ui->workbenchTable->setCellWidget(rowNumber, 0, widget); + auto wItem = new QListWidgetItem(); + wItem->setSizeHint(widget->sizeHint()); + ui->wbList->addItem(wItem); + ui->wbList->setItemWidget(wItem, widget); } QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, bool enabled) @@ -260,23 +245,32 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, enableCheckBox->setEnabled(false); enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); } + connect(enableCheckBox, &QCheckBox::toggled, this, [this, wbName](bool checked) { onWbActivated(wbName, checked); }); // 2: Workbench Icon auto wbIcon = Application::Instance->workbenchIcon(wbName); auto iconLabel = new QLabel(wbDisplayName); + iconLabel->setObjectName(iconLabelStr); iconLabel->setPixmap(wbIcon.scaled(QSize(20, 20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); iconLabel->setToolTip(wbTooltip); iconLabel->setContentsMargins(5, 0, 0, 5); // Left, top, right, bottom + iconLabel->setEnabled(enableCheckBox->isChecked()); // 3: Workbench Display Name auto textLabel = new QLabel(wbDisplayName); - textLabel->setToolTip(wbTooltip); + textLabel->setObjectName(nameLabelStr); + textLabel->setToolTip(wbTooltip); + QFont font = textLabel->font(); + font.setBold(true); + textLabel->setFont(font); + textLabel->setEnabled(enableCheckBox->isChecked()); // 4: Autoloaded checkBox. auto autoloadCheckBox = new QCheckBox(this); autoloadCheckBox->setObjectName(autoloadCheckboxStr); autoloadCheckBox->setText(tr("Auto-load")); autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); + autoloadCheckBox->setEnabled(enableCheckBox->isChecked()); if (wbName.toStdString() == _startupModule) { // Figure out whether to check and/or disable this checkBox: autoloadCheckBox->setChecked(true); @@ -292,8 +286,10 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, auto loadLabel = new QLabel(tr("Loaded")); loadLabel->setAlignment(Qt::AlignCenter); loadLabel->setObjectName(loadLabelStr); + loadLabel->setEnabled(enableCheckBox->isChecked()); auto loadButton = new QPushButton(tr("Load")); loadButton->setObjectName(loadButtonStr); + loadButton->setEnabled(enableCheckBox->isChecked()); connect(loadButton, &QPushButton::clicked, this, [this, wbName]() { onLoadClicked(wbName); }); if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { loadButton->setVisible(false); @@ -302,17 +298,6 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, loadLabel->setVisible(false); } - // 6: up down buttons - auto downButton = new QToolButton(this); - auto upButton = new QToolButton(this); - downButton->setToolTip(tr("Move %1 down").arg(wbDisplayName)); - upButton->setToolTip(tr("Move %1 up").arg(wbDisplayName)); - downButton->setIcon(Gui::BitmapFactory().iconFromTheme("button_down")); - upButton->setIcon(Gui::BitmapFactory().iconFromTheme("button_up")); - connect(upButton, &QToolButton::clicked, this, [this, wbName]() { onUpDownClicked(wbName, true); }); - connect(downButton, &QToolButton::clicked, this, [this, wbName]() { onUpDownClicked(wbName, false); }); - - auto mainWidget = new QWidget(this); mainWidget->setObjectName(wbName); auto layout = new QHBoxLayout(mainWidget); @@ -323,8 +308,6 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, layout->addWidget(loadButton); layout->addWidget(loadLabel); layout->addWidget(autoloadCheckBox); - layout->addWidget(downButton); - layout->addWidget(upButton); layout->setAlignment(Qt::AlignLeft); layout->setContentsMargins(10, 0, 0, 0); diff --git a/src/Gui/DlgSettingsLazyLoadedImp.h b/src/Gui/DlgSettingsLazyLoadedImp.h index e1f76c6a21..b2a6b93caa 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.h +++ b/src/Gui/DlgSettingsLazyLoadedImp.h @@ -55,7 +55,7 @@ public: protected Q_SLOTS: void onLoadClicked(const QString& wbName); - void onUpDownClicked(const QString& wbName, bool up); + void onWbActivated(const QString& wbName, bool checked); protected: void buildWorkbenchList(); @@ -66,8 +66,8 @@ private: QWidget* createWorkbenchWidget(const QString& it, bool enabled); std::unique_ptr ui; - static const uint WorkbenchNameRole; - static const int columnCount; + static const QString iconLabelStr; + static const QString nameLabelStr; static const QString loadLabelStr; static const QString loadButtonStr; static const QString enableCheckboxStr; diff --git a/src/Gui/QListWidgetDragBugFix.cpp b/src/Gui/QListWidgetDragBugFix.cpp new file mode 100644 index 0000000000..71f864f4e4 --- /dev/null +++ b/src/Gui/QListWidgetDragBugFix.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2023 Boyer Pierre-louis * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include "QListWidgetDragBugFix.h" + + +QListWidgetDragBugFix::QListWidgetDragBugFix(QWidget * parent) + : QListWidget(parent) +{ +} + +QListWidgetDragBugFix::~QListWidgetDragBugFix() +{ +} + +/* Qt has a recent bug (2023, https://bugreports.qt.io/browse/QTBUG-100128) +* where the items disappears in certain conditions when drag and dropping. +* Here we prevent the situation where this happens. +* 1 - If the item is dropped on the item below such that the item doesn't move (ie superior half of the below item) +* 2 - The item is the last one and user drop it on the empty space below. +* In both those cases the item widget was lost. + */ +void QListWidgetDragBugFix::dragMoveEvent(QDragMoveEvent *e) +{ + if ((row(itemAt(e->pos())) == currentRow() + 1) + || (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1)) { + e->ignore(); + } + else { + QListWidget::dragMoveEvent(e); + } +} + +#include "moc_QListWidgetDragBugFix.cpp" diff --git a/src/Gui/QListWidgetDragBugFix.h b/src/Gui/QListWidgetDragBugFix.h new file mode 100644 index 0000000000..6b19195566 --- /dev/null +++ b/src/Gui/QListWidgetDragBugFix.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (c) 2023 Boyer Pierre-louis * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef QLISTWIDGETDRAGBUGFIX_HPP +#define QLISTWIDGETDRAGBUGFIX_HPP + +#include +#include + + +class QListWidgetDragBugFix : public QListWidget +{ + Q_OBJECT + +public: + QListWidgetDragBugFix(QWidget *parent); + ~QListWidgetDragBugFix() override; + +protected: + void dragMoveEvent(QDragMoveEvent *e) override; +}; + +#endif From eb57a85fc14dcc8da92dd5509b3676e3843aab64 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 24 Mar 2023 11:59:20 +0100 Subject: [PATCH 04/22] Preferences: Workbench : Change the text of the page to be more informative. Move the sentence "To preserve resources, FreeCAD..." to the load button tooltips. --- src/Gui/DlgSettingsLazyLoaded.ui | 5 ++--- src/Gui/DlgSettingsLazyLoadedImp.cpp | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gui/DlgSettingsLazyLoaded.ui b/src/Gui/DlgSettingsLazyLoaded.ui index 8c47ce85cb..d59223cd9d 100644 --- a/src/Gui/DlgSettingsLazyLoaded.ui +++ b/src/Gui/DlgSettingsLazyLoaded.ui @@ -29,9 +29,8 @@ - <html><head/><body><p>To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.</p><p> -You can enable/disable and reorder workbenches (requires restart).</p><p> -Your installed workbenches(you can add more through the addon manager):</p></body></html> + <html><head/><body><p>You can enable, disable and reorder workbenches (requires restart). Additional workbenches can be installed through the addon manager.</p><p> +Your currently system has the following workbenches:</p></body></html> true diff --git a/src/Gui/DlgSettingsLazyLoadedImp.cpp b/src/Gui/DlgSettingsLazyLoadedImp.cpp index 9999e9c0ac..e9c18facb0 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.cpp +++ b/src/Gui/DlgSettingsLazyLoadedImp.cpp @@ -289,6 +289,7 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, loadLabel->setEnabled(enableCheckBox->isChecked()); auto loadButton = new QPushButton(tr("Load")); loadButton->setObjectName(loadButtonStr); + loadButton->setToolTip(tr("To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.")); loadButton->setEnabled(enableCheckBox->isChecked()); connect(loadButton, &QPushButton::clicked, this, [this, wbName]() { onLoadClicked(wbName); }); if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { From 801afd0eeb01088ddf0fbe17f442a214d18865b7 Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 24 Mar 2023 12:58:35 +0100 Subject: [PATCH 05/22] Preferences: Workbench : Replace the functions used to retrieve the list of enabled wb --- src/Gui/Action.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index d2bb7ba96d..c31194a3b3 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -48,7 +48,7 @@ #include "BitmapFactory.h" #include "Command.h" #include "DlgUndoRedo.h" -#include "DlgWorkbenchesImp.h" +#include "DlgSettingsLazyLoadedImp.h" #include "Document.h" #include "EditorView.h" #include "FileDialog.h" @@ -801,8 +801,8 @@ void WorkbenchGroup::setWorkbenchData(int index, const QString& wb) void WorkbenchGroup::refreshWorkbenchList() { QStringList items = Application::Instance->workbenches(); - QStringList enabled_wbs_list = DlgWorkbenchesImp::load_enabled_workbenches(); - QStringList disabled_wbs_list = DlgWorkbenchesImp::load_disabled_workbenches(); + QStringList enabled_wbs_list = DlgSettingsLazyLoadedImp::getEnabledWorkbenches(); + QStringList disabled_wbs_list = DlgSettingsLazyLoadedImp::getDisabledWorkbenches(); QStringList enable_wbs; // Go through the list of enabled workbenches and verify that they really exist because From 4e31cb14128b8f3d3172e25525ef44543733388e Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 24 Mar 2023 13:04:01 +0100 Subject: [PATCH 06/22] Preferences: Remove Customize Workbenches dialog. --- src/Gui/CMakeLists.txt | 4 - src/Gui/DlgWorkbenches.ui | 289 ---------------------------------- src/Gui/DlgWorkbenchesImp.cpp | 273 -------------------------------- src/Gui/DlgWorkbenchesImp.h | 79 ---------- src/Gui/resource.cpp | 2 - 5 files changed, 647 deletions(-) delete mode 100644 src/Gui/DlgWorkbenches.ui delete mode 100644 src/Gui/DlgWorkbenchesImp.cpp delete mode 100644 src/Gui/DlgWorkbenchesImp.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index f01bd764b8..13fd302545 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -331,7 +331,6 @@ SET(Gui_UIC_SRCS DlgSettingsPythonConsole.ui DlgCheckableMessageBox.ui DlgToolbars.ui - DlgWorkbenches.ui DlgTreeWidget.ui DlgLocationAngle.ui DlgLocationPos.ui @@ -526,7 +525,6 @@ SET(Dialog_Customize_CPP_SRCS DlgCustomizeSpNavSettings.cpp DlgKeyboardImp.cpp DlgToolbarsImp.cpp - DlgWorkbenchesImp.cpp QListWidgetCustom.cpp QListWidgetDragBugFix.cpp ) @@ -538,7 +536,6 @@ SET(Dialog_Customize_HPP_SRCS DlgCustomizeSpNavSettings.h DlgKeyboardImp.h DlgToolbarsImp.h - DlgWorkbenchesImp.h QListWidgetCustom.h QListWidgetDragBugFix.h ) @@ -551,7 +548,6 @@ SET(Dialog_Customize_SRCS DlgCustomizeSpNavSettings.ui DlgKeyboard.ui DlgToolbars.ui - DlgWorkbenches.ui ) SOURCE_GROUP("Dialog\\Customize" FILES ${Dialog_Customize_SRCS}) diff --git a/src/Gui/DlgWorkbenches.ui b/src/Gui/DlgWorkbenches.ui deleted file mode 100644 index 328f7d9fa3..0000000000 --- a/src/Gui/DlgWorkbenches.ui +++ /dev/null @@ -1,289 +0,0 @@ - - - Gui::Dialog::DlgWorkbenches - - - - 0 - 0 - 421 - 354 - - - - Workbenches - - - - 9 - - - 6 - - - - - 6 - - - 0 - - - - - Disabled workbenches - - - - - - - - - - - - 6 - - - 0 - - - - - Enabled workbenches - - - - - - - - - - - - true - - - - 30 - 30 - - - - Move right - - - <html><head/><body><p><span style=" font-weight:600;">Move the selected workbench to enabled workbenches.</span></p></body></html> - - - - - - - :/icons/button_right.svg:/icons/button_right.svg - - - - - - - true - - - - 30 - 30 - - - - Move up - - - <html><head/><body><p><span style=" font-weight:600;">Move the selected item up.</span></p><p>The item will be moved up.</p></body></html> - - - - - - - :/icons/button_up.svg:/icons/button_up.svg - - - - - - - true - - - - 30 - 30 - - - - Add all to enabled workbenches - - - <html><head/><body><p><span style=" font-weight:600;">Remove the selected workbench from enabled workbenches</span></p></body></html> - - - - - - - :/icons/button_add_all.svg:/icons/button_add_all.svg - - - true - - - false - - - - - - - true - - - - 30 - 30 - - - - Sort enabled workbenches - - - <p>Sort enabled workbenches</p> - - - - - - - :/icons/button_sort.svg:/icons/button_sort.svg - - - true - - - - - - - true - - - - 30 - 30 - - - - Move left - - - <html><head/><body><p><span style=" font-weight:600;">Remove the selected workbench from enabled workbenches</span></p></body></html> - - - - - - - :/icons/button_left.svg:/icons/button_left.svg - - - true - - - false - - - - - - - true - - - - 30 - 30 - - - - Move down - - - <html><head/><body><p><span style=" font-weight:600;">Move the selected item down.</span></p><p>The item will be moved down</p></body></html> - - - - - - - :/icons/button_down.svg:/icons/button_down.svg - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 33 - 57 - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 33 - 57 - - - - - - - - <html><head/><body><p><span style=" font-size:8pt; font-weight:600;">Note:</span><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> The changes become active the next time you start the application</span></p></body></html> - - - - - - - - QListWidgetCustom - QListWidget -
QListWidgetCustom.h
-
-
- - - - -
diff --git a/src/Gui/DlgWorkbenchesImp.cpp b/src/Gui/DlgWorkbenchesImp.cpp deleted file mode 100644 index 45da472f35..0000000000 --- a/src/Gui/DlgWorkbenchesImp.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2015 FreeCAD Developers * - * Author: Przemo Firszt * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -// Based on DlgToolbars.cpp - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -# include -#endif - -#include "DlgWorkbenchesImp.h" -#include "ui_DlgWorkbenches.h" -#include "Application.h" -#include "QListWidgetCustom.h" - - -using namespace Gui::Dialog; - -const QString DlgWorkbenchesImp::all_workbenches = QString::fromLatin1("ALL"); - -/* TRANSLATOR Gui::Dialog::DlgWorkbenchesImp */ - -DlgWorkbenchesImp::DlgWorkbenchesImp(QWidget* parent) - : CustomizeActionPage(parent) - , ui(new Ui_DlgWorkbenches) -{ - ui->setupUi(this); - set_lw_properties(ui->lw_enabled_workbenches); - set_lw_properties(ui->lw_disabled_workbenches); - ui->lw_disabled_workbenches->setProperty("OnlyAcceptFrom", - QStringList() << ui->lw_enabled_workbenches->objectName()); - ui->lw_disabled_workbenches->setSortingEnabled(true); - - ui->lw_enabled_workbenches->setProperty("OnlyAcceptFrom", - QStringList() << ui->lw_enabled_workbenches->objectName() - << ui->lw_disabled_workbenches->objectName()); - - QStringList enabled_wbs_list = load_enabled_workbenches(); - QStringList disabled_wbs_list = load_disabled_workbenches(); - QStringList workbenches = Application::Instance->workbenches(); - - for (QStringList::Iterator it = enabled_wbs_list.begin(); it != enabled_wbs_list.end(); ++it) { - if (workbenches.contains(*it)) { - add_workbench(ui->lw_enabled_workbenches, *it); - } else { - qDebug() << "Ignoring unknown" << *it << "workbench found in user preferences."; - } - } - for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { - if (disabled_wbs_list.contains(*it)){ - add_workbench(ui->lw_disabled_workbenches, *it); - } else if (!enabled_wbs_list.contains(*it)){ - qDebug() << "Adding unknown " << *it << "workbench."; - add_workbench(ui->lw_enabled_workbenches, *it); - } - } - ui->lw_enabled_workbenches->setCurrentRow(0); - ui->lw_disabled_workbenches->setCurrentRow(0); -} - -/** Destroys the object and frees any allocated resources */ -DlgWorkbenchesImp::~DlgWorkbenchesImp() -{ -} - -void DlgWorkbenchesImp::set_lw_properties(QListWidgetCustom *lw) -{ - lw->setDragDropMode(QAbstractItemView::DragDrop); - lw->setSelectionMode(QAbstractItemView::SingleSelection); - lw->viewport()->setAcceptDrops(true); - lw->setDropIndicatorShown(true); - lw->setDragEnabled(true); - lw->setDefaultDropAction(Qt::MoveAction); -} - -void DlgWorkbenchesImp::add_workbench(QListWidgetCustom *lw, const QString& it) -{ - QPixmap px = Application::Instance->workbenchIcon(it); - QString mt = Application::Instance->workbenchMenuText(it); - auto wi = (new QListWidgetItem(QIcon(px), mt)); - wi->setData(Qt::UserRole, QVariant(it)); - lw->addItem(wi); -} - -void DlgWorkbenchesImp::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::LanguageChange) { - ui->retranslateUi(this); - } - else { - QWidget::changeEvent(e); - } -} - -void DlgWorkbenchesImp::hideEvent(QHideEvent * event) -{ - Q_UNUSED(event); - save_workbenches(); -} - -void DlgWorkbenchesImp::onAddMacroAction(const QByteArray& macro) -{ - Q_UNUSED(macro); -} - -void DlgWorkbenchesImp::onRemoveMacroAction(const QByteArray& macro) -{ - Q_UNUSED(macro); -} - -void DlgWorkbenchesImp::onModifyMacroAction(const QByteArray& macro) -{ - Q_UNUSED(macro); -} - -void DlgWorkbenchesImp::move_workbench(QListWidgetCustom *lwc_dest, - QListWidgetItem *wi) -{ - QListWidgetItem* item = wi->clone(); - lwc_dest->addItem(item); - lwc_dest->setCurrentItem(item); - delete wi; -} - -void DlgWorkbenchesImp::on_add_to_enabled_workbenches_btn_clicked() -{ - QListWidgetItem* ci = ui->lw_disabled_workbenches->currentItem(); - if (ci) { - move_workbench(ui->lw_enabled_workbenches, ci); - } -} - -void DlgWorkbenchesImp::on_remove_from_enabled_workbenches_btn_clicked() -{ - QListWidgetItem* ci = ui->lw_enabled_workbenches->currentItem(); - if (ci) { - move_workbench(ui->lw_disabled_workbenches, ci); - } -} - -void DlgWorkbenchesImp::shift_workbench(bool up) -{ - int direction; - if (up){ - direction = -1; - } else { - direction = 1; - } - if (ui->lw_enabled_workbenches->currentItem()) { - int index = ui->lw_enabled_workbenches->currentRow(); - QListWidgetItem *item = ui->lw_enabled_workbenches->takeItem(index); - ui->lw_enabled_workbenches->insertItem(index + direction, item); - ui->lw_enabled_workbenches->setCurrentRow(index + direction); - } -} - -void DlgWorkbenchesImp::on_shift_workbench_up_btn_clicked() -{ - shift_workbench(true); -} - -void DlgWorkbenchesImp::on_shift_workbench_down_btn_clicked() -{ - shift_workbench(false); -} - -void DlgWorkbenchesImp::on_sort_enabled_workbenches_btn_clicked() -{ - ui->lw_enabled_workbenches->sortItems(); -} - -void DlgWorkbenchesImp::on_add_all_to_enabled_workbenches_btn_clicked() -{ - while (ui->lw_disabled_workbenches->count() > 0) { - QListWidgetItem* item = ui->lw_disabled_workbenches->item(0); - move_workbench(ui->lw_enabled_workbenches, item); - } -} - -QStringList DlgWorkbenchesImp::load_enabled_workbenches() -{ - QString enabled_wbs; - QStringList enabled_wbs_list; - ParameterGrp::handle hGrp; - - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); - enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", all_workbenches.toStdString().c_str()).c_str()); -#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) - enabled_wbs_list = enabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts); -#else - enabled_wbs_list = enabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts); -#endif - - if (enabled_wbs_list.at(0) == all_workbenches) { - enabled_wbs_list.removeFirst(); - QStringList workbenches = Application::Instance->workbenches(); - for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { - enabled_wbs_list.append(*it); - } - enabled_wbs_list.sort(); - } - return enabled_wbs_list; -} - -QStringList DlgWorkbenchesImp::load_disabled_workbenches() -{ - QString disabled_wbs; - QStringList disabled_wbs_list; - ParameterGrp::handle hGrp; - - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); - disabled_wbs = QString::fromStdString(hGrp->GetASCII("Disabled", "")); -#if QT_VERSION >= QT_VERSION_CHECK(5,15,0) - disabled_wbs_list = disabled_wbs.split(QLatin1String(","), Qt::SkipEmptyParts); -#else - disabled_wbs_list = disabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts); -#endif - - return disabled_wbs_list; -} - -void DlgWorkbenchesImp::save_workbenches() -{ - QString enabled_wbs; - QString disabled_wbs; - ParameterGrp::handle hGrp; - - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); - hGrp->Clear(); - - if (ui->lw_enabled_workbenches->count() == 0) { - enabled_wbs.append(QString::fromLatin1("NoneWorkbench")); - } else { - for (int i = 0; i < ui->lw_enabled_workbenches->count(); i++) { - QVariant item_data = ui->lw_enabled_workbenches->item(i)->data(Qt::UserRole); - QString name = item_data.toString(); - enabled_wbs.append(name + QString::fromLatin1(",")); - } - } - hGrp->SetASCII("Enabled", enabled_wbs.toLatin1()); - - for (int i = 0; i < ui->lw_disabled_workbenches->count(); i++) { - QVariant item_data = ui->lw_disabled_workbenches->item(i)->data(Qt::UserRole); - QString name = item_data.toString(); - disabled_wbs.append(name + QString::fromLatin1(",")); - } - hGrp->SetASCII("Disabled", disabled_wbs.toLatin1()); -} - -#include "moc_DlgWorkbenchesImp.cpp" - diff --git a/src/Gui/DlgWorkbenchesImp.h b/src/Gui/DlgWorkbenchesImp.h deleted file mode 100644 index dc3cf907e3..0000000000 --- a/src/Gui/DlgWorkbenchesImp.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2015 FreeCAD Developers * - * Author: Przemo Firszt * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -// Based on DlgToolbars.h file - - -#ifndef GUI_DIALOG_DLGWORKBENCHES_IMP_H -#define GUI_DIALOG_DLGWORKBENCHES_IMP_H - -#include "PropertyPage.h" -#include - -class QListWidgetCustom; -class QListWidgetItem; - -namespace Gui { -namespace Dialog { -class Ui_DlgWorkbenches; - -class DlgWorkbenchesImp : public CustomizeActionPage -{ - Q_OBJECT - -public: - explicit DlgWorkbenchesImp(QWidget* parent = nullptr); - ~DlgWorkbenchesImp() override; - static QStringList load_enabled_workbenches(); - static QStringList load_disabled_workbenches(); - static const QString all_workbenches; - -protected: - void changeEvent(QEvent *e) override; - void hideEvent(QHideEvent * event) override; - -protected Q_SLOTS: - void onAddMacroAction(const QByteArray&) override; - void onRemoveMacroAction(const QByteArray&) override; - void onModifyMacroAction(const QByteArray&) override; - void on_add_to_enabled_workbenches_btn_clicked(); - void on_remove_from_enabled_workbenches_btn_clicked(); - void on_shift_workbench_up_btn_clicked(); - void on_shift_workbench_down_btn_clicked(); - void on_sort_enabled_workbenches_btn_clicked(); - void on_add_all_to_enabled_workbenches_btn_clicked(); - -private: - void set_lw_properties(QListWidgetCustom *lw); - void add_workbench(QListWidgetCustom *lw, const QString& it); - void move_workbench(QListWidgetCustom *lwc_dest, - QListWidgetItem *wi); - void save_workbenches(); - void shift_workbench(bool up); - -private: - std::unique_ptr ui; -}; - -} // namespace Dialog -} // namespace Gui - -#endif // GUI_DIALOG_DLGWORKBENCHES_IMP_H diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index 8e84edf1e2..1572bbab5f 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -45,7 +45,6 @@ #include "DlgSettingsLazyLoadedImp.h" #include "DlgToolbarsImp.h" -#include "DlgWorkbenchesImp.h" #include "DlgActionsImp.h" #include "DlgCommandsImp.h" #include "DlgKeyboardImp.h" @@ -87,7 +86,6 @@ WidgetFactorySupplier::WidgetFactorySupplier() // new CustomPageProducer; new CustomPageProducer; - new CustomPageProducer; new CustomPageProducer; new CustomPageProducer; new CustomPageProducer; From 255270b21fe461e600a30f800b35fe27332081b4 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sat, 25 Mar 2023 07:50:45 +0100 Subject: [PATCH 07/22] Preference: Replace the name LazyLoaded by Workbenches. --- src/Gui/Action.cpp | 6 +-- src/Gui/CMakeLists.txt | 8 ++-- ...azyLoaded.ui => DlgSettingsWorkbenches.ui} | 4 +- ...dImp.cpp => DlgSettingsWorkbenchesImp.cpp} | 48 +++++++++---------- ...oadedImp.h => DlgSettingsWorkbenchesImp.h} | 18 +++---- src/Gui/resource.cpp | 4 +- 6 files changed, 44 insertions(+), 44 deletions(-) rename src/Gui/{DlgSettingsLazyLoaded.ui => DlgSettingsWorkbenches.ui} (92%) rename src/Gui/{DlgSettingsLazyLoadedImp.cpp => DlgSettingsWorkbenchesImp.cpp} (89%) rename src/Gui/{DlgSettingsLazyLoadedImp.h => DlgSettingsWorkbenchesImp.h} (85%) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index c31194a3b3..bd0e4113c3 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -48,7 +48,7 @@ #include "BitmapFactory.h" #include "Command.h" #include "DlgUndoRedo.h" -#include "DlgSettingsLazyLoadedImp.h" +#include "DlgSettingsWorkbenchesImp.h" #include "Document.h" #include "EditorView.h" #include "FileDialog.h" @@ -801,8 +801,8 @@ void WorkbenchGroup::setWorkbenchData(int index, const QString& wb) void WorkbenchGroup::refreshWorkbenchList() { QStringList items = Application::Instance->workbenches(); - QStringList enabled_wbs_list = DlgSettingsLazyLoadedImp::getEnabledWorkbenches(); - QStringList disabled_wbs_list = DlgSettingsLazyLoadedImp::getDisabledWorkbenches(); + QStringList enabled_wbs_list = DlgSettingsWorkbenchesImp::getEnabledWorkbenches(); + QStringList disabled_wbs_list = DlgSettingsWorkbenchesImp::getDisabledWorkbenches(); QStringList enable_wbs; // Go through the list of enabled workbenches and verify that they really exist because diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 13fd302545..6442c89e84 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -325,7 +325,7 @@ SET(Gui_UIC_SRCS DlgSettingsColorGradient.ui DlgSettingsDocument.ui DlgSettingsImage.ui - DlgSettingsLazyLoaded.ui + DlgSettingsWorkbenches.ui DlgSettingsMacro.ui DlgSettingsNotificationArea.ui DlgSettingsPythonConsole.ui @@ -567,7 +567,7 @@ SET(Dialog_Settings_CPP_SRCS DlgSettingsColorGradientImp.cpp DlgSettingsDocumentImp.cpp DlgSettingsImageImp.cpp - DlgSettingsLazyLoadedImp.cpp + DlgSettingsWorkbenchesImp.cpp DlgSettingsMacroImp.cpp DlgSettingsNotificationArea.cpp DlgSettingsPythonConsole.cpp @@ -587,7 +587,7 @@ SET(Dialog_Settings_HPP_SRCS DlgSettingsColorGradientImp.h DlgSettingsDocumentImp.h DlgSettingsImageImp.h - DlgSettingsLazyLoadedImp.h + DlgSettingsWorkbenchesImp.h DlgSettingsMacroImp.h DlgSettingsNotificationArea.h DlgSettingsPythonConsole.h @@ -609,7 +609,7 @@ SET(Dialog_Settings_SRCS DlgSettingsColorGradient.ui DlgSettingsDocument.ui DlgSettingsImage.ui - DlgSettingsLazyLoaded.ui + DlgSettingsWorkbenches.ui DlgSettingsMacro.ui DlgSettingsNotificationArea.ui DlgSettingsPythonConsole.ui diff --git a/src/Gui/DlgSettingsLazyLoaded.ui b/src/Gui/DlgSettingsWorkbenches.ui similarity index 92% rename from src/Gui/DlgSettingsLazyLoaded.ui rename to src/Gui/DlgSettingsWorkbenches.ui index d59223cd9d..79b3f3d2cd 100644 --- a/src/Gui/DlgSettingsLazyLoaded.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -1,7 +1,7 @@ - Gui::Dialog::DlgSettingsLazyLoaded - + Gui::Dialog::DlgSettingsWorkbenches + 0 diff --git a/src/Gui/DlgSettingsLazyLoadedImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp similarity index 89% rename from src/Gui/DlgSettingsLazyLoadedImp.cpp rename to src/Gui/DlgSettingsWorkbenchesImp.cpp index e9c18facb0..d75d386fa6 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -27,8 +27,8 @@ #include #endif -#include "DlgSettingsLazyLoadedImp.h" -#include "ui_DlgSettingsLazyLoaded.h" +#include "DlgSettingsWorkbenchesImp.h" +#include "ui_DlgSettingsWorkbenches.h" #include "Application.h" #include "Workbench.h" #include "WorkbenchManager.h" @@ -36,21 +36,21 @@ using namespace Gui::Dialog; -const QString DlgSettingsLazyLoadedImp::iconLabelStr = QString::fromLatin1("iconLabel"); -const QString DlgSettingsLazyLoadedImp::nameLabelStr = QString::fromLatin1("nameLabel"); -const QString DlgSettingsLazyLoadedImp::loadLabelStr = QString::fromLatin1("loadLabel"); -const QString DlgSettingsLazyLoadedImp::loadButtonStr = QString::fromLatin1("loadButton"); -const QString DlgSettingsLazyLoadedImp::enableCheckboxStr = QString::fromLatin1("enableCheckbox"); -const QString DlgSettingsLazyLoadedImp::autoloadCheckboxStr = QString::fromLatin1("autoloadCheckbox"); +const QString DlgSettingsWorkbenchesImp::iconLabelStr = QString::fromLatin1("iconLabel"); +const QString DlgSettingsWorkbenchesImp::nameLabelStr = QString::fromLatin1("nameLabel"); +const QString DlgSettingsWorkbenchesImp::loadLabelStr = QString::fromLatin1("loadLabel"); +const QString DlgSettingsWorkbenchesImp::loadButtonStr = QString::fromLatin1("loadButton"); +const QString DlgSettingsWorkbenchesImp::enableCheckboxStr = QString::fromLatin1("enableCheckbox"); +const QString DlgSettingsWorkbenchesImp::autoloadCheckboxStr = QString::fromLatin1("autoloadCheckbox"); -/* TRANSLATOR Gui::Dialog::DlgSettingsLazyLoadedImp */ +/* TRANSLATOR Gui::Dialog::DlgSettingsWorkbenchesImp */ /** - * Constructs a DlgSettingsLazyLoadedImp + * Constructs a DlgSettingsWorkbenchesImp */ -DlgSettingsLazyLoadedImp::DlgSettingsLazyLoadedImp( QWidget* parent ) +DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) : PreferencePage( parent ) - , ui(new Ui_DlgSettingsLazyLoaded) + , ui(new Ui_DlgSettingsWorkbenches) { ui->setupUi(this); } @@ -58,12 +58,12 @@ DlgSettingsLazyLoadedImp::DlgSettingsLazyLoadedImp( QWidget* parent ) /** * Destroys the object and frees any allocated resources */ -DlgSettingsLazyLoadedImp::~DlgSettingsLazyLoadedImp() +DlgSettingsWorkbenchesImp::~DlgSettingsWorkbenchesImp() { } -void DlgSettingsLazyLoadedImp::saveSettings() +void DlgSettingsWorkbenchesImp::saveSettings() { std::ostringstream enabledStr, disabledStr, autoloadStr; @@ -113,7 +113,7 @@ void DlgSettingsLazyLoadedImp::saveSettings() SetASCII("BackgroundAutoloadModules", autoloadStr.str().c_str()); } -void DlgSettingsLazyLoadedImp::loadSettings() +void DlgSettingsWorkbenchesImp::loadSettings() { // There are two different "autoload" settings: the first, in FreeCAD since 2004, // controls the module the user sees first when starting FreeCAD, and defaults to the Start workbench @@ -136,7 +136,7 @@ void DlgSettingsLazyLoadedImp::loadSettings() buildWorkbenchList(); } -void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) +void DlgSettingsWorkbenchesImp::onLoadClicked(const QString &wbName) { // activate selected workbench Workbench* originalActiveWB = WorkbenchManager::instance()->active(); @@ -156,7 +156,7 @@ void DlgSettingsLazyLoadedImp::onLoadClicked(const QString &wbName) } } -void DlgSettingsLazyLoadedImp::onWbActivated(const QString &wbName, bool checked) +void DlgSettingsWorkbenchesImp::onWbActivated(const QString &wbName, bool checked) { // activate/deactivate the widgets for (int i = 0; i < ui->wbList->count(); i++) { @@ -184,7 +184,7 @@ void DlgSettingsLazyLoadedImp::onWbActivated(const QString &wbName, bool checked /** Build the list of unloaded workbenches. */ -void DlgSettingsLazyLoadedImp::buildWorkbenchList() +void DlgSettingsWorkbenchesImp::buildWorkbenchList() { QStringList workbenches = Application::Instance->workbenches(); QStringList enabledWbs = getEnabledWorkbenches(); @@ -218,7 +218,7 @@ void DlgSettingsLazyLoadedImp::buildWorkbenchList() } } -void DlgSettingsLazyLoadedImp::addWorkbench(const QString& wbName, bool enabled) +void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled) { if (wbName.toStdString() == "NoneWorkbench") return; // Do not list the default empty Workbench @@ -230,7 +230,7 @@ void DlgSettingsLazyLoadedImp::addWorkbench(const QString& wbName, bool enabled) ui->wbList->setItemWidget(wItem, widget); } -QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, bool enabled) +QWidget* DlgSettingsWorkbenchesImp::createWorkbenchWidget(const QString& wbName, bool enabled) { auto wbTooltip = Application::Instance->workbenchToolTip(wbName); auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); @@ -316,7 +316,7 @@ QWidget* DlgSettingsLazyLoadedImp::createWorkbenchWidget(const QString& wbName, } -QStringList DlgSettingsLazyLoadedImp::getEnabledWorkbenches() +QStringList DlgSettingsWorkbenchesImp::getEnabledWorkbenches() { QString enabled_wbs; QStringList enabled_wbs_list; @@ -342,7 +342,7 @@ QStringList DlgSettingsLazyLoadedImp::getEnabledWorkbenches() return enabled_wbs_list; } -QStringList DlgSettingsLazyLoadedImp::getDisabledWorkbenches() +QStringList DlgSettingsWorkbenchesImp::getDisabledWorkbenches() { QString disabled_wbs; QStringList disabled_wbs_list; @@ -362,7 +362,7 @@ QStringList DlgSettingsLazyLoadedImp::getDisabledWorkbenches() /** * Sets the strings of the subwidgets using the current language. */ -void DlgSettingsLazyLoadedImp::changeEvent(QEvent *e) +void DlgSettingsWorkbenchesImp::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -372,4 +372,4 @@ void DlgSettingsLazyLoadedImp::changeEvent(QEvent *e) } } -#include "moc_DlgSettingsLazyLoadedImp.cpp" +#include "moc_DlgSettingsWorkbenchesImp.cpp" diff --git a/src/Gui/DlgSettingsLazyLoadedImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h similarity index 85% rename from src/Gui/DlgSettingsLazyLoadedImp.h rename to src/Gui/DlgSettingsWorkbenchesImp.h index b2a6b93caa..d228c57811 100644 --- a/src/Gui/DlgSettingsLazyLoadedImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -21,8 +21,8 @@ ***************************************************************************/ -#ifndef GUI_DIALOG_DLGSETTINGSLAZYLOADED_IMP_H -#define GUI_DIALOG_DLGSETTINGSLAZYLOADED_IMP_H +#ifndef GUI_DIALOG_DLGSETTINGSWORKBENCHES_IMP_H +#define GUI_DIALOG_DLGSETTINGSWORKBENCHES_IMP_H #include "PropertyPage.h" #include @@ -31,21 +31,21 @@ class QCheckBox; namespace Gui { namespace Dialog { -class Ui_DlgSettingsLazyLoaded; +class Ui_DlgSettingsWorkbenches; /** - * The DlgSettingsLazyLoadedImp class implements a pseudo-preference page explain why + * The DlgSettingsWorkbenchesImp class implements a pseudo-preference page explain why * the remaining preference pages aren't loaded yet, and to help the user do so on demand. * \author Jürgen Riegel */ -class DlgSettingsLazyLoadedImp : public PreferencePage +class DlgSettingsWorkbenchesImp : public PreferencePage { Q_OBJECT public: - explicit DlgSettingsLazyLoadedImp( QWidget* parent = nullptr ); - ~DlgSettingsLazyLoadedImp() override; + explicit DlgSettingsWorkbenchesImp( QWidget* parent = nullptr ); + ~DlgSettingsWorkbenchesImp() override; void saveSettings() override; void loadSettings() override; @@ -65,7 +65,7 @@ private: void addWorkbench(const QString& it, bool enabled); QWidget* createWorkbenchWidget(const QString& it, bool enabled); - std::unique_ptr ui; + std::unique_ptr ui; static const QString iconLabelStr; static const QString nameLabelStr; static const QString loadLabelStr; @@ -80,4 +80,4 @@ private: } // namespace Dialog } // namespace Gui -#endif // GUI_DIALOG_DLGSETTINGSLAZYLOADED_IMP_H +#endif // GUI_DIALOG_DLGSETTINGSWORKBENCHES_IMP_H diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index 1572bbab5f..b0ec59c799 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -42,7 +42,7 @@ #include "DlgSettingsUnitsImp.h" #include "DlgSettingsDocumentImp.h" #include "DlgReportViewImp.h" -#include "DlgSettingsLazyLoadedImp.h" +#include "DlgSettingsWorkbenchesImp.h" #include "DlgToolbarsImp.h" #include "DlgActionsImp.h" @@ -79,7 +79,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); - new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Workbenches") ); + new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Workbenches") ); // ADD YOUR CUSTOMIZE PAGES HERE // From 46a1fe435cbd369fba3fec125ca28fbc64a21e19 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sat, 25 Mar 2023 08:49:21 +0100 Subject: [PATCH 08/22] Preference: Move workbench selector position to the workbench preference page. --- src/Gui/DlgGeneral.ui | 37 --------------------------- src/Gui/DlgGeneralImp.cpp | 23 ----------------- src/Gui/DlgGeneralImp.h | 2 -- src/Gui/DlgSettingsWorkbenches.ui | 37 +++++++++++++++++++++++++++ src/Gui/DlgSettingsWorkbenchesImp.cpp | 22 ++++++++++++++++ src/Gui/DlgSettingsWorkbenchesImp.h | 3 +++ 6 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui index d2a43592ab..542ffd0e88 100644 --- a/src/Gui/DlgGeneral.ui +++ b/src/Gui/DlgGeneral.ui @@ -508,43 +508,6 @@ this according to your screen size or personal taste
- - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Workbench selector position : - - - - - - - Customize where the workbench selector appears (restart required). - -'Toolbar': In the toolbars, as a movable toolbar. -'Left Corner': In the menu bar, on the left corner. -'Right Corner': In the menu bar, on the right corner. - - - - - diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index fcfb8da8f7..e35375b69a 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -41,7 +41,6 @@ #include "DlgRevertToBackupConfigImp.h" #include "MainWindow.h" #include "PreferencePackManager.h" -#include "UserSettings.h" #include "Language/Translator.h" using namespace Gui::Dialog; @@ -223,8 +222,6 @@ void DlgGeneralImp::saveSettings() hGrp->GetGroup("TreeView")->SetBool("Enabled",treeView); hGrp->GetGroup("PropertyView")->SetBool("Enabled",propertyView); - saveWorkbenchSelector(); - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow"); hGrp->SetBool("TiledBackground", ui->tiledBackground->isChecked()); @@ -310,9 +307,6 @@ void DlgGeneralImp::loadSettings() } ui->treeMode->setCurrentIndex(index); - //workbench selector position combobox setup - loadWorkbenchSelector(); - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow"); ui->tiledBackground->setChecked(hGrp->GetBool("TiledBackground", false)); @@ -509,21 +503,4 @@ void DlgGeneralImp::onLoadPreferencePackClicked(const std::string& packName) } } -void DlgGeneralImp::saveWorkbenchSelector() -{ - //save workbench selector position - auto index = ui->WorkbenchSelectorPosition->currentIndex(); - WorkbenchSwitcher::setIndex(index); -} - -void DlgGeneralImp::loadWorkbenchSelector() -{ - //workbench selector position combobox setup - ui->WorkbenchSelectorPosition->clear(); - ui->WorkbenchSelectorPosition->addItem(tr("Toolbar")); - ui->WorkbenchSelectorPosition->addItem(tr("Left corner")); - ui->WorkbenchSelectorPosition->addItem(tr("Right corner")); - ui->WorkbenchSelectorPosition->setCurrentIndex(WorkbenchSwitcher::getIndex()); -} - #include "moc_DlgGeneralImp.cpp" diff --git a/src/Gui/DlgGeneralImp.h b/src/Gui/DlgGeneralImp.h index c92f9c0fc8..ae74bdae0c 100644 --- a/src/Gui/DlgGeneralImp.h +++ b/src/Gui/DlgGeneralImp.h @@ -69,8 +69,6 @@ private: bool setLanguage(); //Returns true if language has been changed void setNumberLocale(bool force = false); void setDecimalPointConversion(bool on); - void saveWorkbenchSelector(); - void loadWorkbenchSelector(); private: int localeIndex; diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index 79b3f3d2cd..50cc9cfbbf 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -40,6 +40,43 @@ Your currently system has the following workbenches:</p></body></ + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Workbench selector position : + + + + + + + Customize where the workbench selector appears (restart required). + +'Toolbar': In the toolbars, as a movable toolbar. +'Left Corner': In the menu bar, on the left corner. +'Right Corner': In the menu bar, on the right corner. + + + + + diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index d75d386fa6..f41f7620e6 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -30,6 +30,7 @@ #include "DlgSettingsWorkbenchesImp.h" #include "ui_DlgSettingsWorkbenches.h" #include "Application.h" +#include "UserSettings.h" #include "Workbench.h" #include "WorkbenchManager.h" @@ -111,10 +112,14 @@ void DlgSettingsWorkbenchesImp::saveSettings() App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> SetASCII("BackgroundAutoloadModules", autoloadStr.str().c_str()); + + saveWorkbenchSelector(); } void DlgSettingsWorkbenchesImp::loadSettings() { + loadWorkbenchSelector(); + // There are two different "autoload" settings: the first, in FreeCAD since 2004, // controls the module the user sees first when starting FreeCAD, and defaults to the Start workbench std::string start = App::Application::Config()["StartWorkbench"]; @@ -372,4 +377,21 @@ void DlgSettingsWorkbenchesImp::changeEvent(QEvent *e) } } +void DlgSettingsWorkbenchesImp::saveWorkbenchSelector() +{ + //save workbench selector position + auto index = ui->WorkbenchSelectorPosition->currentIndex(); + WorkbenchSwitcher::setIndex(index); +} + +void DlgSettingsWorkbenchesImp::loadWorkbenchSelector() +{ + //workbench selector position combobox setup + ui->WorkbenchSelectorPosition->clear(); + ui->WorkbenchSelectorPosition->addItem(tr("Toolbar")); + ui->WorkbenchSelectorPosition->addItem(tr("Left corner")); + ui->WorkbenchSelectorPosition->addItem(tr("Right corner")); + ui->WorkbenchSelectorPosition->setCurrentIndex(WorkbenchSwitcher::getIndex()); +} + #include "moc_DlgSettingsWorkbenchesImp.cpp" diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index d228c57811..3a5bd9a2c7 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -65,6 +65,9 @@ private: void addWorkbench(const QString& it, bool enabled); QWidget* createWorkbenchWidget(const QString& it, bool enabled); + void saveWorkbenchSelector(); + void loadWorkbenchSelector(); + std::unique_ptr ui; static const QString iconLabelStr; static const QString nameLabelStr; From d1e97444c9a674ff3f53ea252f32d0f0f615e627 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 26 Mar 2023 07:57:00 +0200 Subject: [PATCH 09/22] Preferences: Workbench: Move startup workbench to workbench page --- src/Gui/DlgGeneral.ui | 34 ----------- src/Gui/DlgGeneralImp.cpp | 43 -------------- src/Gui/DlgSettingsWorkbenches.ui | 34 +++++++++++ src/Gui/DlgSettingsWorkbenchesImp.cpp | 83 ++++++++++++++++++++++++++- src/Gui/DlgSettingsWorkbenchesImp.h | 3 + 5 files changed, 119 insertions(+), 78 deletions(-) diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui index 542ffd0e88..b54c5e08dd 100644 --- a/src/Gui/DlgGeneral.ui +++ b/src/Gui/DlgGeneral.ui @@ -533,40 +533,6 @@ this according to your screen size or personal taste 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - Auto load module after start up: - - - - - - - Choose which workbench will be activated and shown -after FreeCAD launches - - - - - - A Splash screen is a small loading window that is shown diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index e35375b69a..f63f00cc86 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -62,37 +62,6 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent ) { ui->setupUi(this); - // fills the combo box with all available workbenches - // sorted by their menu text - QStringList work = Application::Instance->workbenches(); - QMap menuText; - for (const auto & it : work) { - QString text = Application::Instance->workbenchMenuText(it); - menuText[text] = it; - } - - { // add special workbench to selection - QPixmap px = Application::Instance->workbenchIcon(QString::fromLatin1("NoneWorkbench")); - QString key = QString::fromLatin1(""); - QString value = QString::fromLatin1("$LastModule"); - if (px.isNull()) { - ui->AutoloadModuleCombo->addItem(key, QVariant(value)); - } - else { - ui->AutoloadModuleCombo->addItem(px, key, QVariant(value)); - } - } - - for (QMap::Iterator it = menuText.begin(); it != menuText.end(); ++it) { - QPixmap px = Application::Instance->workbenchIcon(it.value()); - if (px.isNull()) { - ui->AutoloadModuleCombo->addItem(it.key(), QVariant(it.value())); - } - else { - ui->AutoloadModuleCombo->addItem(px, it.key(), QVariant(it.value())); - } - } - recreatePreferencePackMenu(); connect(ui->ImportConfig, &QPushButton::clicked, this, &DlgGeneralImp::onImportConfigClicked); @@ -177,12 +146,6 @@ void DlgGeneralImp::setDecimalPointConversion(bool on) void DlgGeneralImp::saveSettings() { - int index = ui->AutoloadModuleCombo->currentIndex(); - QVariant data = ui->AutoloadModuleCombo->itemData(index); - QString startWbName = data.toString(); - App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> - SetASCII("AutoloadModule", startWbName.toLatin1()); - ui->SubstituteDecimal->onSave(); ui->UseLocaleFormatting->onSave(); ui->RecentFiles->onSave(); @@ -232,12 +195,6 @@ void DlgGeneralImp::saveSettings() void DlgGeneralImp::loadSettings() { - std::string start = App::Application::Config()["StartWorkbench"]; - start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> - GetASCII("AutoloadModule", start.c_str()); - QString startWbName = QLatin1String(start.c_str()); - ui->AutoloadModuleCombo->setCurrentIndex(ui->AutoloadModuleCombo->findData(startWbName)); - ui->SubstituteDecimal->onRestore(); ui->UseLocaleFormatting->onRestore(); ui->RecentFiles->onRestore(); diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index 50cc9cfbbf..47d48642c8 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -41,6 +41,40 @@ Your currently system has the following workbenches:</p></body></ + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Start up workbench: + + + + + + + Choose which workbench will be activated and shown +after FreeCAD launches + + + + + + 6 diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index f41f7620e6..5ece29f084 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -54,6 +54,7 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) , ui(new Ui_DlgSettingsWorkbenches) { ui->setupUi(this); + connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChangedClicked(index); }); } /** @@ -114,6 +115,12 @@ void DlgSettingsWorkbenchesImp::saveSettings() SetASCII("BackgroundAutoloadModules", autoloadStr.str().c_str()); saveWorkbenchSelector(); + + int index = ui->AutoloadModuleCombo->currentIndex(); + QVariant data = ui->AutoloadModuleCombo->itemData(index); + QString startWbName = data.toString(); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("AutoloadModule", startWbName.toLatin1()); } void DlgSettingsWorkbenchesImp::loadSettings() @@ -137,8 +144,10 @@ void DlgSettingsWorkbenchesImp::loadSettings() while (std::getline(stream, workbench, ',')) _backgroundAutoloadedModules.push_back(workbench); - buildWorkbenchList(); + + //We set the startup setting after building the list so that we can put only the enabled wb. + setStartWorkbenchComboItems(); } void DlgSettingsWorkbenchesImp::onLoadClicked(const QString &wbName) @@ -184,6 +193,9 @@ void DlgSettingsWorkbenchesImp::onWbActivated(const QString &wbName, bool checke break; } } + + // Reset the start combo items. + setStartWorkbenchComboItems(); } /** @@ -394,4 +406,73 @@ void DlgSettingsWorkbenchesImp::loadWorkbenchSelector() ui->WorkbenchSelectorPosition->setCurrentIndex(WorkbenchSwitcher::getIndex()); } +void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() +{ + ui->AutoloadModuleCombo->clear(); + + // fills the combo box with activated workbenches. + QStringList enabledWbs; + for (int i = 0; i < ui->wbList->count(); i++) { + QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); + if (widget) { + QCheckBox* enableCheckbox = widget->findChild(enableCheckboxStr); + if (enableCheckbox && enableCheckbox->isChecked()) { + enabledWbs << widget->objectName(); + } + } + } + + QMap menuText; + for (const auto& it : enabledWbs) { + QString text = Application::Instance->workbenchMenuText(it); + menuText[text] = it; + } + + { // add special workbench to selection + QPixmap px = Application::Instance->workbenchIcon(QString::fromLatin1("NoneWorkbench")); + QString key = QString::fromLatin1(""); + QString value = QString::fromLatin1("$LastModule"); + if (px.isNull()) { + ui->AutoloadModuleCombo->addItem(key, QVariant(value)); + } + else { + ui->AutoloadModuleCombo->addItem(px, key, QVariant(value)); + } + } + + for (QMap::Iterator it = menuText.begin(); it != menuText.end(); ++it) { + QPixmap px = Application::Instance->workbenchIcon(it.value()); + if (px.isNull()) { + ui->AutoloadModuleCombo->addItem(it.key(), QVariant(it.value())); + } + else { + ui->AutoloadModuleCombo->addItem(px, it.key(), QVariant(it.value())); + } + } + + ui->AutoloadModuleCombo->setCurrentIndex(ui->AutoloadModuleCombo->findData(QString::fromStdString(_startupModule))); +} + +void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) +{ + //Update _startupModule + QVariant data = ui->AutoloadModuleCombo->itemData(index); + QString wbName = data.toString(); + _startupModule = wbName.toStdString(); + + //Change wb that user can't deactivate. + for (int i = 0; i < ui->wbList->count(); i++) { + QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); + if (widget) { + QCheckBox* enableCheckbox = widget->findChild(enableCheckboxStr); + if (enableCheckbox && widget->objectName() == wbName) { + enableCheckbox->setEnabled(false); + } + else { + enableCheckbox->setEnabled(true); + } + } + } +} + #include "moc_DlgSettingsWorkbenchesImp.cpp" diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 3a5bd9a2c7..78bc20baa6 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -68,6 +68,9 @@ private: void saveWorkbenchSelector(); void loadWorkbenchSelector(); + void setStartWorkbenchComboItems(); + void onStartWbChangedClicked(int index); + std::unique_ptr ui; static const QString iconLabelStr; static const QString nameLabelStr; From 55d93ce3fbde241f0d923fce49c5279310c8f861 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 26 Mar 2023 09:45:20 +0200 Subject: [PATCH 10/22] Preferences: Workbench: Move the buttons closer to the label. --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 5ece29f084..f8a1cafb7a 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -281,6 +281,8 @@ QWidget* DlgSettingsWorkbenchesImp::createWorkbenchWidget(const QString& wbName, font.setBold(true); textLabel->setFont(font); textLabel->setEnabled(enableCheckBox->isChecked()); + textLabel->setMinimumSize(200,0); + // 4: Autoloaded checkBox. auto autoloadCheckBox = new QCheckBox(this); @@ -322,7 +324,6 @@ QWidget* DlgSettingsWorkbenchesImp::createWorkbenchWidget(const QString& wbName, layout->addWidget(enableCheckBox); layout->addWidget(iconLabel); layout->addWidget(textLabel); - layout->addStretch(); layout->addWidget(loadButton); layout->addWidget(loadLabel); layout->addWidget(autoloadCheckBox); From a0f1b46f4e2a05e358bbb15e846adaa15f0b0618 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 26 Mar 2023 14:16:55 +0200 Subject: [PATCH 11/22] Preferences: Workbench: Change the QListWidgetDragBug name to ListWidgetDragBug. Move the wbList setXxx() to ctor. Fix the 'Currently, your...' --- src/Gui/CMakeLists.txt | 4 +- src/Gui/DlgSettingsWorkbenches.ui | 8 +-- src/Gui/DlgSettingsWorkbenchesImp.cpp | 15 ++--- ...tDragBugFix.h => ListWidgetDragBugFix.cpp} | 46 ++++++++------ ...tDragBugFix.cpp => ListWidgetDragBugFix.h} | 61 ++++++++----------- 5 files changed, 67 insertions(+), 67 deletions(-) rename src/Gui/{QListWidgetDragBugFix.h => ListWidgetDragBugFix.cpp} (74%) rename src/Gui/{QListWidgetDragBugFix.cpp => ListWidgetDragBugFix.h} (61%) diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 6442c89e84..76117d2ea5 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -526,7 +526,7 @@ SET(Dialog_Customize_CPP_SRCS DlgKeyboardImp.cpp DlgToolbarsImp.cpp QListWidgetCustom.cpp - QListWidgetDragBugFix.cpp + ListWidgetDragBugFix.cpp ) SET(Dialog_Customize_HPP_SRCS DlgActionsImp.h @@ -537,7 +537,7 @@ SET(Dialog_Customize_HPP_SRCS DlgKeyboardImp.h DlgToolbarsImp.h QListWidgetCustom.h - QListWidgetDragBugFix.h + ListWidgetDragBugFix.h ) SET(Dialog_Customize_SRCS ${Dialog_Customize_CPP_SRCS} diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index 47d48642c8..a92c528dda 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -30,7 +30,7 @@ <html><head/><body><p>You can enable, disable and reorder workbenches (requires restart). Additional workbenches can be installed through the addon manager.</p><p> -Your currently system has the following workbenches:</p></body></html> +Currently, your system has the following workbenches:</p></body></html> true @@ -38,7 +38,7 @@ Your currently system has the following workbenches:</p></body></ - + @@ -116,9 +116,9 @@ after FreeCAD launches - QListWidgetDragBugFix + ListWidgetDragBugFix QListWidget -
QListWidgetDragBugFix.h
+
ListWidgetDragBugFix.h
diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index f8a1cafb7a..8014bebd26 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -54,6 +54,14 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) , ui(new Ui_DlgSettingsWorkbenches) { ui->setupUi(this); + + ui->wbList->setDragDropMode(QAbstractItemView::InternalMove); + ui->wbList->setSelectionMode(QAbstractItemView::SingleSelection); + ui->wbList->viewport()->setAcceptDrops(true); + ui->wbList->setDropIndicatorShown(true); + ui->wbList->setDragEnabled(true); + ui->wbList->setDefaultDropAction(Qt::MoveAction); + connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChangedClicked(index); }); } @@ -207,13 +215,6 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList() QStringList enabledWbs = getEnabledWorkbenches(); QStringList disabledWbs = getDisabledWorkbenches(); - ui->wbList->setDragDropMode(QAbstractItemView::InternalMove); - ui->wbList->setSelectionMode(QAbstractItemView::SingleSelection); - ui->wbList->viewport()->setAcceptDrops(true); - ui->wbList->setDropIndicatorShown(true); - ui->wbList->setDragEnabled(true); - ui->wbList->setDefaultDropAction(Qt::MoveAction); - //First we add the enabled wbs in their saved order. for (const auto& wbName : enabledWbs) { if (workbenches.contains(wbName)) { diff --git a/src/Gui/QListWidgetDragBugFix.h b/src/Gui/ListWidgetDragBugFix.cpp similarity index 74% rename from src/Gui/QListWidgetDragBugFix.h rename to src/Gui/ListWidgetDragBugFix.cpp index 6b19195566..23f5a11574 100644 --- a/src/Gui/QListWidgetDragBugFix.h +++ b/src/Gui/ListWidgetDragBugFix.cpp @@ -20,23 +20,31 @@ * * ***************************************************************************/ -#ifndef QLISTWIDGETDRAGBUGFIX_HPP -#define QLISTWIDGETDRAGBUGFIX_HPP - -#include -#include - - -class QListWidgetDragBugFix : public QListWidget -{ - Q_OBJECT - -public: - QListWidgetDragBugFix(QWidget *parent); - ~QListWidgetDragBugFix() override; - -protected: - void dragMoveEvent(QDragMoveEvent *e) override; -}; - +#include "PreCompiled.h" +#ifndef _PreComp_ +# include #endif + +#include "ListWidgetDragBugFix.h" + + +ListWidgetDragBugFix::ListWidgetDragBugFix(QWidget * parent) + : QListWidget(parent) +{ +} + +ListWidgetDragBugFix::~ListWidgetDragBugFix() +{ +} + +void ListWidgetDragBugFix::dragMoveEvent(QDragMoveEvent *e) +{ + if ((row(itemAt(e->pos())) == currentRow() + 1) + || (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1)) { + e->ignore(); + return; + } + QListWidget::dragMoveEvent(e); +} + +#include "moc_ListWidgetDragBugFix.cpp" diff --git a/src/Gui/QListWidgetDragBugFix.cpp b/src/Gui/ListWidgetDragBugFix.h similarity index 61% rename from src/Gui/QListWidgetDragBugFix.cpp rename to src/Gui/ListWidgetDragBugFix.h index 71f864f4e4..2af0b6fb52 100644 --- a/src/Gui/QListWidgetDragBugFix.cpp +++ b/src/Gui/ListWidgetDragBugFix.h @@ -20,39 +20,30 @@ * * ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ -# include +#ifndef QLISTWIDGETDRAGBUGFIX_HPP +#define QLISTWIDGETDRAGBUGFIX_HPP + +#include +#include + + /* Qt has a recent bug (2023, https://bugreports.qt.io/browse/QTBUG-100128) + * where the items disappears in certain conditions when drag and dropping. + * Here we prevent the situation where this happens. + * 1 - If the item is dropped on the item below such that the item doesn't move (ie superior half of the below item) + * 2 - The item is the last one and user drop it on the empty space below. + * In both those cases the item widget was lost. + * When Qt solve this bug, this class should not be required anymore. + */ +class ListWidgetDragBugFix : public QListWidget +{ + Q_OBJECT + +public: + explicit ListWidgetDragBugFix(QWidget *parent); + ~ListWidgetDragBugFix() override; + +protected: + void dragMoveEvent(QDragMoveEvent *e) override; +}; + #endif - -#include "QListWidgetDragBugFix.h" - - -QListWidgetDragBugFix::QListWidgetDragBugFix(QWidget * parent) - : QListWidget(parent) -{ -} - -QListWidgetDragBugFix::~QListWidgetDragBugFix() -{ -} - -/* Qt has a recent bug (2023, https://bugreports.qt.io/browse/QTBUG-100128) -* where the items disappears in certain conditions when drag and dropping. -* Here we prevent the situation where this happens. -* 1 - If the item is dropped on the item below such that the item doesn't move (ie superior half of the below item) -* 2 - The item is the last one and user drop it on the empty space below. -* In both those cases the item widget was lost. - */ -void QListWidgetDragBugFix::dragMoveEvent(QDragMoveEvent *e) -{ - if ((row(itemAt(e->pos())) == currentRow() + 1) - || (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1)) { - e->ignore(); - } - else { - QListWidget::dragMoveEvent(e); - } -} - -#include "moc_QListWidgetDragBugFix.cpp" From 398d84391de46db0f8664288187ad72af298a2e9 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 26 Mar 2023 15:33:01 +0200 Subject: [PATCH 12/22] Preferences: workbench: make a wbListItem qwidget sub class --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 292 +++++++++++--------------- src/Gui/DlgSettingsWorkbenchesImp.h | 40 ++-- 2 files changed, 151 insertions(+), 181 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 8014bebd26..d8def7ed38 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -37,12 +37,115 @@ using namespace Gui::Dialog; -const QString DlgSettingsWorkbenchesImp::iconLabelStr = QString::fromLatin1("iconLabel"); -const QString DlgSettingsWorkbenchesImp::nameLabelStr = QString::fromLatin1("nameLabel"); -const QString DlgSettingsWorkbenchesImp::loadLabelStr = QString::fromLatin1("loadLabel"); -const QString DlgSettingsWorkbenchesImp::loadButtonStr = QString::fromLatin1("loadButton"); -const QString DlgSettingsWorkbenchesImp::enableCheckboxStr = QString::fromLatin1("enableCheckbox"); -const QString DlgSettingsWorkbenchesImp::autoloadCheckboxStr = QString::fromLatin1("autoloadCheckbox"); +wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dialog, QWidget* parent) : QWidget(parent) + , dlg(dialog) +{ + this->setObjectName(wbName); + + auto wbTooltip = Application::Instance->workbenchToolTip(wbName); + auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); + + // 1: Enable checkbox + enableCheckBox = new QCheckBox(this); + enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); + enableCheckBox->setChecked(enabled); + if (wbName.toStdString() == dlg->_startupModule) { + enableCheckBox->setChecked(true); + enableCheckBox->setEnabled(false); + enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); + } + connect(enableCheckBox, &QCheckBox::toggled, this, [this](bool checked) { onWbActivated(checked); }); + + // 2: Workbench Icon + auto wbIcon = Application::Instance->workbenchIcon(wbName); + iconLabel = new QLabel(wbDisplayName); + iconLabel->setPixmap(wbIcon.scaled(QSize(20, 20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); + iconLabel->setToolTip(wbTooltip); + iconLabel->setContentsMargins(5, 0, 0, 5); // Left, top, right, bottom + iconLabel->setEnabled(enableCheckBox->isChecked()); + + // 3: Workbench Display Name + textLabel = new QLabel(wbDisplayName); + textLabel->setToolTip(wbTooltip); + QFont font = textLabel->font(); + font.setBold(true); + textLabel->setFont(font); + textLabel->setEnabled(enableCheckBox->isChecked()); + textLabel->setMinimumSize(200, 0); + + + // 4: Autoloaded checkBox. + autoloadCheckBox = new QCheckBox(this); + autoloadCheckBox->setText(tr("Auto-load")); + autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); + autoloadCheckBox->setEnabled(enableCheckBox->isChecked()); + + if (wbName.toStdString() == dlg->_startupModule) { // Figure out whether to check and/or disable this checkBox: + autoloadCheckBox->setChecked(true); + autoloadCheckBox->setEnabled(false); + autoloadCheckBox->setToolTip(tr("This is the current startup module, and must be autoloaded. See Preferences/General/Autoload to change.")); + } + else if (std::find(dlg->_backgroundAutoloadedModules.begin(), dlg->_backgroundAutoloadedModules.end(), + wbName.toStdString()) != dlg->_backgroundAutoloadedModules.end()) { + autoloadCheckBox->setChecked(true); + } + + // 5: Load button/loaded indicator + loadLabel = new QLabel(tr("Loaded")); + loadLabel->setAlignment(Qt::AlignCenter); + loadLabel->setEnabled(enableCheckBox->isChecked()); + loadButton = new QPushButton(tr("Load")); + loadButton->setToolTip(tr("To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.")); + loadButton->setEnabled(enableCheckBox->isChecked()); + connect(loadButton, &QPushButton::clicked, this, [this]() { onLoadClicked(); }); + if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { + loadButton->setVisible(false); + } + else { + loadLabel->setVisible(false); + } + + auto layout = new QHBoxLayout(this); + layout->addWidget(enableCheckBox); + layout->addWidget(iconLabel); + layout->addWidget(textLabel); + layout->addWidget(loadButton); + layout->addWidget(loadLabel); + layout->addWidget(autoloadCheckBox); + layout->setAlignment(Qt::AlignLeft); + layout->setContentsMargins(10, 0, 0, 0); +} + +wbListItem::~wbListItem() +{ +} + +void wbListItem::onLoadClicked() +{ + // activate selected workbench + Workbench* originalActiveWB = WorkbenchManager::instance()->active(); + Application::Instance->activateWorkbench(objectName().toStdString().c_str()); + Application::Instance->activateWorkbench(originalActiveWB->name().c_str()); + + // replace load button with loaded indicator + loadButton->setVisible(false); + loadLabel->setVisible(true); +} + +void wbListItem::onWbActivated(bool checked) +{ + // activate/deactivate the widgets + iconLabel->setEnabled(checked); + textLabel->setEnabled(checked); + loadLabel->setEnabled(checked); + loadButton->setEnabled(checked); + autoloadCheckBox->setEnabled(checked); + if (!checked) //disabling wb disable auto-load. + autoloadCheckBox->setChecked(false); + + // Reset the start combo items. + dlg->setStartWorkbenchComboItems(); +} /* TRANSLATOR Gui::Dialog::DlgSettingsWorkbenchesImp */ @@ -78,32 +181,25 @@ void DlgSettingsWorkbenchesImp::saveSettings() std::ostringstream enabledStr, disabledStr, autoloadStr; for (int i = 0; i < ui->wbList->count(); i++) { - QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); - if (!widget) - continue; - QCheckBox* enableBox = widget->findChild(enableCheckboxStr); - if (!enableBox) + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (!wbItem) continue; - if (enableBox->isChecked()) { + if (wbItem->enableCheckBox->isChecked()) { if (!enabledStr.str().empty()) enabledStr << ","; - enabledStr << widget->objectName().toStdString(); + enabledStr << wbItem->objectName().toStdString(); } else { if (!disabledStr.str().empty()) disabledStr << ","; - disabledStr << widget->objectName().toStdString(); + disabledStr << wbItem->objectName().toStdString(); } - QCheckBox* autoloadBox = widget->findChild(autoloadCheckboxStr); - if (!autoloadBox) - continue; - - if (autoloadBox->isChecked()) { + if (wbItem->autoloadCheckBox->isChecked()) { if (!autoloadStr.str().empty()) autoloadStr << ","; - autoloadStr << widget->objectName().toStdString(); + autoloadStr << wbItem->objectName().toStdString(); } } @@ -158,54 +254,6 @@ void DlgSettingsWorkbenchesImp::loadSettings() setStartWorkbenchComboItems(); } -void DlgSettingsWorkbenchesImp::onLoadClicked(const QString &wbName) -{ - // activate selected workbench - Workbench* originalActiveWB = WorkbenchManager::instance()->active(); - Application::Instance->activateWorkbench(wbName.toStdString().c_str()); - Application::Instance->activateWorkbench(originalActiveWB->name().c_str()); - - // replace load button with loaded indicator - for (int i = 0; i < ui->wbList->count(); i++) { - QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); - if (widget && widget->objectName() == wbName) { - QWidget* loadLabel = widget->findChild(loadLabelStr); - QWidget* loadButton = widget->findChild(loadButtonStr); - loadButton->setVisible(false); - loadLabel->setVisible(true); - break; - } - } -} - -void DlgSettingsWorkbenchesImp::onWbActivated(const QString &wbName, bool checked) -{ - // activate/deactivate the widgets - for (int i = 0; i < ui->wbList->count(); i++) { - QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); - if (widget && widget->objectName() == wbName) { - QWidget* iconLabel = widget->findChild(iconLabelStr); - QWidget* nameLabel = widget->findChild(nameLabelStr); - QWidget* loadLabel = widget->findChild(loadLabelStr); - QWidget* loadButton = widget->findChild(loadButtonStr); - QCheckBox* autoloadCheckbox = widget->findChild(autoloadCheckboxStr); - if (!iconLabel || !nameLabel || !loadLabel || !loadButton || !autoloadCheckbox) - return; - iconLabel->setEnabled(checked); - nameLabel->setEnabled(checked); - loadLabel->setEnabled(checked); - loadButton->setEnabled(checked); - autoloadCheckbox->setEnabled(checked); - if (!checked) //disabling wb disable auto-load. - autoloadCheckbox->setChecked(false); - break; - } - } - - // Reset the start combo items. - setStartWorkbenchComboItems(); -} - /** Build the list of unloaded workbenches. */ @@ -241,99 +289,13 @@ void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled if (wbName.toStdString() == "NoneWorkbench") return; // Do not list the default empty Workbench - QWidget* widget = createWorkbenchWidget(wbName, enabled); + wbListItem* widget = new wbListItem(wbName, enabled, this, this); auto wItem = new QListWidgetItem(); wItem->setSizeHint(widget->sizeHint()); ui->wbList->addItem(wItem); ui->wbList->setItemWidget(wItem, widget); } -QWidget* DlgSettingsWorkbenchesImp::createWorkbenchWidget(const QString& wbName, bool enabled) -{ - auto wbTooltip = Application::Instance->workbenchToolTip(wbName); - auto wbDisplayName = Application::Instance->workbenchMenuText(wbName); - - // 1: Enable checkbox - auto enableCheckBox = new QCheckBox(this); - enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); - enableCheckBox->setChecked(enabled); - enableCheckBox->setObjectName(enableCheckboxStr); - if (wbName.toStdString() == _startupModule) { - enableCheckBox->setChecked(true); - enableCheckBox->setEnabled(false); - enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); - } - connect(enableCheckBox, &QCheckBox::toggled, this, [this, wbName](bool checked) { onWbActivated(wbName, checked); }); - - // 2: Workbench Icon - auto wbIcon = Application::Instance->workbenchIcon(wbName); - auto iconLabel = new QLabel(wbDisplayName); - iconLabel->setObjectName(iconLabelStr); - iconLabel->setPixmap(wbIcon.scaled(QSize(20, 20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); - iconLabel->setToolTip(wbTooltip); - iconLabel->setContentsMargins(5, 0, 0, 5); // Left, top, right, bottom - iconLabel->setEnabled(enableCheckBox->isChecked()); - - // 3: Workbench Display Name - auto textLabel = new QLabel(wbDisplayName); - textLabel->setObjectName(nameLabelStr); - textLabel->setToolTip(wbTooltip); - QFont font = textLabel->font(); - font.setBold(true); - textLabel->setFont(font); - textLabel->setEnabled(enableCheckBox->isChecked()); - textLabel->setMinimumSize(200,0); - - - // 4: Autoloaded checkBox. - auto autoloadCheckBox = new QCheckBox(this); - autoloadCheckBox->setObjectName(autoloadCheckboxStr); - autoloadCheckBox->setText(tr("Auto-load")); - autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); - autoloadCheckBox->setEnabled(enableCheckBox->isChecked()); - - if (wbName.toStdString() == _startupModule) { // Figure out whether to check and/or disable this checkBox: - autoloadCheckBox->setChecked(true); - autoloadCheckBox->setEnabled(false); - autoloadCheckBox->setToolTip(tr("This is the current startup module, and must be autoloaded. See Preferences/General/Autoload to change.")); - } - else if (std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), - wbName.toStdString()) != _backgroundAutoloadedModules.end()) { - autoloadCheckBox->setChecked(true); - } - - // 5: Load button/loaded indicator - auto loadLabel = new QLabel(tr("Loaded")); - loadLabel->setAlignment(Qt::AlignCenter); - loadLabel->setObjectName(loadLabelStr); - loadLabel->setEnabled(enableCheckBox->isChecked()); - auto loadButton = new QPushButton(tr("Load")); - loadButton->setObjectName(loadButtonStr); - loadButton->setToolTip(tr("To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.")); - loadButton->setEnabled(enableCheckBox->isChecked()); - connect(loadButton, &QPushButton::clicked, this, [this, wbName]() { onLoadClicked(wbName); }); - if (WorkbenchManager::instance()->getWorkbench(wbName.toStdString())) { - loadButton->setVisible(false); - } - else { - loadLabel->setVisible(false); - } - - auto mainWidget = new QWidget(this); - mainWidget->setObjectName(wbName); - auto layout = new QHBoxLayout(mainWidget); - layout->addWidget(enableCheckBox); - layout->addWidget(iconLabel); - layout->addWidget(textLabel); - layout->addWidget(loadButton); - layout->addWidget(loadLabel); - layout->addWidget(autoloadCheckBox); - layout->setAlignment(Qt::AlignLeft); - layout->setContentsMargins(10, 0, 0, 0); - - return mainWidget; -} - QStringList DlgSettingsWorkbenchesImp::getEnabledWorkbenches() { @@ -415,12 +377,9 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() // fills the combo box with activated workbenches. QStringList enabledWbs; for (int i = 0; i < ui->wbList->count(); i++) { - QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); - if (widget) { - QCheckBox* enableCheckbox = widget->findChild(enableCheckboxStr); - if (enableCheckbox && enableCheckbox->isChecked()) { - enabledWbs << widget->objectName(); - } + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (wbItem && wbItem->enableCheckBox->isChecked()) { + enabledWbs << wbItem->objectName(); } } @@ -464,14 +423,13 @@ void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) //Change wb that user can't deactivate. for (int i = 0; i < ui->wbList->count(); i++) { - QWidget* widget = ui->wbList->itemWidget(ui->wbList->item(i)); - if (widget) { - QCheckBox* enableCheckbox = widget->findChild(enableCheckboxStr); - if (enableCheckbox && widget->objectName() == wbName) { - enableCheckbox->setEnabled(false); + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (wbItem) { + if (wbItem->objectName() == wbName) { + wbItem->enableCheckBox->setEnabled(false); } else { - enableCheckbox->setEnabled(true); + wbItem->enableCheckBox->setEnabled(true); } } } diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 78bc20baa6..f8f4ae401f 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -33,7 +33,6 @@ namespace Gui { namespace Dialog { class Ui_DlgSettingsWorkbenches; - /** * The DlgSettingsWorkbenchesImp class implements a pseudo-preference page explain why * the remaining preference pages aren't loaded yet, and to help the user do so on demand. @@ -53,9 +52,10 @@ public: static QStringList getEnabledWorkbenches(); static QStringList getDisabledWorkbenches(); -protected Q_SLOTS: - void onLoadClicked(const QString& wbName); - void onWbActivated(const QString& wbName, bool checked); + void setStartWorkbenchComboItems(); + + std::vector _backgroundAutoloadedModules; + std::string _startupModule; protected: void buildWorkbenchList(); @@ -63,24 +63,36 @@ protected: private: void addWorkbench(const QString& it, bool enabled); - QWidget* createWorkbenchWidget(const QString& it, bool enabled); void saveWorkbenchSelector(); void loadWorkbenchSelector(); - void setStartWorkbenchComboItems(); void onStartWbChangedClicked(int index); std::unique_ptr ui; - static const QString iconLabelStr; - static const QString nameLabelStr; - static const QString loadLabelStr; - static const QString loadButtonStr; - static const QString enableCheckboxStr; - static const QString autoloadCheckboxStr; +}; - std::vector _backgroundAutoloadedModules; - std::string _startupModule; +class wbListItem : public QWidget +{ + Q_OBJECT + +public: + explicit wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dlg, QWidget* parent = nullptr); + ~wbListItem() override; + +protected Q_SLOTS: + void onLoadClicked(); + void onWbActivated(bool checked); + +public: + QCheckBox* enableCheckBox; + QCheckBox* autoloadCheckBox; + QLabel* iconLabel; + QLabel* textLabel; + QLabel* loadLabel; + QPushButton* loadButton; + + DlgSettingsWorkbenchesImp* dlg; }; } // namespace Dialog From f9c5c08344a13713a2a9c826d5414ac5e60194eb Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 10:53:54 +0200 Subject: [PATCH 13/22] Pref: wb: Move wbListItem to cpp. --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 32 +++++++++++++++++++++++---- src/Gui/DlgSettingsWorkbenchesImp.h | 31 ++------------------------ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index d8def7ed38..66d900b1f6 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include #include +#include #include #endif @@ -37,6 +38,29 @@ using namespace Gui::Dialog; +namespace Gui::Dialog { +class wbListItem : public QWidget +{ +public: + explicit wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dlg, QWidget* parent = nullptr); + ~wbListItem() override; + +protected Q_SLOTS: + void onLoadClicked(); + void onWbActivated(bool checked); + +public: + QCheckBox* enableCheckBox; + QCheckBox* autoloadCheckBox; + QLabel* iconLabel; + QLabel* textLabel; + QLabel* loadLabel; + QPushButton* loadButton; + + DlgSettingsWorkbenchesImp* dlg; +}; +} + wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dialog, QWidget* parent) : QWidget(parent) , dlg(dialog) { @@ -58,14 +82,14 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbench // 2: Workbench Icon auto wbIcon = Application::Instance->workbenchIcon(wbName); - iconLabel = new QLabel(wbDisplayName); + iconLabel = new QLabel(wbDisplayName, this); iconLabel->setPixmap(wbIcon.scaled(QSize(20, 20), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation)); iconLabel->setToolTip(wbTooltip); iconLabel->setContentsMargins(5, 0, 0, 5); // Left, top, right, bottom iconLabel->setEnabled(enableCheckBox->isChecked()); // 3: Workbench Display Name - textLabel = new QLabel(wbDisplayName); + textLabel = new QLabel(wbDisplayName, this); textLabel->setToolTip(wbTooltip); QFont font = textLabel->font(); font.setBold(true); @@ -91,10 +115,10 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbench } // 5: Load button/loaded indicator - loadLabel = new QLabel(tr("Loaded")); + loadLabel = new QLabel(tr("Loaded"), this); loadLabel->setAlignment(Qt::AlignCenter); loadLabel->setEnabled(enableCheckBox->isChecked()); - loadButton = new QPushButton(tr("Load")); + loadButton = new QPushButton(tr("Load"), this); loadButton->setToolTip(tr("To preserve resources, FreeCAD does not load workbenches until they are used. Loading them may provide access to additional preferences related to their functionality.")); loadButton->setEnabled(enableCheckBox->isChecked()); connect(loadButton, &QPushButton::clicked, this, [this]() { onLoadClicked(); }); diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index f8f4ae401f..d21d59294b 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -27,10 +27,7 @@ #include "PropertyPage.h" #include -class QCheckBox; - -namespace Gui { -namespace Dialog { +namespace Gui::Dialog { class Ui_DlgSettingsWorkbenches; /** @@ -72,30 +69,6 @@ private: std::unique_ptr ui; }; -class wbListItem : public QWidget -{ - Q_OBJECT - -public: - explicit wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dlg, QWidget* parent = nullptr); - ~wbListItem() override; - -protected Q_SLOTS: - void onLoadClicked(); - void onWbActivated(bool checked); - -public: - QCheckBox* enableCheckBox; - QCheckBox* autoloadCheckBox; - QLabel* iconLabel; - QLabel* textLabel; - QLabel* loadLabel; - QPushButton* loadButton; - - DlgSettingsWorkbenchesImp* dlg; -}; - -} // namespace Dialog -} // namespace Gui +} // namespace Gui::Dialog #endif // GUI_DIALOG_DLGSETTINGSWORKBENCHES_IMP_H From c480af73bc42e0f878a0b75b5c33b2ecdc237961 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 11:14:01 +0200 Subject: [PATCH 14/22] Pref: Wb: add setters and getters to wbListItem --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 34 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 66d900b1f6..cf0befcc9e 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -45,11 +45,15 @@ public: explicit wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dlg, QWidget* parent = nullptr); ~wbListItem() override; + bool isEnabled(); + bool isAutoLoading(); + void setEnableCheckboxActivated(bool val); + protected Q_SLOTS: void onLoadClicked(); void onWbActivated(bool checked); -public: +private: QCheckBox* enableCheckBox; QCheckBox* autoloadCheckBox; QLabel* iconLabel; @@ -144,6 +148,21 @@ wbListItem::~wbListItem() { } +bool wbListItem::isEnabled() +{ + return enableCheckBox->isChecked(); +} + +bool wbListItem::isAutoLoading() +{ + return autoloadCheckBox->isChecked(); +} + +void wbListItem::setEnableCheckboxActivated(bool val) +{ + enableCheckBox->setEnabled(val); +} + void wbListItem::onLoadClicked() { // activate selected workbench @@ -209,7 +228,7 @@ void DlgSettingsWorkbenchesImp::saveSettings() if (!wbItem) continue; - if (wbItem->enableCheckBox->isChecked()) { + if (wbItem->isEnabled()) { if (!enabledStr.str().empty()) enabledStr << ","; enabledStr << wbItem->objectName().toStdString(); @@ -220,7 +239,7 @@ void DlgSettingsWorkbenchesImp::saveSettings() disabledStr << wbItem->objectName().toStdString(); } - if (wbItem->autoloadCheckBox->isChecked()) { + if (wbItem->isAutoLoading()) { if (!autoloadStr.str().empty()) autoloadStr << ","; autoloadStr << wbItem->objectName().toStdString(); @@ -402,7 +421,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() QStringList enabledWbs; for (int i = 0; i < ui->wbList->count(); i++) { wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); - if (wbItem && wbItem->enableCheckBox->isChecked()) { + if (wbItem && wbItem->isEnabled()) { enabledWbs << wbItem->objectName(); } } @@ -449,12 +468,7 @@ void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) for (int i = 0; i < ui->wbList->count(); i++) { wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); if (wbItem) { - if (wbItem->objectName() == wbName) { - wbItem->enableCheckBox->setEnabled(false); - } - else { - wbItem->enableCheckBox->setEnabled(true); - } + wbItem->setEnableCheckboxActivated(!(wbItem->objectName() == wbName)); } } } From 09c9fd601d94dafe1f95fde7e0982fa4fdae14a7 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 14:43:57 +0200 Subject: [PATCH 15/22] Pref: Wb: remove the dlg pointer from the wbListItem --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 28 ++++++++++++++++----------- src/Gui/DlgSettingsWorkbenchesImp.h | 7 ++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index cf0befcc9e..f0d665c8dc 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -41,8 +41,10 @@ using namespace Gui::Dialog; namespace Gui::Dialog { class wbListItem : public QWidget { + Q_OBJECT + public: - explicit wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dlg, QWidget* parent = nullptr); + explicit wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, QWidget* parent = nullptr); ~wbListItem() override; bool isEnabled(); @@ -53,6 +55,9 @@ protected Q_SLOTS: void onLoadClicked(); void onWbActivated(bool checked); +Q_SIGNALS: + void activatedWbListChanged(); + private: QCheckBox* enableCheckBox; QCheckBox* autoloadCheckBox; @@ -60,13 +65,10 @@ private: QLabel* textLabel; QLabel* loadLabel; QPushButton* loadButton; - - DlgSettingsWorkbenchesImp* dlg; }; } -wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbenchesImp* dialog, QWidget* parent) : QWidget(parent) - , dlg(dialog) +wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, QWidget* parent) : QWidget(parent) { this->setObjectName(wbName); @@ -77,7 +79,7 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbench enableCheckBox = new QCheckBox(this); enableCheckBox->setToolTip(tr("If unchecked, %1 will not appear in the available workbenches.").arg(wbDisplayName)); enableCheckBox->setChecked(enabled); - if (wbName.toStdString() == dlg->_startupModule) { + if (startupWb) { enableCheckBox->setChecked(true); enableCheckBox->setEnabled(false); enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); @@ -108,13 +110,12 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, DlgSettingsWorkbench autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); autoloadCheckBox->setEnabled(enableCheckBox->isChecked()); - if (wbName.toStdString() == dlg->_startupModule) { // Figure out whether to check and/or disable this checkBox: + if (startupWb) { // Figure out whether to check and/or disable this checkBox: autoloadCheckBox->setChecked(true); autoloadCheckBox->setEnabled(false); autoloadCheckBox->setToolTip(tr("This is the current startup module, and must be autoloaded. See Preferences/General/Autoload to change.")); } - else if (std::find(dlg->_backgroundAutoloadedModules.begin(), dlg->_backgroundAutoloadedModules.end(), - wbName.toStdString()) != dlg->_backgroundAutoloadedModules.end()) { + else if (autoLoad) { autoloadCheckBox->setChecked(true); } @@ -187,7 +188,7 @@ void wbListItem::onWbActivated(bool checked) autoloadCheckBox->setChecked(false); // Reset the start combo items. - dlg->setStartWorkbenchComboItems(); + Q_EMIT activatedWbListChanged(); } /* TRANSLATOR Gui::Dialog::DlgSettingsWorkbenchesImp */ @@ -332,7 +333,11 @@ void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled if (wbName.toStdString() == "NoneWorkbench") return; // Do not list the default empty Workbench - wbListItem* widget = new wbListItem(wbName, enabled, this, this); + bool isStartupWb = wbName.toStdString() == _startupModule; + bool autoLoad = std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), + wbName.toStdString()) != _backgroundAutoloadedModules.end(); + wbListItem* widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, this); + connect(widget, &wbListItem::activatedWbListChanged, this, &DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems); auto wItem = new QListWidgetItem(); wItem->setSizeHint(widget->sizeHint()); ui->wbList->addItem(wItem); @@ -474,3 +479,4 @@ void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) } #include "moc_DlgSettingsWorkbenchesImp.cpp" +#include "DlgSettingsWorkbenchesImp.moc" \ No newline at end of file diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index d21d59294b..37632e83e2 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -49,11 +49,9 @@ public: static QStringList getEnabledWorkbenches(); static QStringList getDisabledWorkbenches(); +protected Q_SLOTS: void setStartWorkbenchComboItems(); - std::vector _backgroundAutoloadedModules; - std::string _startupModule; - protected: void buildWorkbenchList(); void changeEvent(QEvent *e) override; @@ -66,6 +64,9 @@ private: void onStartWbChangedClicked(int index); + std::vector _backgroundAutoloadedModules; + std::string _startupModule; + std::unique_ptr ui; }; From 3a66218f9dd9a757a11f8407b14dc90672111e6a Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 15:00:18 +0200 Subject: [PATCH 16/22] Pref: Wb: startup wb has to be autoloading. --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 19 +++++++++++-------- src/Gui/DlgSettingsWorkbenchesImp.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index f0d665c8dc..12d9dd7737 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -49,7 +49,7 @@ public: bool isEnabled(); bool isAutoLoading(); - void setEnableCheckboxActivated(bool val); + void setStartupWb(bool val); protected Q_SLOTS: void onLoadClicked(); @@ -103,7 +103,6 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool textLabel->setEnabled(enableCheckBox->isChecked()); textLabel->setMinimumSize(200, 0); - // 4: Autoloaded checkBox. autoloadCheckBox = new QCheckBox(this); autoloadCheckBox->setText(tr("Auto-load")); @@ -138,9 +137,9 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool layout->addWidget(enableCheckBox); layout->addWidget(iconLabel); layout->addWidget(textLabel); + layout->addWidget(autoloadCheckBox); layout->addWidget(loadButton); layout->addWidget(loadLabel); - layout->addWidget(autoloadCheckBox); layout->setAlignment(Qt::AlignLeft); layout->setContentsMargins(10, 0, 0, 0); } @@ -159,9 +158,13 @@ bool wbListItem::isAutoLoading() return autoloadCheckBox->isChecked(); } -void wbListItem::setEnableCheckboxActivated(bool val) +void wbListItem::setStartupWb(bool val) { - enableCheckBox->setEnabled(val); + if(val) + autoloadCheckBox->setChecked(true); + + enableCheckBox->setEnabled(!val); + autoloadCheckBox->setEnabled(!val); } void wbListItem::onLoadClicked() @@ -209,7 +212,7 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) ui->wbList->setDragEnabled(true); ui->wbList->setDefaultDropAction(Qt::MoveAction); - connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChangedClicked(index); }); + connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChanged(index); }); } /** @@ -462,7 +465,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() ui->AutoloadModuleCombo->setCurrentIndex(ui->AutoloadModuleCombo->findData(QString::fromStdString(_startupModule))); } -void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) +void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChanged(int index) { //Update _startupModule QVariant data = ui->AutoloadModuleCombo->itemData(index); @@ -473,7 +476,7 @@ void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChangedClicked(int index) for (int i = 0; i < ui->wbList->count(); i++) { wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); if (wbItem) { - wbItem->setEnableCheckboxActivated(!(wbItem->objectName() == wbName)); + wbItem->setStartupWb(wbItem->objectName() == wbName); } } } diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 37632e83e2..b2447cf149 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -62,7 +62,7 @@ private: void saveWorkbenchSelector(); void loadWorkbenchSelector(); - void onStartWbChangedClicked(int index); + void onStartWbChanged(int index); std::vector _backgroundAutoloadedModules; std::string _startupModule; From e66c0468db9fdf7205b4e0a7014a62642bf44585 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 16:02:21 +0200 Subject: [PATCH 17/22] Pref: Wb: lambda to simplify saveSettings() --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 12d9dd7737..ba8b90c486 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -227,35 +227,34 @@ void DlgSettingsWorkbenchesImp::saveSettings() { std::ostringstream enabledStr, disabledStr, autoloadStr; + auto addStrToOss = [](std::string wbName, std::ostringstream& oss) { + if (!oss.str().empty()) + oss << ","; + oss << wbName; + }; + for (int i = 0; i < ui->wbList->count(); i++) { wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); if (!wbItem) continue; + std::string wbName = wbItem->objectName().toStdString(); if (wbItem->isEnabled()) { - if (!enabledStr.str().empty()) - enabledStr << ","; - enabledStr << wbItem->objectName().toStdString(); + addStrToOss(wbName, enabledStr); } else { - if (!disabledStr.str().empty()) - disabledStr << ","; - disabledStr << wbItem->objectName().toStdString(); + addStrToOss(wbName, disabledStr); } if (wbItem->isAutoLoading()) { - if (!autoloadStr.str().empty()) - autoloadStr << ","; - autoloadStr << wbItem->objectName().toStdString(); + addStrToOss(wbName, autoloadStr); } } if (enabledStr.str().empty()) //make sure that we have at least one enabled workbench. enabledStr << "NoneWorkbench"; else { - if (!disabledStr.str().empty()) - disabledStr << ","; - disabledStr << "NoneWorkbench"; //Note, NoneWorkbench is not in the table so it's not added before. + addStrToOss("NoneWorkbench", disabledStr); //Note, NoneWorkbench is not in the table so it's not added before. } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); From dd10649096005ac8090d7f9de5c70171cbae479f Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 17:01:38 +0200 Subject: [PATCH 18/22] Pref: Wb: add shortcuts. --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 51 ++++++++++++++++++++++----- src/Gui/DlgSettingsWorkbenchesImp.h | 1 + 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index ba8b90c486..203c6b69b8 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -44,13 +44,15 @@ class wbListItem : public QWidget Q_OBJECT public: - explicit wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, QWidget* parent = nullptr); + explicit wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, int index, QWidget* parent = nullptr); ~wbListItem() override; bool isEnabled(); bool isAutoLoading(); void setStartupWb(bool val); + void setShortcutLabel(int index); + protected Q_SLOTS: void onLoadClicked(); void onWbActivated(bool checked); @@ -63,12 +65,13 @@ private: QCheckBox* autoloadCheckBox; QLabel* iconLabel; QLabel* textLabel; + QLabel* shortcutLabel; QLabel* loadLabel; QPushButton* loadButton; }; } -wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, QWidget* parent) : QWidget(parent) +wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoLoad, int index, QWidget* parent) : QWidget(parent) { this->setObjectName(wbName); @@ -86,6 +89,7 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool } connect(enableCheckBox, &QCheckBox::toggled, this, [this](bool checked) { onWbActivated(checked); }); + QWidget* subWidget = new QWidget(this); // 2: Workbench Icon auto wbIcon = Application::Instance->workbenchIcon(wbName); iconLabel = new QLabel(wbDisplayName, this); @@ -101,9 +105,22 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool font.setBold(true); textLabel->setFont(font); textLabel->setEnabled(enableCheckBox->isChecked()); - textLabel->setMinimumSize(200, 0); - // 4: Autoloaded checkBox. + // 4: shortcut + shortcutLabel = new QLabel(QString::fromLatin1("(W, %1)").arg(index + 1), this); + shortcutLabel->setToolTip(tr("Shortcut to activate this workbench.")); + shortcutLabel->setEnabled(enableCheckBox->isChecked()); + shortcutLabel->setVisible(index < 9); + + auto subLayout = new QHBoxLayout(subWidget); + subLayout->addWidget(iconLabel); + subLayout->addWidget(textLabel); + subLayout->addWidget(shortcutLabel); + subLayout->setAlignment(Qt::AlignLeft); + subLayout->setContentsMargins(5, 0, 0, 5); + subWidget->setMinimumSize(250, 0); + + // 5: Autoloaded checkBox. autoloadCheckBox = new QCheckBox(this); autoloadCheckBox->setText(tr("Auto-load")); autoloadCheckBox->setToolTip(tr("If checked, %1 will be loaded automatically when FreeCAD starts up").arg(wbDisplayName)); @@ -118,7 +135,7 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool autoloadCheckBox->setChecked(true); } - // 5: Load button/loaded indicator + // 6: Load button/loaded indicator loadLabel = new QLabel(tr("Loaded"), this); loadLabel->setAlignment(Qt::AlignCenter); loadLabel->setEnabled(enableCheckBox->isChecked()); @@ -135,8 +152,7 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool auto layout = new QHBoxLayout(this); layout->addWidget(enableCheckBox); - layout->addWidget(iconLabel); - layout->addWidget(textLabel); + layout->addWidget(subWidget); layout->addWidget(autoloadCheckBox); layout->addWidget(loadButton); layout->addWidget(loadLabel); @@ -167,6 +183,12 @@ void wbListItem::setStartupWb(bool val) autoloadCheckBox->setEnabled(!val); } +void wbListItem::setShortcutLabel(int index) +{ + shortcutLabel->setText(QString::fromLatin1("(W, %1)").arg(index + 1)); + shortcutLabel->setVisible(index < 9); +} + void wbListItem::onLoadClicked() { // activate selected workbench @@ -184,6 +206,7 @@ void wbListItem::onWbActivated(bool checked) // activate/deactivate the widgets iconLabel->setEnabled(checked); textLabel->setEnabled(checked); + shortcutLabel->setEnabled(checked); loadLabel->setEnabled(checked); loadButton->setEnabled(checked); autoloadCheckBox->setEnabled(checked); @@ -212,6 +235,8 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) ui->wbList->setDragEnabled(true); ui->wbList->setDefaultDropAction(Qt::MoveAction); + connect(ui->wbList->model(), &QAbstractItemModel::rowsMoved, this, &DlgSettingsWorkbenchesImp::wbItemMoved); + connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChanged(index); }); } @@ -338,7 +363,7 @@ void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled bool isStartupWb = wbName.toStdString() == _startupModule; bool autoLoad = std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), wbName.toStdString()) != _backgroundAutoloadedModules.end(); - wbListItem* widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, this); + wbListItem* widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, ui->wbList->count(), this); connect(widget, &wbListItem::activatedWbListChanged, this, &DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems); auto wItem = new QListWidgetItem(); wItem->setSizeHint(widget->sizeHint()); @@ -464,6 +489,16 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() ui->AutoloadModuleCombo->setCurrentIndex(ui->AutoloadModuleCombo->findData(QString::fromStdString(_startupModule))); } +void DlgSettingsWorkbenchesImp::wbItemMoved() +{ + for (int i = 0; i < ui->wbList->count(); i++) { + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (wbItem) { + wbItem->setShortcutLabel(i); + } + } +} + void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChanged(int index) { //Update _startupModule diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index b2447cf149..99e628917c 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -51,6 +51,7 @@ public: protected Q_SLOTS: void setStartWorkbenchComboItems(); + void wbItemMoved(); protected: void buildWorkbenchList(); From 24699f39a0c8e5e51b2807542fa031ff0c40d718 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 27 Mar 2023 18:40:34 +0200 Subject: [PATCH 19/22] Pref: Wb: add shortcuts + reorder when wb toggled. --- src/Gui/DlgSettingsWorkbenchesImp.cpp | 42 ++++++++++++++++++++++----- src/Gui/DlgSettingsWorkbenchesImp.h | 4 ++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 203c6b69b8..657378b923 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -55,10 +55,10 @@ public: protected Q_SLOTS: void onLoadClicked(); - void onWbActivated(bool checked); + void onWbToggled(bool checked); Q_SIGNALS: - void activatedWbListChanged(); + void wbToggled(const QString& wbName, bool enabled); private: QCheckBox* enableCheckBox; @@ -87,7 +87,7 @@ wbListItem::wbListItem(const QString& wbName, bool enabled, bool startupWb, bool enableCheckBox->setEnabled(false); enableCheckBox->setToolTip(tr("This is the current startup module, and must be enabled. See Preferences/General/Autoload to change.")); } - connect(enableCheckBox, &QCheckBox::toggled, this, [this](bool checked) { onWbActivated(checked); }); + connect(enableCheckBox, &QCheckBox::toggled, this, [this](bool checked) { onWbToggled(checked); }); QWidget* subWidget = new QWidget(this); // 2: Workbench Icon @@ -201,7 +201,7 @@ void wbListItem::onLoadClicked() loadLabel->setVisible(true); } -void wbListItem::onWbActivated(bool checked) +void wbListItem::onWbToggled(bool checked) { // activate/deactivate the widgets iconLabel->setEnabled(checked); @@ -212,9 +212,9 @@ void wbListItem::onWbActivated(bool checked) autoloadCheckBox->setEnabled(checked); if (!checked) //disabling wb disable auto-load. autoloadCheckBox->setChecked(false); - + // Reset the start combo items. - Q_EMIT activatedWbListChanged(); + Q_EMIT wbToggled(objectName(), checked); } /* TRANSLATOR Gui::Dialog::DlgSettingsWorkbenchesImp */ @@ -364,7 +364,7 @@ void DlgSettingsWorkbenchesImp::addWorkbench(const QString& wbName, bool enabled bool autoLoad = std::find(_backgroundAutoloadedModules.begin(), _backgroundAutoloadedModules.end(), wbName.toStdString()) != _backgroundAutoloadedModules.end(); wbListItem* widget = new wbListItem(wbName, enabled, isStartupWb, autoLoad, ui->wbList->count(), this); - connect(widget, &wbListItem::activatedWbListChanged, this, &DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems); + connect(widget, &wbListItem::wbToggled, this, &DlgSettingsWorkbenchesImp::wbToggled); auto wItem = new QListWidgetItem(); wItem->setSizeHint(widget->sizeHint()); ui->wbList->addItem(wItem); @@ -445,6 +445,34 @@ void DlgSettingsWorkbenchesImp::loadWorkbenchSelector() ui->WorkbenchSelectorPosition->setCurrentIndex(WorkbenchSwitcher::getIndex()); } +void DlgSettingsWorkbenchesImp::wbToggled(const QString& wbName, bool enabled) +{ + setStartWorkbenchComboItems(); + + //reorder the list of items. + int wbIndex = 0; + for (int i = 0; i < ui->wbList->count(); i++) { + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (wbItem && wbItem->objectName() == wbName) { + wbIndex = i; + } + } + + int destinationIndex = ui->wbList->count(); + + for (int i = 0; i < ui->wbList->count(); i++) { + wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); + if (wbItem && !wbItem->isEnabled() && (enabled || ((wbItem->objectName()).toStdString() > wbName.toStdString()))) { + //If the wb was enabled, then it was in the disabled wbs. So it moves to the row of the currently first disabled wb + //If the wb was disabled. Then it goes to the disabled wb where it belongs alphabetically. + destinationIndex = i; + break; + } + } + ui->wbList->model()->moveRow(QModelIndex(), wbIndex, QModelIndex(), destinationIndex); + +} + void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() { ui->AutoloadModuleCombo->clear(); diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 99e628917c..9a790ef822 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -50,7 +50,7 @@ public: static QStringList getDisabledWorkbenches(); protected Q_SLOTS: - void setStartWorkbenchComboItems(); + void wbToggled(const QString& wbName, bool enabled); void wbItemMoved(); protected: @@ -60,6 +60,8 @@ protected: private: void addWorkbench(const QString& it, bool enabled); + void setStartWorkbenchComboItems(); + void saveWorkbenchSelector(); void loadWorkbenchSelector(); From 2107002ed26c944b77dc2b672b7d4a1d087dda03 Mon Sep 17 00:00:00 2001 From: Paddle Date: Tue, 28 Mar 2023 11:59:18 +0200 Subject: [PATCH 20/22] Pref: - add require-reboot capability to PreferencePage. - Implement this require-reboot in wb pref page --- src/Gui/ApplicationPy.cpp | 2 ++ src/Gui/CommandStd.cpp | 1 + src/Gui/DlgPreferencesImp.cpp | 36 +++++++++++++++++++++++++-- src/Gui/DlgPreferencesImp.h | 2 ++ src/Gui/DlgSettingsWorkbenches.ui | 2 +- src/Gui/DlgSettingsWorkbenchesImp.cpp | 20 ++++++++++++--- src/Gui/DlgSettingsWorkbenchesImp.h | 3 ++- src/Gui/PropertyPage.cpp | 14 ++++++++++- src/Gui/PropertyPage.h | 6 +++++ 9 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 6b04456f78..d0d5678179 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -1377,6 +1377,8 @@ PyObject* Application::sShowPreferences(PyObject * /*self*/, PyObject *args) wc.restoreCursor(); cDlg.exec(); wc.setWaitCursor(); + cDlg.isRebootRequired(); //The user may have applied first, then clicked the cancel button so it's not in the if(cDlg.exec()) + wc.setWaitCursor(); Py_Return; } diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index 4141b754fd..9af6dab2cf 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -383,6 +383,7 @@ void StdCmdDlgPreferences::activated(int iMsg) if (cDlg.exec()) { cDlg.activeGroupPage(groupName, index); } + cDlg.isRebootRequired(); //The user may have applied first, then clicked the cancel button so it's not in the if(cDlg.exec()) } //=========================================================================== diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp index e2b98f5c60..53a2df622c 100644 --- a/src/Gui/DlgPreferencesImp.cpp +++ b/src/Gui/DlgPreferencesImp.cpp @@ -32,6 +32,8 @@ # include # include # include +# include +# include #endif #include @@ -67,7 +69,7 @@ DlgPreferencesImp* DlgPreferencesImp::_activeDialog = nullptr; */ DlgPreferencesImp::DlgPreferencesImp(QWidget* parent, Qt::WindowFlags fl) : QDialog(parent, fl), ui(new Ui_DlgPreferences), - invalidParameter(false), canEmbedScrollArea(true) + invalidParameter(false), canEmbedScrollArea(true), rebootRequired(false) { ui->setupUi(this); QFontMetrics fm(font()); @@ -458,8 +460,10 @@ void DlgPreferencesImp::applyChanges() auto tabWidget = static_cast(ui->tabWidgetStack->widget(i)); for (int j=0; jcount(); j++) { auto page = qobject_cast(tabWidget->widget(j)); - if (page) + if (page) { page->saveSettings(); + rebootRequired = rebootRequired || page->isRebootRequired(); + } } } @@ -471,6 +475,34 @@ void DlgPreferencesImp::applyChanges() } } +void DlgPreferencesImp::isRebootRequired() +{ + if (rebootRequired) { + QMessageBox* restartBox = new QMessageBox(); + restartBox->setIcon(QMessageBox::Warning); + restartBox->setWindowTitle(tr("Restart required")); + restartBox->setText(tr("You must restart FreeCAD for changes to take effect.")); + restartBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + restartBox->setDefaultButton(QMessageBox::Cancel); + auto okBtn = restartBox->button(QMessageBox::Ok); + auto cancelBtn = restartBox->button(QMessageBox::Cancel); + okBtn->setText(tr("Restart now")); + cancelBtn->setText(tr("Restart later")); + + int exec = restartBox->exec(); + + if (exec == QMessageBox::Ok) { + //restart FreeCAD after a delay to give time to this dialog to close + QTimer::singleShot(1000, []() + { + QStringList args = QApplication::arguments(); + if (getMainWindow()->close()) + QProcess::startDetached(QApplication::applicationFilePath(), args); + }); + } + } +} + void DlgPreferencesImp::showEvent(QShowEvent* ev) { this->adjustSize(); diff --git a/src/Gui/DlgPreferencesImp.h b/src/Gui/DlgPreferencesImp.h index 2c5de5d002..0b71d7067c 100644 --- a/src/Gui/DlgPreferencesImp.h +++ b/src/Gui/DlgPreferencesImp.h @@ -125,6 +125,7 @@ public: void reload(); void activateGroupPage(const QString& group, int index); void activeGroupPage(QString& group, int& index) const; + void isRebootRequired(); protected: void changeEvent(QEvent *e) override; @@ -160,6 +161,7 @@ private: std::unique_ptr ui; bool invalidParameter; bool canEmbedScrollArea; + bool rebootRequired; static const int GroupNameRole; /**< A name for our Qt::UserRole, used when storing user data in a list item */ diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index a92c528dda..f21e38e188 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -29,7 +29,7 @@ - <html><head/><body><p>You can enable, disable and reorder workbenches (requires restart). Additional workbenches can be installed through the addon manager.</p><p> + <html><head/><body><p>You can reorder workbenches by drag and drop. Additional workbenches can be installed through the addon manager.</p><p> Currently, your system has the following workbenches:</p></body></html> diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 657378b923..87325e126e 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -180,7 +180,7 @@ void wbListItem::setStartupWb(bool val) autoloadCheckBox->setChecked(true); enableCheckBox->setEnabled(!val); - autoloadCheckBox->setEnabled(!val); + autoloadCheckBox->setEnabled(!val && textLabel->isEnabled()); } void wbListItem::setShortcutLabel(int index) @@ -236,8 +236,8 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) ui->wbList->setDefaultDropAction(Qt::MoveAction); connect(ui->wbList->model(), &QAbstractItemModel::rowsMoved, this, &DlgSettingsWorkbenchesImp::wbItemMoved); - - connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, [this](int index) { onStartWbChanged(index); }); + connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, &DlgSettingsWorkbenchesImp::onStartWbChanged); + connect(ui->WorkbenchSelectorPosition, QOverload::of(&QComboBox::activated), this, &DlgSettingsWorkbenchesImp::onWbSelectorChanged); } /** @@ -330,6 +330,8 @@ Build the list of unloaded workbenches. */ void DlgSettingsWorkbenchesImp::buildWorkbenchList() { + QSignalBlocker sigblk(ui->wbList); + QStringList workbenches = Application::Instance->workbenches(); QStringList enabledWbs = getEnabledWorkbenches(); QStringList disabledWbs = getDisabledWorkbenches(); @@ -437,6 +439,8 @@ void DlgSettingsWorkbenchesImp::saveWorkbenchSelector() void DlgSettingsWorkbenchesImp::loadWorkbenchSelector() { + QSignalBlocker sigblk(ui->WorkbenchSelectorPosition); + //workbench selector position combobox setup ui->WorkbenchSelectorPosition->clear(); ui->WorkbenchSelectorPosition->addItem(tr("Toolbar")); @@ -447,6 +451,8 @@ void DlgSettingsWorkbenchesImp::loadWorkbenchSelector() void DlgSettingsWorkbenchesImp::wbToggled(const QString& wbName, bool enabled) { + requireReboot(); + setStartWorkbenchComboItems(); //reorder the list of items. @@ -519,6 +525,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems() void DlgSettingsWorkbenchesImp::wbItemMoved() { + requireReboot(); for (int i = 0; i < ui->wbList->count(); i++) { wbListItem* wbItem = dynamic_cast(ui->wbList->itemWidget(ui->wbList->item(i))); if (wbItem) { @@ -527,7 +534,7 @@ void DlgSettingsWorkbenchesImp::wbItemMoved() } } -void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChanged(int index) +void DlgSettingsWorkbenchesImp::onStartWbChanged(int index) { //Update _startupModule QVariant data = ui->AutoloadModuleCombo->itemData(index); @@ -543,5 +550,10 @@ void Gui::Dialog::DlgSettingsWorkbenchesImp::onStartWbChanged(int index) } } +void Gui::Dialog::DlgSettingsWorkbenchesImp::onWbSelectorChanged(int index) +{ + requireReboot(); +} + #include "moc_DlgSettingsWorkbenchesImp.cpp" #include "DlgSettingsWorkbenchesImp.moc" \ No newline at end of file diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 9a790ef822..4d0fd86d61 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -52,6 +52,8 @@ public: protected Q_SLOTS: void wbToggled(const QString& wbName, bool enabled); void wbItemMoved(); + void onWbSelectorChanged(int index); + void onStartWbChanged(int index); protected: void buildWorkbenchList(); @@ -65,7 +67,6 @@ private: void saveWorkbenchSelector(); void loadWorkbenchSelector(); - void onStartWbChanged(int index); std::vector _backgroundAutoloadedModules; std::string _startupModule; diff --git a/src/Gui/PropertyPage.cpp b/src/Gui/PropertyPage.cpp index a26772c23e..8c5154176b 100644 --- a/src/Gui/PropertyPage.cpp +++ b/src/Gui/PropertyPage.cpp @@ -96,7 +96,7 @@ void PropertyPage::onReset() // ---------------------------------------------------------------- /** Construction */ -PreferencePage::PreferencePage(QWidget* parent) : QWidget(parent) +PreferencePage::PreferencePage(QWidget* parent) : QWidget(parent), rebootRequired(false) { } @@ -105,6 +105,18 @@ void PreferencePage::changeEvent(QEvent* event) QWidget::changeEvent(event); } +bool PreferencePage::isRebootRequired() +{ + return rebootRequired; +} + +void PreferencePage::requireReboot() +{ + rebootRequired = true; +} + + + // ---------------------------------------------------------------- PreferenceUiForm::PreferenceUiForm(const QString& fn, QWidget* parent) diff --git a/src/Gui/PropertyPage.h b/src/Gui/PropertyPage.h index 1794c6800f..4afafaa42c 100644 --- a/src/Gui/PropertyPage.h +++ b/src/Gui/PropertyPage.h @@ -71,12 +71,18 @@ public: explicit PreferencePage(QWidget* parent = nullptr); ~PreferencePage() override = default; + bool isRebootRequired(); + void requireReboot(); + public Q_SLOTS: virtual void loadSettings()=0; virtual void saveSettings()=0; protected: void changeEvent(QEvent* event) override = 0; + +private: + bool rebootRequired; }; /** Subclass that embeds a form from a UI file. From 46864203261cf75d0984a888fadb062235095cca Mon Sep 17 00:00:00 2001 From: Paddle Date: Tue, 28 Mar 2023 12:36:02 +0200 Subject: [PATCH 21/22] Changed copyright texts of modified pages. --- src/Gui/CommandStd.cpp | 44 ++++++++++++++------------- src/Gui/DlgGeneralImp.cpp | 44 ++++++++++++++------------- src/Gui/DlgGeneralImp.h | 44 ++++++++++++++------------- src/Gui/DlgPreferencesImp.cpp | 44 ++++++++++++++------------- src/Gui/DlgPreferencesImp.h | 44 ++++++++++++++------------- src/Gui/DlgSettingsWorkbenchesImp.cpp | 42 +++++++++++++------------ src/Gui/DlgSettingsWorkbenchesImp.h | 44 ++++++++++++++------------- src/Gui/ListWidgetDragBugFix.cpp | 44 ++++++++++++++------------- src/Gui/ListWidgetDragBugFix.h | 44 ++++++++++++++------------- src/Gui/PropertyPage.cpp | 42 +++++++++++++------------ src/Gui/PropertyPage.h | 44 ++++++++++++++------------- 11 files changed, 251 insertions(+), 229 deletions(-) diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index 9af6dab2cf..9d58e84e72 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ + // SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index f63f00cc86..bc5edc477e 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2004 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2004 Werner Mayer * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #include "PreCompiled.h" diff --git a/src/Gui/DlgGeneralImp.h b/src/Gui/DlgGeneralImp.h index ae74bdae0c..d3aa1afecb 100644 --- a/src/Gui/DlgGeneralImp.h +++ b/src/Gui/DlgGeneralImp.h @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2004 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2004 Werner Mayer * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #ifndef GUI_DIALOG_DLGGENERALIMP_H diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp index 53a2df622c..4133b00636 100644 --- a/src/Gui/DlgPreferencesImp.cpp +++ b/src/Gui/DlgPreferencesImp.cpp @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Gui/DlgPreferencesImp.h b/src/Gui/DlgPreferencesImp.h index 0b71d7067c..ec3fccfc00 100644 --- a/src/Gui/DlgPreferencesImp.h +++ b/src/Gui/DlgPreferencesImp.h @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ + // SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #ifndef GUI_DIALOG_DLGPREFERENCESIMP_H diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 87325e126e..2b91a9b69b 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -1,23 +1,25 @@ -/*************************************************************************** - * Copyright (c) 2020 Chris Hennes (chennes@pioneerlibrarysystem.org) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * + // SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2020 Chris Hennes (chennes@pioneerlibrarysystem.org) * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ #include "PreCompiled.h" diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 4d0fd86d61..8cc95381f1 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2020 Chris Hennes (chennes@pioneerlibrarysystem.org) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/**************************************************************************** +* Copyright (c) 2020 Chris Hennes (chennes@pioneerlibrarysystem.org) * +* Copyright (c) 2023 FreeCAD Project Association * +* * +* This file is part of FreeCAD. * +* * +* FreeCAD is free software: you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as * +* published by the Free Software Foundation, either version 2.1 of the * +* License, or (at your option) any later version. * +* * +* FreeCAD is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * +* Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public * +* License along with FreeCAD. If not, see * +* . * +* * +***************************************************************************/ #ifndef GUI_DIALOG_DLGSETTINGSWORKBENCHES_IMP_H diff --git a/src/Gui/ListWidgetDragBugFix.cpp b/src/Gui/ListWidgetDragBugFix.cpp index 23f5a11574..d679f7b248 100644 --- a/src/Gui/ListWidgetDragBugFix.cpp +++ b/src/Gui/ListWidgetDragBugFix.cpp @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2023 Boyer Pierre-louis * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2023 Boyer Pierre-louis * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ diff --git a/src/Gui/ListWidgetDragBugFix.h b/src/Gui/ListWidgetDragBugFix.h index 2af0b6fb52..9436a43f9c 100644 --- a/src/Gui/ListWidgetDragBugFix.h +++ b/src/Gui/ListWidgetDragBugFix.h @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2023 Boyer Pierre-louis * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ +// SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2023 Boyer Pierre-louis * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #ifndef QLISTWIDGETDRAGBUGFIX_HPP #define QLISTWIDGETDRAGBUGFIX_HPP diff --git a/src/Gui/PropertyPage.cpp b/src/Gui/PropertyPage.cpp index 8c5154176b..19b7e0916f 100644 --- a/src/Gui/PropertyPage.cpp +++ b/src/Gui/PropertyPage.cpp @@ -1,23 +1,25 @@ -/*************************************************************************** - * Copyright (c) 2004 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * +// SPDX-License-Identifier: LGPL-2.1-or-later + +/**************************************************************************** + * Copyright (c) 2004 Werner Mayer * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * ***************************************************************************/ #include "PreCompiled.h" diff --git a/src/Gui/PropertyPage.h b/src/Gui/PropertyPage.h index 4afafaa42c..702aba60bc 100644 --- a/src/Gui/PropertyPage.h +++ b/src/Gui/PropertyPage.h @@ -1,24 +1,26 @@ -/*************************************************************************** - * Copyright (c) 2004 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ + // SPDX-License-Identifier: LGPL-2.1-or-later + + /**************************************************************************** + * Copyright (c) 2004 Werner Mayer * + * Copyright (c) 2023 FreeCAD Project Association * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ #ifndef GUI_DIALOG_PROPERTYPAGE_H From 963fc2b17eb2325965351da309e640bfdd15315a Mon Sep 17 00:00:00 2001 From: Paddle Date: Tue, 28 Mar 2023 15:16:59 +0200 Subject: [PATCH 22/22] Pref: Wb : move 'Wb by tab' to wb pref page. --- src/Gui/DlgSettings3DView.ui | 19 ------------------- src/Gui/DlgSettings3DViewImp.cpp | 2 -- src/Gui/DlgSettingsWorkbenches.ui | 24 ++++++++++++++++++++++++ src/Gui/DlgSettingsWorkbenchesImp.cpp | 17 ++++++++++++++++- src/Gui/DlgSettingsWorkbenchesImp.h | 1 + 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/Gui/DlgSettings3DView.ui b/src/Gui/DlgSettings3DView.ui index c947251286..138c0bea19 100644 --- a/src/Gui/DlgSettings3DView.ui +++ b/src/Gui/DlgSettings3DView.ui @@ -129,25 +129,6 @@ will be shown at the lower left corner in opened files
- - - - If checked, application will remember which workbench is active for each tab of the viewport - - - Remember active workbench by tab - - - false - - - SaveWBbyTab - - - View - - - diff --git a/src/Gui/DlgSettings3DViewImp.cpp b/src/Gui/DlgSettings3DViewImp.cpp index 4bcb3ad5ab..1d5a80320e 100644 --- a/src/Gui/DlgSettings3DViewImp.cpp +++ b/src/Gui/DlgSettings3DViewImp.cpp @@ -82,7 +82,6 @@ void DlgSettings3DViewImp::saveSettings() ui->CheckBox_CornerCoordSystem->onSave(); ui->SpinBox_CornerCoordSystemSize->onSave(); ui->CheckBox_ShowAxisCross->onSave(); - ui->CheckBox_WbByTab->onSave(); ui->CheckBox_ShowFPS->onSave(); ui->spinPickRadius->onSave(); ui->CheckBox_use_SW_OpenGL->onSave(); @@ -100,7 +99,6 @@ void DlgSettings3DViewImp::loadSettings() ui->CheckBox_CornerCoordSystem->onRestore(); ui->SpinBox_CornerCoordSystemSize->onRestore(); ui->CheckBox_ShowAxisCross->onRestore(); - ui->CheckBox_WbByTab->onRestore(); ui->CheckBox_ShowFPS->onRestore(); ui->spinPickRadius->onRestore(); ui->CheckBox_use_SW_OpenGL->onRestore(); diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index f21e38e188..e6eb241d4d 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -111,6 +111,25 @@ after FreeCAD launches + + + + If checked, application will remember which workbench is active for each tab of the viewport + + + Remember active workbench by tab + + + false + + + SaveWBbyTab + + + View + + + @@ -120,6 +139,11 @@ after FreeCAD launches QListWidget
ListWidgetDragBugFix.h
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index 2b91a9b69b..d0581c3a04 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -240,6 +240,7 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent ) connect(ui->wbList->model(), &QAbstractItemModel::rowsMoved, this, &DlgSettingsWorkbenchesImp::wbItemMoved); connect(ui->AutoloadModuleCombo, QOverload::of(&QComboBox::activated), this, &DlgSettingsWorkbenchesImp::onStartWbChanged); connect(ui->WorkbenchSelectorPosition, QOverload::of(&QComboBox::activated), this, &DlgSettingsWorkbenchesImp::onWbSelectorChanged); + connect(ui->CheckBox_WbByTab, &QCheckBox::toggled, this, &DlgSettingsWorkbenchesImp::onWbByTabToggled); } /** @@ -298,6 +299,8 @@ void DlgSettingsWorkbenchesImp::saveSettings() QString startWbName = data.toString(); App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> SetASCII("AutoloadModule", startWbName.toLatin1()); + + ui->CheckBox_WbByTab->onSave(); } void DlgSettingsWorkbenchesImp::loadSettings() @@ -325,6 +328,11 @@ void DlgSettingsWorkbenchesImp::loadSettings() //We set the startup setting after building the list so that we can put only the enabled wb. setStartWorkbenchComboItems(); + + { + QSignalBlocker sigblk(ui->CheckBox_WbByTab); + ui->CheckBox_WbByTab->onRestore(); + } } /** @@ -552,8 +560,15 @@ void DlgSettingsWorkbenchesImp::onStartWbChanged(int index) } } -void Gui::Dialog::DlgSettingsWorkbenchesImp::onWbSelectorChanged(int index) +void DlgSettingsWorkbenchesImp::onWbSelectorChanged(int index) { + Q_UNUSED(index); + requireReboot(); +} + +void DlgSettingsWorkbenchesImp::onWbByTabToggled(bool val) +{ + Q_UNUSED(val); requireReboot(); } diff --git a/src/Gui/DlgSettingsWorkbenchesImp.h b/src/Gui/DlgSettingsWorkbenchesImp.h index 8cc95381f1..ce91a31034 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.h +++ b/src/Gui/DlgSettingsWorkbenchesImp.h @@ -56,6 +56,7 @@ protected Q_SLOTS: void wbItemMoved(); void onWbSelectorChanged(int index); void onStartWbChanged(int index); + void onWbByTabToggled(bool val); protected: void buildWorkbenchList();