Preferences: Workbench: Move startup workbench to workbench page

This commit is contained in:
Paddle
2023-03-26 07:57:00 +02:00
parent 9f904ae04f
commit 2fe2da2c4e
5 changed files with 119 additions and 78 deletions

View File

@@ -533,40 +533,6 @@ this according to your screen size or personal taste</string>
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="autoModuleLabel">
<property name="text">
<string>Auto load module after start up:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="AutoloadModuleCombo">
<property name="toolTip">
<string>Choose which workbench will be activated and shown
after FreeCAD launches</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="Gui::PrefCheckBox" name="SplashScreen">
<property name="toolTip">
<string>A Splash screen is a small loading window that is shown

View File

@@ -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<QString, QString> 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("<last>");
QString value = QString::fromLatin1("$LastModule");
if (px.isNull()) {
ui->AutoloadModuleCombo->addItem(key, QVariant(value));
}
else {
ui->AutoloadModuleCombo->addItem(px, key, QVariant(value));
}
}
for (QMap<QString, QString>::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();

View File

@@ -41,6 +41,40 @@ Your currently system has the following workbenches:&lt;/p&gt;&lt;/body&gt;&lt;/
<widget class="QListWidgetDragBugFix" name="wbList"/>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="autoModuleLabel">
<property name="text">
<string>Start up workbench:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="AutoloadModuleCombo">
<property name="toolTip">
<string>Choose which workbench will be activated and shown
after FreeCAD launches</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>

View File

@@ -54,6 +54,7 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent )
, ui(new Ui_DlgSettingsWorkbenches)
{
ui->setupUi(this);
connect(ui->AutoloadModuleCombo, QOverload<int>::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<QCheckBox*>(enableCheckboxStr);
if (enableCheckbox && enableCheckbox->isChecked()) {
enabledWbs << widget->objectName();
}
}
}
QMap<QString, QString> 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("<last>");
QString value = QString::fromLatin1("$LastModule");
if (px.isNull()) {
ui->AutoloadModuleCombo->addItem(key, QVariant(value));
}
else {
ui->AutoloadModuleCombo->addItem(px, key, QVariant(value));
}
}
for (QMap<QString, QString>::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<QCheckBox*>(enableCheckboxStr);
if (enableCheckbox && widget->objectName() == wbName) {
enableCheckbox->setEnabled(false);
}
else {
enableCheckbox->setEnabled(true);
}
}
}
}
#include "moc_DlgSettingsWorkbenchesImp.cpp"

View File

@@ -68,6 +68,9 @@ private:
void saveWorkbenchSelector();
void loadWorkbenchSelector();
void setStartWorkbenchComboItems();
void onStartWbChangedClicked(int index);
std::unique_ptr<Ui_DlgSettingsWorkbenches> ui;
static const QString iconLabelStr;
static const QString nameLabelStr;