All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -1,36 +1,36 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* 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 *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* 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 *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
# include <cmath>
|
||||
# include <limits>
|
||||
# include <QApplication>
|
||||
# include <QFileDialog>
|
||||
# include <QLocale>
|
||||
# include <QMessageBox>
|
||||
# include <QString>
|
||||
# include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
#include <algorithm>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Parameter.h>
|
||||
@@ -59,8 +59,8 @@
|
||||
using namespace Gui;
|
||||
using namespace Gui::Dialog;
|
||||
namespace fs = std::filesystem;
|
||||
using Base::UnitsApi;
|
||||
using Base::QuantityFormat;
|
||||
using Base::UnitsApi;
|
||||
|
||||
/* TRANSLATOR Gui::Dialog::DlgSettingsGeneral */
|
||||
|
||||
@@ -71,17 +71,17 @@ using Base::QuantityFormat;
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
DlgSettingsGeneral::DlgSettingsGeneral( QWidget* parent )
|
||||
: PreferencePage(parent)
|
||||
, localeIndex(0)
|
||||
, themeChanged(false)
|
||||
, ui(new Ui_DlgSettingsGeneral)
|
||||
DlgSettingsGeneral::DlgSettingsGeneral(QWidget* parent)
|
||||
: PreferencePage(parent)
|
||||
, localeIndex(0)
|
||||
, themeChanged(false)
|
||||
, ui(new Ui_DlgSettingsGeneral)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
recreatePreferencePackMenu();
|
||||
|
||||
for(const char* option : Translator::formattingOptions) {
|
||||
for (const char* option : Translator::formattingOptions) {
|
||||
ui->UseLocaleFormatting->addItem(tr(option));
|
||||
}
|
||||
|
||||
@@ -102,19 +102,39 @@ DlgSettingsGeneral::DlgSettingsGeneral( QWidget* parent )
|
||||
}
|
||||
if (ui->themesCombobox->isEnabled()) {
|
||||
connect(ui->ImportConfig, &QPushButton::clicked, this, &DlgSettingsGeneral::onImportConfigClicked);
|
||||
connect(ui->SaveNewPreferencePack, &QPushButton::clicked, this, &DlgSettingsGeneral::saveAsNewPreferencePack);
|
||||
connect(
|
||||
ui->SaveNewPreferencePack,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&DlgSettingsGeneral::saveAsNewPreferencePack
|
||||
);
|
||||
ui->ManagePreferencePacks->setToolTip(tr("Manage preference packs"));
|
||||
connect(ui->ManagePreferencePacks, &QPushButton::clicked, this, &DlgSettingsGeneral::onManagePreferencePacksClicked);
|
||||
connect(ui->themesCombobox, qOverload<int>(&QComboBox::activated), this, &DlgSettingsGeneral::onThemeChanged);
|
||||
connect(
|
||||
ui->ManagePreferencePacks,
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&DlgSettingsGeneral::onManagePreferencePacksClicked
|
||||
);
|
||||
connect(
|
||||
ui->themesCombobox,
|
||||
qOverload<int>(&QComboBox::activated),
|
||||
this,
|
||||
&DlgSettingsGeneral::onThemeChanged
|
||||
);
|
||||
connect(ui->moreThemesLabel, &QLabel::linkActivated, this, &DlgSettingsGeneral::onLinkActivated);
|
||||
}
|
||||
|
||||
// If there are any saved config file backs, show the revert button, otherwise hide it:
|
||||
const auto & backups = Application::Instance->prefPackManager()->configBackups();
|
||||
const auto& backups = Application::Instance->prefPackManager()->configBackups();
|
||||
ui->RevertToSavedConfig->setEnabled(backups.empty());
|
||||
connect(ui->RevertToSavedConfig, &QPushButton::clicked, this, &DlgSettingsGeneral::revertToSavedConfig);
|
||||
|
||||
connect(ui->comboBox_UnitSystem, qOverload<int>(&QComboBox::currentIndexChanged), this, &DlgSettingsGeneral::onUnitSystemIndexChanged);
|
||||
connect(
|
||||
ui->comboBox_UnitSystem,
|
||||
qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this,
|
||||
&DlgSettingsGeneral::onUnitSystemIndexChanged
|
||||
);
|
||||
ui->spinBoxDecimals->setMaximum(std::numeric_limits<double>::digits10 + 1);
|
||||
|
||||
auto addItem = [&, index {0}](const std::string& item) mutable {
|
||||
@@ -128,7 +148,8 @@ DlgSettingsGeneral::DlgSettingsGeneral( QWidget* parent )
|
||||
ui->comboBox_FracInch->setVisible(visible);
|
||||
ui->fractionalInchLabel->setVisible(visible);
|
||||
ui->moreThemesLabel->setEnabled(
|
||||
Application::Instance->commandManager().getCommandByName("Std_AddonMgr") != nullptr);
|
||||
Application::Instance->commandManager().getCommandByName("Std_AddonMgr") != nullptr
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +163,7 @@ DlgSettingsGeneral::~DlgSettingsGeneral() = default;
|
||||
*/
|
||||
void DlgSettingsGeneral::setRecentFileSize()
|
||||
{
|
||||
auto recent = getMainWindow()->findChild<RecentFilesAction *>
|
||||
(QLatin1String("recentFiles"));
|
||||
auto recent = getMainWindow()->findChild<RecentFilesAction*>(QLatin1String("recentFiles"));
|
||||
if (recent) {
|
||||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentFiles");
|
||||
recent->resizeList(hGrp->GetInt("RecentFiles", 4));
|
||||
@@ -164,7 +184,7 @@ bool DlgSettingsGeneral::setLanguage()
|
||||
return false;
|
||||
}
|
||||
|
||||
void DlgSettingsGeneral::setNumberLocale(bool force/* = false*/)
|
||||
void DlgSettingsGeneral::setNumberLocale(bool force /* = false*/)
|
||||
{
|
||||
int localeFormat = ui->UseLocaleFormatting->currentIndex();
|
||||
|
||||
@@ -178,8 +198,9 @@ void DlgSettingsGeneral::setNumberLocale(bool force/* = false*/)
|
||||
|
||||
void DlgSettingsGeneral::saveUnitSystemSettings()
|
||||
{
|
||||
ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/Units");
|
||||
ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Units"
|
||||
);
|
||||
hGrpu->SetInt("UserSchema", ui->comboBox_UnitSystem->currentIndex());
|
||||
hGrpu->SetInt("Decimals", ui->spinBoxDecimals->value());
|
||||
hGrpu->SetBool("IgnoreProjectSchema", ui->checkBox_projectUnitSystemIgnore->isChecked());
|
||||
@@ -241,14 +262,16 @@ void DlgSettingsGeneral::saveSettings()
|
||||
QVariant size = ui->toolbarIconSize->itemData(ui->toolbarIconSize->currentIndex());
|
||||
int pixel = size.toInt();
|
||||
hGrp->SetInt("ToolbarIconSize", pixel);
|
||||
getMainWindow()->setIconSize(QSize(pixel,pixel));
|
||||
getMainWindow()->setIconSize(QSize(pixel, pixel));
|
||||
|
||||
int blinkTime{hGrp->GetBool("EnableCursorBlinking", true) ? -1 : 0};
|
||||
int blinkTime {hGrp->GetBool("EnableCursorBlinking", true) ? -1 : 0};
|
||||
qApp->setCursorFlashTime(blinkTime);
|
||||
|
||||
saveDockWindowVisibility();
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow"
|
||||
);
|
||||
hGrp->SetBool("TiledBackground", ui->tiledBackground->isChecked());
|
||||
|
||||
if (themeChanged) {
|
||||
@@ -264,8 +287,9 @@ void DlgSettingsGeneral::loadSettings()
|
||||
int FracInch;
|
||||
int cbIndex;
|
||||
|
||||
ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/Units");
|
||||
ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Units"
|
||||
);
|
||||
ui->comboBox_UnitSystem->setCurrentIndex(hGrpu->GetInt("UserSchema", 0));
|
||||
ui->spinBoxDecimals->setValue(hGrpu->GetInt("Decimals", UnitsApi::getDecimals()));
|
||||
ui->checkBox_projectUnitSystemIgnore->setChecked(hGrpu->GetBool("IgnoreProjectSchema", false));
|
||||
@@ -309,8 +333,9 @@ void DlgSettingsGeneral::loadSettings()
|
||||
QLocale locale(QString::fromLatin1(it->second.c_str()));
|
||||
QString native = locale.nativeLanguageName();
|
||||
if (!native.isEmpty()) {
|
||||
if (native[0].isLetter())
|
||||
if (native[0].isLetter()) {
|
||||
native[0] = native[0].toUpper();
|
||||
}
|
||||
langname = native;
|
||||
}
|
||||
|
||||
@@ -327,10 +352,12 @@ void DlgSettingsGeneral::loadSettings()
|
||||
|
||||
addIconSizes(getCurrentIconSize());
|
||||
|
||||
//TreeMode combobox setup.
|
||||
// TreeMode combobox setup.
|
||||
loadDockWindowVisibility();
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow"
|
||||
);
|
||||
ui->tiledBackground->setChecked(hGrp->GetBool("TiledBackground", false));
|
||||
|
||||
loadThemes();
|
||||
@@ -340,43 +367,49 @@ void DlgSettingsGeneral::resetSettingsToDefaults()
|
||||
{
|
||||
ParameterGrp::handle hGrp;
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Units");
|
||||
//reset "UserSchema" parameter
|
||||
// reset "UserSchema" parameter
|
||||
hGrp->RemoveInt("UserSchema");
|
||||
//reset "Decimals" parameter
|
||||
// reset "Decimals" parameter
|
||||
hGrp->RemoveInt("Decimals");
|
||||
//reset "IgnoreProjectSchema" parameter
|
||||
// reset "IgnoreProjectSchema" parameter
|
||||
hGrp->RemoveBool("IgnoreProjectSchema");
|
||||
//reset "FracInch" parameter
|
||||
// reset "FracInch" parameter
|
||||
hGrp->RemoveInt("FracInch");
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
//reset "Theme" parameter
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow"
|
||||
);
|
||||
// reset "Theme" parameter
|
||||
hGrp->RemoveASCII("Theme");
|
||||
//reset "TiledBackground" parameter
|
||||
// reset "TiledBackground" parameter
|
||||
hGrp->RemoveBool("TiledBackground");
|
||||
|
||||
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DockWindows");
|
||||
//reset "ComboView" parameters
|
||||
hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/DockWindows"
|
||||
);
|
||||
// reset "ComboView" parameters
|
||||
hGrp->GetGroup("ComboView")->RemoveBool("Enabled");
|
||||
//reset "TreeView" parameters
|
||||
// reset "TreeView" parameters
|
||||
hGrp->GetGroup("TreeView")->RemoveBool("Enabled");
|
||||
//reset "PropertyView" parameters
|
||||
// reset "PropertyView" parameters
|
||||
hGrp->GetGroup("PropertyView")->RemoveBool("Enabled");
|
||||
|
||||
hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
|
||||
//reset "Language" parameter
|
||||
// reset "Language" parameter
|
||||
hGrp->RemoveASCII("Language");
|
||||
//reset "ToolbarIconSize" parameter
|
||||
// reset "ToolbarIconSize" parameter
|
||||
hGrp->RemoveInt("ToolbarIconSize");
|
||||
|
||||
//finally reset all the parameters associated to Gui::Pref* widgets
|
||||
// finally reset all the parameters associated to Gui::Pref* widgets
|
||||
PreferencePage::resetSettingsToDefaults();
|
||||
}
|
||||
|
||||
void DlgSettingsGeneral::saveThemes()
|
||||
{
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow"
|
||||
);
|
||||
|
||||
// First we check if the theme has actually changed.
|
||||
std::string previousTheme = hGrp->GetASCII("Theme", "").c_str();
|
||||
@@ -398,9 +431,10 @@ void DlgSettingsGeneral::saveThemes()
|
||||
if (pack.first == newTheme) {
|
||||
|
||||
if (Application::Instance->prefPackManager()->apply(pack.first)) {
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*> (this->window());
|
||||
if (parentDialog)
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*>(this->window());
|
||||
if (parentDialog) {
|
||||
parentDialog->reload();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -414,7 +448,8 @@ void DlgSettingsGeneral::loadThemes()
|
||||
ui->themesCombobox->clear();
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/MainWindow");
|
||||
"User parameter:BaseApp/Preferences/MainWindow"
|
||||
);
|
||||
|
||||
QString currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
|
||||
|
||||
@@ -440,8 +475,8 @@ void DlgSettingsGeneral::loadThemes()
|
||||
}
|
||||
|
||||
if (currentTheme.isEmpty()) {
|
||||
if (!currentStyleSheet.isEmpty()
|
||||
&& !similarTheme.isEmpty()) { // a user upgrading from 0.21 or earlier
|
||||
if (!currentStyleSheet.isEmpty() && !similarTheme.isEmpty()) { // a user upgrading from
|
||||
// 0.21 or earlier
|
||||
hGrp->SetASCII("Theme", similarTheme.toStdString());
|
||||
currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
|
||||
}
|
||||
@@ -468,7 +503,7 @@ void DlgSettingsGeneral::addIconSizes(int current)
|
||||
{
|
||||
ui->toolbarIconSize->clear();
|
||||
|
||||
QList<int> sizes{16, 24, 32, 48};
|
||||
QList<int> sizes {16, 24, 32, 48};
|
||||
if (!sizes.contains(current)) {
|
||||
sizes.append(current);
|
||||
}
|
||||
@@ -511,7 +546,7 @@ void DlgSettingsGeneral::retranslateUnits()
|
||||
std::for_each(descriptions.begin(), descriptions.end(), setItem);
|
||||
}
|
||||
|
||||
void DlgSettingsGeneral::changeEvent(QEvent *event)
|
||||
void DlgSettingsGeneral::changeEvent(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
translateIconSizes();
|
||||
@@ -527,7 +562,9 @@ void DlgSettingsGeneral::changeEvent(QEvent *event)
|
||||
|
||||
void DlgSettingsGeneral::saveDockWindowVisibility()
|
||||
{
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DockWindows");
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/DockWindows"
|
||||
);
|
||||
bool treeView = hGrp->GetGroup("TreeView")->GetBool("Enabled", false);
|
||||
bool propertyView = hGrp->GetGroup("PropertyView")->GetBool("Enabled", false);
|
||||
bool comboView = hGrp->GetGroup("ComboView")->GetBool("Enabled", true);
|
||||
@@ -545,14 +582,14 @@ void DlgSettingsGeneral::saveDockWindowVisibility()
|
||||
}
|
||||
|
||||
switch (ui->treeMode->currentIndex()) {
|
||||
case 0:
|
||||
comboView = true;
|
||||
treeView = propertyView = false;
|
||||
break;
|
||||
case 1:
|
||||
treeView = propertyView = true;
|
||||
comboView = false;
|
||||
break;
|
||||
case 0:
|
||||
comboView = true;
|
||||
treeView = propertyView = false;
|
||||
break;
|
||||
case 1:
|
||||
treeView = propertyView = true;
|
||||
comboView = false;
|
||||
break;
|
||||
}
|
||||
|
||||
hGrp->GetGroup("ComboView")->SetBool("Enabled", comboView);
|
||||
@@ -566,7 +603,9 @@ void DlgSettingsGeneral::loadDockWindowVisibility()
|
||||
ui->treeMode->addItem(tr("Combined"));
|
||||
ui->treeMode->addItem(tr("Independent"));
|
||||
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DockWindows");
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/DockWindows"
|
||||
);
|
||||
bool propertyView = hGrp->GetGroup("PropertyView")->GetBool("Enabled", false);
|
||||
bool treeView = hGrp->GetGroup("TreeView")->GetBool("Enabled", false);
|
||||
bool comboView = hGrp->GetGroup("ComboView")->GetBool("Enabled", true);
|
||||
@@ -582,18 +621,20 @@ void DlgSettingsGeneral::loadDockWindowVisibility()
|
||||
|
||||
void DlgSettingsGeneral::recreatePreferencePackMenu()
|
||||
{
|
||||
ui->PreferencePacks->setRowCount(0); // Begin by clearing whatever is there
|
||||
ui->PreferencePacks->setRowCount(0); // Begin by clearing whatever is there
|
||||
ui->PreferencePacks->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
||||
ui->PreferencePacks->setColumnCount(3);
|
||||
ui->PreferencePacks->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
|
||||
ui->PreferencePacks->horizontalHeader()->setStretchLastSection(false);
|
||||
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
||||
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeMode::Stretch);
|
||||
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeMode::ResizeToContents);
|
||||
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(
|
||||
2,
|
||||
QHeaderView::ResizeMode::ResizeToContents
|
||||
);
|
||||
QStringList columnHeaders;
|
||||
columnHeaders << tr("Preference Pack Name")
|
||||
<< tr("Tags")
|
||||
<< QString(); // for the "Load" buttons
|
||||
columnHeaders << tr("Preference Pack Name") << tr("Tags")
|
||||
<< QString(); // for the "Load" buttons
|
||||
ui->PreferencePacks->setHorizontalHeaderLabels(columnHeaders);
|
||||
|
||||
// Populate the Preference Packs list
|
||||
@@ -604,11 +645,11 @@ void DlgSettingsGeneral::recreatePreferencePackMenu()
|
||||
std::vector<std::string> packsToRemove;
|
||||
for (const auto& pack : packs) {
|
||||
if (pack.second.metadata().type() == "Theme") {
|
||||
packsToRemove.push_back(pack.first); // Store the keys to remove later
|
||||
packsToRemove.push_back(pack.first); // Store the keys to remove later
|
||||
}
|
||||
}
|
||||
for (const auto& key : packsToRemove) {
|
||||
packs.erase(key); // Remove the elements from the map
|
||||
packs.erase(key); // Remove the elements from the map
|
||||
}
|
||||
|
||||
ui->PreferencePacks->setRowCount(packs.size());
|
||||
@@ -622,10 +663,12 @@ void DlgSettingsGeneral::recreatePreferencePackMenu()
|
||||
auto tags = pack.second.metadata().tag();
|
||||
QString tagString;
|
||||
for (const auto& tag : tags) {
|
||||
if (tagString.isEmpty())
|
||||
if (tagString.isEmpty()) {
|
||||
tagString.append(QString::fromStdString(tag));
|
||||
else
|
||||
}
|
||||
else {
|
||||
tagString.append(QStringLiteral(", ") + QString::fromStdString(tag));
|
||||
}
|
||||
}
|
||||
auto kind = new QTableWidgetItem(tagString);
|
||||
ui->PreferencePacks->setItem(row, 1, kind);
|
||||
@@ -642,8 +685,12 @@ void DlgSettingsGeneral::recreatePreferencePackMenu()
|
||||
}
|
||||
}
|
||||
if (button->isEnabled()) {
|
||||
button->setToolTip(tr("Applies the %1 preference pack").arg(QString::fromStdString(pack.first)));
|
||||
connect(button, &QPushButton::clicked, this, [this, pack]() { onLoadPreferencePackClicked(pack.first); });
|
||||
button->setToolTip(
|
||||
tr("Applies the %1 preference pack").arg(QString::fromStdString(pack.first))
|
||||
);
|
||||
connect(button, &QPushButton::clicked, this, [this, pack]() {
|
||||
onLoadPreferencePackClicked(pack.first);
|
||||
});
|
||||
}
|
||||
ui->PreferencePacks->setCellWidget(row, 2, button);
|
||||
++row;
|
||||
@@ -655,9 +702,16 @@ void DlgSettingsGeneral::saveAsNewPreferencePack()
|
||||
// Create and run a modal New PreferencePack dialog box
|
||||
auto packs = Application::Instance->prefPackManager()->preferencePackNames();
|
||||
newPreferencePackDialog = std::make_unique<DlgCreateNewPreferencePackImp>(this);
|
||||
newPreferencePackDialog->setPreferencePackTemplates(Application::Instance->prefPackManager()->templateFiles());
|
||||
newPreferencePackDialog->setPreferencePackTemplates(
|
||||
Application::Instance->prefPackManager()->templateFiles()
|
||||
);
|
||||
newPreferencePackDialog->setPreferencePackNames(packs);
|
||||
connect(newPreferencePackDialog.get(), &DlgCreateNewPreferencePackImp::accepted, this, &DlgSettingsGeneral::newPreferencePackDialogAccepted);
|
||||
connect(
|
||||
newPreferencePackDialog.get(),
|
||||
&DlgCreateNewPreferencePackImp::accepted,
|
||||
this,
|
||||
&DlgSettingsGeneral::newPreferencePackDialogAccepted
|
||||
);
|
||||
newPreferencePackDialog->open();
|
||||
}
|
||||
|
||||
@@ -665,7 +719,7 @@ void DlgSettingsGeneral::revertToSavedConfig()
|
||||
{
|
||||
revertToBackupConfigDialog = std::make_unique<DlgRevertToBackupConfigImp>(this);
|
||||
connect(revertToBackupConfigDialog.get(), &DlgRevertToBackupConfigImp::accepted, this, [this]() {
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*> (this->window());
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*>(this->window());
|
||||
if (parentDialog) {
|
||||
parentDialog->reload();
|
||||
}
|
||||
@@ -678,17 +732,23 @@ void DlgSettingsGeneral::newPreferencePackDialogAccepted()
|
||||
auto preferencePackTemplates = Application::Instance->prefPackManager()->templateFiles();
|
||||
auto selection = newPreferencePackDialog->selectedTemplates();
|
||||
std::vector<PreferencePackManager::TemplateFile> selectedTemplates;
|
||||
std::copy_if(preferencePackTemplates.begin(), preferencePackTemplates.end(), std::back_inserter(selectedTemplates), [selection](PreferencePackManager::TemplateFile& tf) {
|
||||
for (const auto& item : selection) {
|
||||
if (item.group == tf.group && item.name == tf.name) {
|
||||
return true;
|
||||
std::copy_if(
|
||||
preferencePackTemplates.begin(),
|
||||
preferencePackTemplates.end(),
|
||||
std::back_inserter(selectedTemplates),
|
||||
[selection](PreferencePackManager::TemplateFile& tf) {
|
||||
for (const auto& item : selection) {
|
||||
if (item.group == tf.group && item.name == tf.name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
);
|
||||
auto preferencePackName = newPreferencePackDialog->preferencePackName();
|
||||
auto preferencePackDirectory = newPreferencePackDialog->preferencePackDirectory();
|
||||
Application::Instance->prefPackManager()->save(preferencePackName, preferencePackDirectory, selectedTemplates);
|
||||
Application::Instance->prefPackManager()
|
||||
->save(preferencePackName, preferencePackDirectory, selectedTemplates);
|
||||
recreatePreferencePackMenu();
|
||||
}
|
||||
|
||||
@@ -696,29 +756,39 @@ void DlgSettingsGeneral::onManagePreferencePacksClicked()
|
||||
{
|
||||
if (!this->preferencePackManagementDialog) {
|
||||
this->preferencePackManagementDialog = std::make_unique<DlgPreferencePackManagementImp>(this);
|
||||
connect(this->preferencePackManagementDialog.get(), &DlgPreferencePackManagementImp::packVisibilityChanged,
|
||||
this, &DlgSettingsGeneral::recreatePreferencePackMenu);
|
||||
connect(
|
||||
this->preferencePackManagementDialog.get(),
|
||||
&DlgPreferencePackManagementImp::packVisibilityChanged,
|
||||
this,
|
||||
&DlgSettingsGeneral::recreatePreferencePackMenu
|
||||
);
|
||||
}
|
||||
this->preferencePackManagementDialog->show();
|
||||
}
|
||||
|
||||
void DlgSettingsGeneral::onImportConfigClicked()
|
||||
{
|
||||
auto path = fs::path(QFileDialog::getOpenFileName(this,
|
||||
tr("Choose a FreeCAD config file to import"),
|
||||
QString(),
|
||||
QStringLiteral("*.cfg")).toStdString());
|
||||
auto path = fs::path(
|
||||
QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Choose a FreeCAD config file to import"),
|
||||
QString(),
|
||||
QStringLiteral("*.cfg")
|
||||
)
|
||||
.toStdString()
|
||||
);
|
||||
if (!path.empty()) {
|
||||
// Create a name from the filename:
|
||||
auto packName = path.filename().stem().string();
|
||||
std::replace(packName.begin(), packName.end(), '_', ' ');
|
||||
auto existingPacks = Application::Instance->prefPackManager()->preferencePackNames();
|
||||
if (std::ranges::find(existingPacks, packName)
|
||||
!= existingPacks.end()) {
|
||||
if (std::ranges::find(existingPacks, packName) != existingPacks.end()) {
|
||||
auto result = QMessageBox::question(
|
||||
this, tr("File exists"),
|
||||
tr("A preference pack with that name already exists. Overwrite?"));
|
||||
if (result == QMessageBox::No) { // Maybe someday ask for a new name?
|
||||
this,
|
||||
tr("File exists"),
|
||||
tr("A preference pack with that name already exists. Overwrite?")
|
||||
);
|
||||
if (result == QMessageBox::No) { // Maybe someday ask for a new name?
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -730,9 +800,10 @@ void DlgSettingsGeneral::onImportConfigClicked()
|
||||
void DlgSettingsGeneral::onLoadPreferencePackClicked(const std::string& packName)
|
||||
{
|
||||
if (Application::Instance->prefPackManager()->apply(packName)) {
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*> (this->window());
|
||||
if (parentDialog)
|
||||
auto parentDialog = qobject_cast<DlgPreferencesImp*>(this->window());
|
||||
if (parentDialog) {
|
||||
parentDialog->reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +820,8 @@ void DlgSettingsGeneral::onUnitSystemIndexChanged(const int index)
|
||||
ui->fractionalInchLabel->setVisible(visible);
|
||||
}
|
||||
|
||||
void DlgSettingsGeneral::onThemeChanged(int index) {
|
||||
void DlgSettingsGeneral::onThemeChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
themeChanged = true;
|
||||
}
|
||||
@@ -764,36 +836,44 @@ void DlgSettingsGeneral::onLinkActivated(const QString& link)
|
||||
|
||||
// Set the user preferences to include only preference packs.
|
||||
// This is a quick and dirty way to open Addon Manager with only themes.
|
||||
auto pref = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Addons");
|
||||
pref->SetInt("PackageTypeSelection", 3); // 3 stands for Preference Packs
|
||||
pref->SetInt("StatusSelection", 0); // 0 stands for any installation status
|
||||
auto pref = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Addons"
|
||||
);
|
||||
pref->SetInt("PackageTypeSelection", 3); // 3 stands for Preference Packs
|
||||
pref->SetInt("StatusSelection", 0); // 0 stands for any installation status
|
||||
|
||||
Gui::Application::Instance->commandManager().runCommandByName("Std_AddonMgr");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
class ApplyDockWidget: public ParamHandler {
|
||||
class ApplyDockWidget: public ParamHandler
|
||||
{
|
||||
public:
|
||||
bool onChange(const ParamKey *) override {
|
||||
bool onChange(const ParamKey*) override
|
||||
{
|
||||
OverlayManager::instance()->reload(OverlayManager::ReloadMode::ReloadPause);
|
||||
return true;
|
||||
}
|
||||
|
||||
void onTimer() override {
|
||||
void onTimer() override
|
||||
{
|
||||
getMainWindow()->initDockWindows(true);
|
||||
OverlayManager::instance()->reload(OverlayManager::ReloadMode::ReloadResume);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
} // anonymous namespace
|
||||
|
||||
void DlgSettingsGeneral::attachObserver()
|
||||
{
|
||||
static ParamHandlers handlers;
|
||||
|
||||
auto hDockWindows = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/DockWindows");
|
||||
auto hDockWindows = App::GetApplication().GetUserParameter().GetGroup(
|
||||
"BaseApp/Preferences/DockWindows"
|
||||
);
|
||||
auto applyDockWidget = std::shared_ptr<ParamHandler>(new ApplyDockWidget);
|
||||
handlers.addHandler(ParamKey(hDockWindows->GetGroup("ComboView"), "Enabled"), applyDockWidget);
|
||||
handlers.addHandler(ParamKey(hDockWindows->GetGroup("TreeView"), "Enabled"), applyDockWidget);
|
||||
|
||||
Reference in New Issue
Block a user