diff --git a/apps/librepcb/controlpanel/controlpanel.cpp b/apps/librepcb/controlpanel/controlpanel.cpp index 20024a89e5..0c40b2c98c 100644 --- a/apps/librepcb/controlpanel/controlpanel.cpp +++ b/apps/librepcb/controlpanel/controlpanel.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -110,8 +111,6 @@ ControlPanel::ControlPanel(Workspace& workspace) connect(mUi->actionAbout_Qt, &QAction::triggered, qApp, &QApplication::aboutQt); connect(mUi->actionAbout, &QAction::triggered, qApp, &Application::about); - connect(mUi->actionWorkspace_Settings, &QAction::triggered, - &mWorkspace.getSettings(), &WorkspaceSettings::showSettingsDialog); connect(mLibraryManager.data(), &LibraryManager::openLibraryEditorTriggered, this, &ControlPanel::openLibraryEditor); @@ -451,8 +450,8 @@ void ControlPanel::projectEditorClosed() noexcept { if (!editor) return; Project* project = &editor->getProject(); - Q_ASSERT(mOpenProjectEditors.contains( - project->getFilepath().toUnique().toStr())); + Q_ASSERT( + mOpenProjectEditors.contains(project->getFilepath().toUnique().toStr())); mOpenProjectEditors.remove(project->getFilepath().toUnique().toStr()); delete project; } @@ -504,6 +503,11 @@ void ControlPanel::on_actionSwitch_Workspace_triggered() { "restarting the application.")); } +void ControlPanel::on_actionWorkspace_Settings_triggered() { + WorkspaceSettingsDialog dialog(mWorkspace.getSettings(), this); + dialog.exec(); +} + void ControlPanel::on_projectTreeView_clicked(const QModelIndex& index) { FilePath fp(mWorkspace.getProjectTreeModel().filePath(index)); if ((fp.getSuffix() == "lpp") || (fp.getFilename() == "README.md")) { diff --git a/apps/librepcb/controlpanel/controlpanel.h b/apps/librepcb/controlpanel/controlpanel.h index dcd5ea0575..2d5e3e6cd3 100644 --- a/apps/librepcb/controlpanel/controlpanel.h +++ b/apps/librepcb/controlpanel/controlpanel.h @@ -106,6 +106,7 @@ private slots: void on_actionOpen_Library_Manager_triggered(); void on_actionClose_all_open_projects_triggered(); void on_actionSwitch_Workspace_triggered(); + void on_actionWorkspace_Settings_triggered(); void on_projectTreeView_clicked(const QModelIndex& index); void on_projectTreeView_doubleClicked(const QModelIndex& index); void on_projectTreeView_customContextMenuRequested(const QPoint& pos); diff --git a/apps/librepcb/main.cpp b/apps/librepcb/main.cpp index 71abb86345..b33a24d57a 100644 --- a/apps/librepcb/main.cpp +++ b/apps/librepcb/main.cpp @@ -212,8 +212,8 @@ static FilePath determineWorkspacePath() noexcept { // open workspace and apply settings Workspace ws(wsPath); - ws.getSettings().getUser().setName(wizard.getNewWorkspaceUserName()); - ws.getSettings().applyAll(); // can throw + ws.getSettings().userName.set(wizard.getNewWorkspaceUserName()); + ws.getSettings().saveToFile(); // can throw } catch (const Exception& e) { QMessageBox::critical(0, Application::translate("Workspace", "Error"), e.getMsg()); @@ -239,8 +239,8 @@ static int openWorkspace(const FilePath& path) noexcept { // Now since workspace settings are loaded, switch to the locale defined // there (until now, the system locale was used). - if (!ws.getSettings().getAppLocale().getAppLocaleName().isEmpty()) { - QLocale locale(ws.getSettings().getAppLocale().getAppLocaleName()); + if (!ws.getSettings().applicationLocale.get().isEmpty()) { + QLocale locale(ws.getSettings().applicationLocale.get()); QLocale::setDefault(locale); qApp->setTranslationLocale(locale); } diff --git a/libs/librepcb/common/application.cpp b/libs/librepcb/common/application.cpp index d51c243be4..e440411577 100644 --- a/libs/librepcb/common/application.cpp +++ b/libs/librepcb/common/application.cpp @@ -182,6 +182,17 @@ FilePath Application::getResourcesFilePath(const QString& filepath) const return mResourcesDir.getPathTo(filepath); } +QStringList Application::getAvailableTranslationLocales() const noexcept { + QStringList locales; + QDir dir(getResourcesFilePath("i18n").toStr()); + foreach (QString filename, dir.entryList({"*.qm"}, QDir::Files, QDir::Name)) { + filename.remove("librepcb_"); + filename.remove(".qm"); + locales.append(filename); + } + return locales; +} + const StrokeFont& Application::getDefaultStrokeFont() const noexcept { try { return mStrokeFontPool->getFont(getDefaultStrokeFontName()); diff --git a/libs/librepcb/common/application.h b/libs/librepcb/common/application.h index 63f005173f..0497a99b19 100644 --- a/libs/librepcb/common/application.h +++ b/libs/librepcb/common/application.h @@ -79,6 +79,7 @@ class Application final : public QApplication { bool isFileFormatStable() const noexcept { return mIsFileFormatStable; } const FilePath& getResourcesDir() const noexcept { return mResourcesDir; } FilePath getResourcesFilePath(const QString& filepath) const noexcept; + QStringList getAvailableTranslationLocales() const noexcept; const QFont& getDefaultSansSerifFont() const noexcept { return mSansSerifFont; } diff --git a/libs/librepcb/common/dialogs/gridsettingsdialog.cpp b/libs/librepcb/common/dialogs/gridsettingsdialog.cpp index fd309e735d..5fe533f31b 100644 --- a/libs/librepcb/common/dialogs/gridsettingsdialog.cpp +++ b/libs/librepcb/common/dialogs/gridsettingsdialog.cpp @@ -163,8 +163,7 @@ void GridSettingsDialog::buttonBoxClicked(QAbstractButton* button) { ******************************************************************************/ void GridSettingsDialog::updateInternalRepresentation() noexcept { - QLocale locale; // this loads the application's default locale (defined in - // WSI_AppLocale) + QLocale locale; // this loads the application's default locale mUi->lblIntervalNm->setText(QString("%1 nm").arg( locale.toString(mCurrentGrid.getInterval()->toNm()))); } diff --git a/libs/librepcb/libraryeditor/common/categorychooserdialog.cpp b/libs/librepcb/libraryeditor/common/categorychooserdialog.cpp index b66066b2f8..afae17f679 100644 --- a/libs/librepcb/libraryeditor/common/categorychooserdialog.cpp +++ b/libs/librepcb/libraryeditor/common/categorychooserdialog.cpp @@ -50,7 +50,7 @@ CategoryChooserDialog::CategoryChooserDialog( &CategoryChooserDialog::accept); mModel.reset(new workspace::CategoryTreeModel( - ws.getLibraryDb(), ws.getSettings().getLibLocaleOrder().getLocaleOrder(), + ws.getLibraryDb(), ws.getSettings().libraryLocaleOrder.get(), workspace::CategoryTreeFilter::ALL)); mUi->treeView->setModel(mModel.data()); mUi->treeView->setRootIndex(QModelIndex()); diff --git a/libs/librepcb/libraryeditor/common/categorylisteditorwidget.cpp b/libs/librepcb/libraryeditor/common/categorylisteditorwidget.cpp index 3a5325041f..5431aa2117 100644 --- a/libs/librepcb/libraryeditor/common/categorylisteditorwidget.cpp +++ b/libs/librepcb/libraryeditor/common/categorylisteditorwidget.cpp @@ -207,7 +207,7 @@ QString CategoryListEditorWidget::getCategoryName( const FilePath& fp) const { QString name; mWorkspace.getLibraryDb().template getElementTranslations( - fp, mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(), + fp, mWorkspace.getSettings().libraryLocaleOrder.get(), &name); // can throw return name; } diff --git a/libs/librepcb/libraryeditor/common/componentchooserdialog.cpp b/libs/librepcb/libraryeditor/common/componentchooserdialog.cpp index 24b4fdb4f0..b2dd17b0c2 100644 --- a/libs/librepcb/libraryeditor/common/componentchooserdialog.cpp +++ b/libs/librepcb/libraryeditor/common/componentchooserdialog.cpp @@ -254,7 +254,7 @@ void ComponentChooserDialog::accept() noexcept { } const QStringList& ComponentChooserDialog::localeOrder() const noexcept { - return mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + return mWorkspace.getSettings().libraryLocaleOrder.get(); } /******************************************************************************* diff --git a/libs/librepcb/libraryeditor/common/editorwidgetbase.cpp b/libs/librepcb/libraryeditor/common/editorwidgetbase.cpp index c46466d3bc..c33d69eb3a 100644 --- a/libs/librepcb/libraryeditor/common/editorwidgetbase.cpp +++ b/libs/librepcb/libraryeditor/common/editorwidgetbase.cpp @@ -178,11 +178,11 @@ void EditorWidgetBase::undoStackStateModified() noexcept { } const QStringList& EditorWidgetBase::getLibLocaleOrder() const noexcept { - return mContext.workspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + return mContext.workspace.getSettings().libraryLocaleOrder.get(); } QString EditorWidgetBase::getWorkspaceSettingsUserName() noexcept { - QString u = mContext.workspace.getSettings().getUser().getName().trimmed(); + QString u = mContext.workspace.getSettings().userName.get(); if (u.isEmpty()) { QMessageBox::warning( this, tr("User name not set"), diff --git a/libs/librepcb/libraryeditor/common/packagechooserdialog.cpp b/libs/librepcb/libraryeditor/common/packagechooserdialog.cpp index 45c86abef6..d3be35311d 100644 --- a/libs/librepcb/libraryeditor/common/packagechooserdialog.cpp +++ b/libs/librepcb/libraryeditor/common/packagechooserdialog.cpp @@ -234,7 +234,7 @@ void PackageChooserDialog::accept() noexcept { } const QStringList& PackageChooserDialog::localeOrder() const noexcept { - return mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + return mWorkspace.getSettings().libraryLocaleOrder.get(); } /******************************************************************************* diff --git a/libs/librepcb/libraryeditor/common/symbolchooserdialog.cpp b/libs/librepcb/libraryeditor/common/symbolchooserdialog.cpp index 155c7c3588..aa351451d8 100644 --- a/libs/librepcb/libraryeditor/common/symbolchooserdialog.cpp +++ b/libs/librepcb/libraryeditor/common/symbolchooserdialog.cpp @@ -233,7 +233,7 @@ void SymbolChooserDialog::accept() noexcept { } const QStringList& SymbolChooserDialog::localeOrder() const noexcept { - return mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + return mWorkspace.getSettings().libraryLocaleOrder.get(); } /******************************************************************************* diff --git a/libs/librepcb/libraryeditor/libraryeditor.cpp b/libs/librepcb/libraryeditor/libraryeditor.cpp index d80e08d99e..512410ecc7 100644 --- a/libs/librepcb/libraryeditor/libraryeditor.cpp +++ b/libs/librepcb/libraryeditor/libraryeditor.cpp @@ -129,7 +129,7 @@ LibraryEditor::LibraryEditor(workspace::Workspace& ws, const FilePath& libFp, // set window title and icon const QStringList localeOrder = - mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + mWorkspace.getSettings().libraryLocaleOrder.get(); QString libName = *mLibrary->getNames().value(localeOrder); if (readOnly) libName.append(tr(" [Read-Only]")); setWindowTitle(QString(tr("%1 - LibrePCB Library Editor")).arg(libName)); diff --git a/libs/librepcb/libraryeditor/newelementwizard/newelementwizardcontext.cpp b/libs/librepcb/libraryeditor/newelementwizard/newelementwizardcontext.cpp index c1b30763f5..436b8177da 100644 --- a/libs/librepcb/libraryeditor/newelementwizard/newelementwizardcontext.cpp +++ b/libs/librepcb/libraryeditor/newelementwizard/newelementwizardcontext.cpp @@ -58,7 +58,7 @@ NewElementWizardContext::~NewElementWizardContext() noexcept { ******************************************************************************/ const QStringList& NewElementWizardContext::getLibLocaleOrder() const noexcept { - return mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(); + return mWorkspace.getSettings().libraryLocaleOrder.get(); } /******************************************************************************* @@ -71,7 +71,7 @@ void NewElementWizardContext::reset(ElementType newType) noexcept { mElementName = tl::nullopt; mElementDescription.clear(); mElementKeywords.clear(); - mElementAuthor = mWorkspace.getSettings().getUser().getName(); + mElementAuthor = mWorkspace.getSettings().userName.get(); mElementVersion = Version::fromString("0.1"); mElementCategoryUuid = tl::nullopt; diff --git a/libs/librepcb/libraryeditor/newelementwizard/newelementwizardpage_entermetadata.cpp b/libs/librepcb/libraryeditor/newelementwizard/newelementwizardpage_entermetadata.cpp index 0746286500..9efbef95d1 100644 --- a/libs/librepcb/libraryeditor/newelementwizard/newelementwizardpage_entermetadata.cpp +++ b/libs/librepcb/libraryeditor/newelementwizard/newelementwizardpage_entermetadata.cpp @@ -169,10 +169,7 @@ void NewElementWizardPage_EnterMetadata::updateCategoryTreeLabel() noexcept { case NewElementWizardContext::ElementType::Device: { ComponentCategoryTreeLabelTextBuilder builder( mContext.getWorkspace().getLibraryDb(), - mContext.getWorkspace() - .getSettings() - .getLibLocaleOrder() - .getLocaleOrder(), + mContext.getWorkspace().getSettings().libraryLocaleOrder.get(), *mUi->lblCategoryTree); builder.setHighlightLastLine(true); builder.setOneLine(true); @@ -183,10 +180,7 @@ void NewElementWizardPage_EnterMetadata::updateCategoryTreeLabel() noexcept { case NewElementWizardContext::ElementType::Package: { PackageCategoryTreeLabelTextBuilder builder( mContext.getWorkspace().getLibraryDb(), - mContext.getWorkspace() - .getSettings() - .getLibLocaleOrder() - .getLocaleOrder(), + mContext.getWorkspace().getSettings().libraryLocaleOrder.get(), *mUi->lblCategoryTree); builder.setHighlightLastLine(true); builder.setOneLine(true); diff --git a/libs/librepcb/libraryeditor/pkg/packageeditorwidget.cpp b/libs/librepcb/libraryeditor/pkg/packageeditorwidget.cpp index 306c131443..48fc266249 100644 --- a/libs/librepcb/libraryeditor/pkg/packageeditorwidget.cpp +++ b/libs/librepcb/libraryeditor/pkg/packageeditorwidget.cpp @@ -65,7 +65,7 @@ PackageEditorWidget::PackageEditorWidget(const Context& context, mUi->lstMessages->setHandler(this); setupErrorNotificationWidget(*mUi->errorNotificationWidget); mUi->graphicsView->setUseOpenGl( - mContext.workspace.getSettings().getAppearance().getUseOpenGl()); + mContext.workspace.getSettings().useOpenGl.get()); mUi->graphicsView->setScene(mGraphicsScene.data()); mUi->graphicsView->setBackgroundBrush(Qt::black); mUi->graphicsView->setForegroundBrush(Qt::white); diff --git a/libs/librepcb/libraryeditor/sym/symboleditorwidget.cpp b/libs/librepcb/libraryeditor/sym/symboleditorwidget.cpp index d3a7a9388c..4ebf8f4f94 100644 --- a/libs/librepcb/libraryeditor/sym/symboleditorwidget.cpp +++ b/libs/librepcb/libraryeditor/sym/symboleditorwidget.cpp @@ -70,7 +70,7 @@ SymbolEditorWidget::SymbolEditorWidget(const Context& context, mUi->lstMessages->setHandler(this); setupErrorNotificationWidget(*mUi->errorNotificationWidget); mUi->graphicsView->setUseOpenGl( - mContext.workspace.getSettings().getAppearance().getUseOpenGl()); + mContext.workspace.getSettings().useOpenGl.get()); mUi->graphicsView->setScene(mGraphicsScene.data()); connect(mUi->graphicsView, &GraphicsView::cursorScenePositionChanged, this, &SymbolEditorWidget::cursorPositionChanged); diff --git a/libs/librepcb/librarymanager/addlibrarywidget.cpp b/libs/librepcb/librarymanager/addlibrarywidget.cpp index 8cc6a01404..631aa8bc2d 100644 --- a/libs/librepcb/librarymanager/addlibrarywidget.cpp +++ b/libs/librepcb/librarymanager/addlibrarywidget.cpp @@ -65,7 +65,7 @@ AddLibraryWidget::AddLibraryWidget(workspace::Workspace& ws) noexcept // tab "create local library": set placeholder texts mUi->edtLocalName->setPlaceholderText("My Library"); mUi->edtLocalAuthor->setPlaceholderText( - mWorkspace.getSettings().getUser().getName()); + mWorkspace.getSettings().userName.get()); mUi->edtLocalVersion->setPlaceholderText("0.1"); mUi->edtLocalUrl->setPlaceholderText( tr("e.g. the URL to the Git repository (optional)")); @@ -94,8 +94,7 @@ AddLibraryWidget::~AddLibraryWidget() noexcept { void AddLibraryWidget::updateRepositoryLibraryList() noexcept { clearRepositoryLibraryList(); - foreach (const QUrl& url, - mWorkspace.getSettings().getRepositories().getUrls()) { + foreach (const QUrl& url, mWorkspace.getSettings().repositoryUrls.get()) { std::shared_ptr repo = std::make_shared(url); connect(repo.get(), &Repository::libraryListReceived, this, &AddLibraryWidget::repositoryLibraryListReceived); diff --git a/libs/librepcb/librarymanager/libraryinfowidget.cpp b/libs/librepcb/librarymanager/libraryinfowidget.cpp index 8aaa633b0e..741043396c 100644 --- a/libs/librepcb/librarymanager/libraryinfowidget.cpp +++ b/libs/librepcb/librarymanager/libraryinfowidget.cpp @@ -62,8 +62,7 @@ LibraryInfoWidget::LibraryInfoWidget(workspace::Workspace& ws, std::unique_ptr(new TransactionalDirectory( TransactionalFileSystem::openRO(mLibDir)))); // can throw - const QStringList& localeOrder = - ws.getSettings().getLibLocaleOrder().getLocaleOrder(); + const QStringList& localeOrder = ws.getSettings().libraryLocaleOrder.get(); // image if (!lib.getIconAsPixmap().isNull()) { diff --git a/libs/librepcb/librarymanager/librarymanager.cpp b/libs/librepcb/librarymanager/librarymanager.cpp index 508e21fa0b..e18bd71014 100644 --- a/libs/librepcb/librarymanager/librarymanager.cpp +++ b/libs/librepcb/librarymanager/librarymanager.cpp @@ -134,8 +134,8 @@ void LibraryManager::updateLibraryList() noexcept { foreach (const FilePath& libDir, libraries) { QString name, description, keywords; mWorkspace.getLibraryDb().getElementTranslations( - libDir, mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder(), - &name, &description, &keywords); // can throw + libDir, mWorkspace.getSettings().libraryLocaleOrder.get(), &name, + &description, &keywords); // can throw QPixmap icon; mWorkspace.getLibraryDb().getLibraryMetadata(libDir, &icon); // can throw diff --git a/libs/librepcb/projecteditor/boardeditor/boardeditor.cpp b/libs/librepcb/projecteditor/boardeditor/boardeditor.cpp index 3fe04500a7..90b9a6907e 100644 --- a/libs/librepcb/projecteditor/boardeditor/boardeditor.cpp +++ b/libs/librepcb/projecteditor/boardeditor/boardeditor.cpp @@ -127,10 +127,8 @@ BoardEditor::BoardEditor(ProjectEditor& projectEditor, Project& project) // add graphics view as central widget mGraphicsView = new GraphicsView(nullptr, this); - mGraphicsView->setUseOpenGl(mProjectEditor.getWorkspace() - .getSettings() - .getAppearance() - .getUseOpenGl()); + mGraphicsView->setUseOpenGl( + mProjectEditor.getWorkspace().getSettings().useOpenGl.get()); mGraphicsView->setBackgroundBrush(Qt::black); mGraphicsView->setForegroundBrush(Qt::white); // setCentralWidget(mGraphicsView); diff --git a/libs/librepcb/projecteditor/newprojectwizard/newprojectwizard.cpp b/libs/librepcb/projecteditor/newprojectwizard/newprojectwizard.cpp index d5ed47126c..a4d01b2d33 100644 --- a/libs/librepcb/projecteditor/newprojectwizard/newprojectwizard.cpp +++ b/libs/librepcb/projecteditor/newprojectwizard/newprojectwizard.cpp @@ -92,10 +92,8 @@ Project* NewProjectWizard::createProject() const { // set project settings (copy from workspace settings) ProjectSettings& settings = project->getSettings(); - settings.setLocaleOrder( - mWorkspace.getSettings().getLibLocaleOrder().getLocaleOrder()); - settings.setNormOrder( - mWorkspace.getSettings().getLibNormOrder().getNormOrder()); + settings.setLocaleOrder(mWorkspace.getSettings().libraryLocaleOrder.get()); + settings.setNormOrder(mWorkspace.getSettings().libraryNormOrder.get()); // add schematic if (mPageInitialization->getCreateSchematic()) { diff --git a/libs/librepcb/projecteditor/newprojectwizard/newprojectwizardpage_metadata.cpp b/libs/librepcb/projecteditor/newprojectwizard/newprojectwizardpage_metadata.cpp index e38d2327d7..3cef6fe732 100644 --- a/libs/librepcb/projecteditor/newprojectwizard/newprojectwizardpage_metadata.cpp +++ b/libs/librepcb/projecteditor/newprojectwizard/newprojectwizardpage_metadata.cpp @@ -59,7 +59,7 @@ NewProjectWizardPage_Metadata::NewProjectWizardPage_Metadata( &NewProjectWizardPage_Metadata::chooseLocationClicked); // insert values - mUi->edtAuthor->setText(ws.getSettings().getUser().getName()); + mUi->edtAuthor->setText(ws.getSettings().userName.get()); mUi->cbxLicense->addItem(QString("No License (not recommended)"), QString()); mUi->cbxLicense->addItem( tr("CC0-1.0 (no restrictions, recommended for open hardware projects)"), diff --git a/libs/librepcb/projecteditor/projecteditor.cpp b/libs/librepcb/projecteditor/projecteditor.cpp index f712743743..5727ad8d8d 100644 --- a/libs/librepcb/projecteditor/projecteditor.cpp +++ b/libs/librepcb/projecteditor/projecteditor.cpp @@ -73,7 +73,7 @@ ProjectEditor::ProjectEditor(workspace::Workspace& workspace, Project& project) // setup the timer for automatic backups, if enabled in the settings int intervalSecs = - mWorkspace.getSettings().getProjectAutosaveInterval().getInterval(); + mWorkspace.getSettings().projectAutosaveIntervalSeconds.get(); if ((intervalSecs > 0) && project.getDirectory().isWritable()) { // autosaving is enabled --> start the timer connect(&mAutoSaveTimer, &QTimer::timeout, this, diff --git a/libs/librepcb/projecteditor/schematiceditor/schematiceditor.cpp b/libs/librepcb/projecteditor/schematiceditor/schematiceditor.cpp index fe3104f5e5..6864d6a52e 100644 --- a/libs/librepcb/projecteditor/schematiceditor/schematiceditor.cpp +++ b/libs/librepcb/projecteditor/schematiceditor/schematiceditor.cpp @@ -108,10 +108,8 @@ SchematicEditor::SchematicEditor(ProjectEditor& projectEditor, Project& project) // add graphics view as central widget mGraphicsView = new GraphicsView(nullptr, this); - mGraphicsView->setUseOpenGl(mProjectEditor.getWorkspace() - .getSettings() - .getAppearance() - .getUseOpenGl()); + mGraphicsView->setUseOpenGl( + mProjectEditor.getWorkspace().getSettings().useOpenGl.get()); mGraphicsView->setGridProperties(*mGridProperties); setCentralWidget(mGraphicsView); diff --git a/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.cpp b/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.cpp deleted file mode 100644 index f0fb37f27b..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_appdefaultmeasurementunits.h" - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_AppDefaultMeasurementUnits::WSI_AppDefaultMeasurementUnits( - const SExpression& node) - : WSI_Base(), - mLengthUnit(LengthUnit::millimeters()), - mLengthUnitTmp(mLengthUnit) { - if (const SExpression* child = - node.tryGetChildByPath("default_length_unit")) { - mLengthUnit = child->getValueOfFirstChild(); - mLengthUnitTmp = mLengthUnit; - } - - // create a QComboBox with all available length units - mLengthUnitComboBox.reset(new QComboBox()); - foreach (const LengthUnit& unit, LengthUnit::getAllUnits()) { - mLengthUnitComboBox->addItem(unit.toStringTr(), unit.getIndex()); - } - updateLengthUnitComboBoxIndex(); - connect( - mLengthUnitComboBox.data(), - static_cast(&QComboBox::currentIndexChanged), - this, &WSI_AppDefaultMeasurementUnits::lengthUnitComboBoxIndexChanged); -} - -WSI_AppDefaultMeasurementUnits::~WSI_AppDefaultMeasurementUnits() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_AppDefaultMeasurementUnits::restoreDefault() noexcept { - mLengthUnitTmp = LengthUnit::millimeters(); - updateLengthUnitComboBoxIndex(); -} - -void WSI_AppDefaultMeasurementUnits::apply() noexcept { - mLengthUnit = mLengthUnitTmp; -} - -void WSI_AppDefaultMeasurementUnits::revert() noexcept { - mLengthUnitTmp = mLengthUnit; - updateLengthUnitComboBoxIndex(); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_AppDefaultMeasurementUnits::lengthUnitComboBoxIndexChanged( - int index) noexcept { - try { - mLengthUnitTmp = LengthUnit::fromIndex(index); - } catch (Exception& e) { - QMessageBox::critical(mLengthUnitComboBox.data(), tr("Error"), e.getMsg()); - } -} - -void WSI_AppDefaultMeasurementUnits::updateLengthUnitComboBoxIndex() noexcept { - mLengthUnitComboBox->setCurrentIndex(mLengthUnitTmp.getIndex()); -} - -void WSI_AppDefaultMeasurementUnits::serialize(SExpression& root) const { - root.appendChild("default_length_unit", mLengthUnit, true); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.h b/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.h deleted file mode 100644 index dc6f66b49c..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_appdefaultmeasurementunits.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_APPDEFAULTMEASUREMENTUNITS_H -#define LIBREPCB_WSI_APPDEFAULTMEASUREMENTUNITS_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -#include - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_AppDefaultMeasurementUnits - ******************************************************************************/ - -/** - * @brief The WSI_AppDefaultMeasurementUnits class represents the application's - * default measurement units (for example the application's default length unit) - */ -class WSI_AppDefaultMeasurementUnits final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_AppDefaultMeasurementUnits() = delete; - WSI_AppDefaultMeasurementUnits(const WSI_AppDefaultMeasurementUnits& other) = - delete; - explicit WSI_AppDefaultMeasurementUnits(const SExpression& node); - ~WSI_AppDefaultMeasurementUnits() noexcept; - - // Getters - const LengthUnit& getLengthUnit() const noexcept { return mLengthUnit; } - - // Getters: Widgets - QString getLengthUnitLabelText() const noexcept { - return tr("Default Length Unit:"); - } - QComboBox* getLengthUnitComboBox() const noexcept { - return mLengthUnitComboBox.data(); - } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_AppDefaultMeasurementUnits& operator =( - const WSI_AppDefaultMeasurementUnits& rhs) = delete; - -private: // Methods - void lengthUnitComboBoxIndexChanged(int index) noexcept; - void updateLengthUnitComboBoxIndex() noexcept; - -private: // Data - /** - * @brief The application's default length unit - * - * Default: millimeters - */ - LengthUnit mLengthUnit; - LengthUnit mLengthUnitTmp; - - // Widgets - QScopedPointer mLengthUnitComboBox; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_APPDEFAULTMEASUREMENTUNITS_H diff --git a/libs/librepcb/workspace/settings/items/wsi_appearance.cpp b/libs/librepcb/workspace/settings/items/wsi_appearance.cpp deleted file mode 100644 index 675d7f456f..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_appearance.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_appearance.h" - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_Appearance::WSI_Appearance(const SExpression& node) - : WSI_Base(), mUseOpenGl(false) { - if (const SExpression* child = node.tryGetChildByPath("use_opengl")) { - mUseOpenGl = child->getValueOfFirstChild(); - } - - // create widgets - mUseOpenGlWidget.reset(new QWidget()); - QGridLayout* openGlLayout = new QGridLayout(mUseOpenGlWidget.data()); - openGlLayout->setContentsMargins(0, 0, 0, 0); - mUseOpenGlCheckBox.reset( - new QCheckBox(tr("Use OpenGL Hardware Acceleration"))); - mUseOpenGlCheckBox->setChecked(mUseOpenGl); - openGlLayout->addWidget(mUseOpenGlCheckBox.data(), openGlLayout->rowCount(), - 0); - openGlLayout->addWidget( - new QLabel(tr("This setting will be applied only to newly " - "opened windows.")), - openGlLayout->rowCount(), 0); -} - -WSI_Appearance::~WSI_Appearance() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_Appearance::restoreDefault() noexcept { - mUseOpenGlCheckBox->setChecked(false); -} - -void WSI_Appearance::apply() noexcept { - mUseOpenGl = mUseOpenGlCheckBox->isChecked(); -} - -void WSI_Appearance::revert() noexcept { - mUseOpenGlCheckBox->setChecked(mUseOpenGl); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_Appearance::serialize(SExpression& root) const { - root.appendChild("use_opengl", mUseOpenGlCheckBox->isChecked(), true); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_appearance.h b/libs/librepcb/workspace/settings/items/wsi_appearance.h deleted file mode 100644 index ccb4875a59..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_appearance.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_APPEARANCE_H -#define LIBREPCB_WSI_APPEARANCE_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_Appearance - ******************************************************************************/ - -/** - * @brief The WSI_Appearance class - */ -class WSI_Appearance final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_Appearance() = delete; - WSI_Appearance(const WSI_Appearance& other) = delete; - explicit WSI_Appearance(const SExpression& node); - ~WSI_Appearance() noexcept; - - // Getters - bool getUseOpenGl() const noexcept { return mUseOpenGlCheckBox->isChecked(); } - - // Getters: Widgets - QString getUseOpenGlLabelText() const noexcept { - return tr("Rendering Method:"); - } - QWidget* getUseOpenGlWidget() const noexcept { - return mUseOpenGlWidget.data(); - } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_Appearance& operator=(const WSI_Appearance& rhs) = delete; - -private: // Data - bool mUseOpenGl; - - // Widgets - QScopedPointer mUseOpenGlWidget; - QScopedPointer mUseOpenGlCheckBox; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_APPEARANCE_H diff --git a/libs/librepcb/workspace/settings/items/wsi_applocale.cpp b/libs/librepcb/workspace/settings/items/wsi_applocale.cpp deleted file mode 100644 index dad73f6ad9..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_applocale.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_applocale.h" - -#include - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_AppLocale::WSI_AppLocale(const SExpression& node) - : WSI_Base(), mAppLocale(), mAppLocaleTmp(mAppLocale) { - if (const SExpression* child = node.tryGetChildByPath("application_locale")) { - mAppLocale = child->getValueOfFirstChild(); - mAppLocaleTmp = mAppLocale; - } - - // create a QComboBox with all available languages - mComboBox.reset(new QComboBox()); - mComboBox->addItem(tr("System Language"), QString("")); - QDir translations(qApp->getResourcesFilePath("i18n").toStr()); - foreach (QString filename, translations.entryList(QDir::Files, QDir::Name)) { - filename.remove("librepcb_"); - QFileInfo fileInfo(filename); - if (fileInfo.suffix() == "qm") { - QString code = fileInfo.baseName(); - QLocale loc(code); - QString str = loc.nativeLanguageName(); - if (str.isEmpty()) { - str = code; // fallback if language code is not recognized - } - if (!loc.nativeCountryName().isEmpty()) { - str += " (" % loc.nativeCountryName() % ")"; - } - mComboBox->addItem(str, code); - } - } - updateComboBoxIndex(); - connect( - mComboBox.data(), - static_cast(&QComboBox::currentIndexChanged), - this, &WSI_AppLocale::comboBoxIndexChanged); - - // create a QWidget - mWidget.reset(new QWidget()); - QVBoxLayout* layout = new QVBoxLayout(mWidget.data()); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(mComboBox.data()); - layout->addWidget(new QLabel( - tr("Changing the language needs to restart the application."))); -} - -WSI_AppLocale::~WSI_AppLocale() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_AppLocale::restoreDefault() noexcept { - mAppLocaleTmp = QString(""); - updateComboBoxIndex(); -} - -void WSI_AppLocale::apply() noexcept { - mAppLocale = mAppLocaleTmp; -} - -void WSI_AppLocale::revert() noexcept { - mAppLocaleTmp = mAppLocale; - updateComboBoxIndex(); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_AppLocale::comboBoxIndexChanged(int index) noexcept { - mAppLocaleTmp = mComboBox->itemData(index).toString(); -} - -void WSI_AppLocale::updateComboBoxIndex() noexcept { - int index = mComboBox->findData(mAppLocaleTmp); - mComboBox->setCurrentIndex(index > 0 ? index : 0); - - if ((!mAppLocaleTmp.isEmpty()) && (index < 0)) { - qWarning() << "could not find the language:" << mAppLocaleTmp; - } -} - -void WSI_AppLocale::serialize(SExpression& root) const { - root.appendChild("application_locale", mAppLocale, true); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_applocale.h b/libs/librepcb/workspace/settings/items/wsi_applocale.h deleted file mode 100644 index 7120ea300e..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_applocale.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_APPLOCALE_H -#define LIBREPCB_WSI_APPLOCALE_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_AppLocale - ******************************************************************************/ - -/** - * @brief The WSI_AppLocale class represents the application's locale settings - * (for translation and localization) - */ -class WSI_AppLocale final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_AppLocale() = delete; - WSI_AppLocale(const WSI_AppLocale& other) = delete; - explicit WSI_AppLocale(const SExpression& node); - ~WSI_AppLocale() noexcept; - - // Getters - const QString& getAppLocaleName() const noexcept { return mAppLocale; } - - // Getters: Widgets - QString getLabelText() const noexcept { return tr("Application Language:"); } - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_AppLocale& operator=(const WSI_AppLocale& rhs) = delete; - -private: // Methods - void comboBoxIndexChanged(int index) noexcept; - void updateComboBoxIndex() noexcept; - -private: // Data - /** - * @brief The locale name - * - * Examples: - * - QString("de_CH") for German/Switzerland - * - QString("") or QString() means "use system locale" - * - * Default: QString() - */ - QString mAppLocale; - QString mAppLocaleTmp; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mComboBox; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_APPLOCALE_H diff --git a/libs/librepcb/workspace/settings/items/wsi_debugtools.cpp b/libs/librepcb/workspace/settings/items/wsi_debugtools.cpp deleted file mode 100644 index ec10cf3565..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_debugtools.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_debugtools.h" - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_DebugTools::WSI_DebugTools(const SExpression& node) : WSI_Base() { - Q_UNUSED(node); - - // create a QWidget - mWidget.reset(new QWidget()); - QGridLayout* layout = new QGridLayout(mWidget.data()); -#ifndef QT_DEBUG - layout->addWidget( - new QLabel( - tr("Warning: Some of these settings may only work in DEBUG mode!")), - 0, 0); -#endif - - // stretch the last row - layout->setRowStretch(layout->rowCount(), 1); -} - -WSI_DebugTools::~WSI_DebugTools() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_DebugTools::restoreDefault() noexcept { -} - -void WSI_DebugTools::apply() noexcept { -} - -void WSI_DebugTools::revert() noexcept { -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_DebugTools::serialize(SExpression& root) const { - Q_UNUSED(root); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_debugtools.h b/libs/librepcb/workspace/settings/items/wsi_debugtools.h deleted file mode 100644 index d0d3839da7..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_debugtools.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_DEBUGTOOLS_H -#define LIBREPCB_WSI_DEBUGTOOLS_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_DebugTools - ******************************************************************************/ - -/** - * @brief The WSI_DebugTools class contains some tools/settings which are useful - * for debugging - */ -class WSI_DebugTools final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_DebugTools() = delete; - WSI_DebugTools(const WSI_DebugTools& other) = delete; - explicit WSI_DebugTools(const SExpression& node); - ~WSI_DebugTools() noexcept; - - // Getters: Widgets - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_DebugTools& operator=(const WSI_DebugTools& rhs) = delete; - -private: // Data - // Widgets - QScopedPointer mWidget; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_DEBUGTOOLS_H diff --git a/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.cpp b/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.cpp deleted file mode 100644 index 99e9a517ee..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_librarylocaleorder.h" - -#include -#include - -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_LibraryLocaleOrder::WSI_LibraryLocaleOrder(const SExpression& node) - : WSI_Base() { - if (const SExpression* child = - node.tryGetChildByPath("library_locale_order")) { - foreach (const SExpression& childchild, child->getChildren()) { - mList.append(QLocale(childchild.getValueOfFirstChild()) - .name()); // can throw - } - } else { - foreach (const QString& localeStr, QLocale::system().uiLanguages()) { - QLocale locale(localeStr); - if ((!locale.name().isEmpty()) && (!mList.contains(locale.name()))) { - mList.append(locale.name()); - } - } - } - mList.removeDuplicates(); - mList.removeAll(""); - mListTmp = mList; - - // create the QListWidget - mListWidget.reset(new QListWidget()); - updateListWidgetItems(); - - // create a QComboBox with all available languages - mComboBox.reset(new QComboBox()); - QList allLocales = QLocale::matchingLocales( - QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); - std::sort(allLocales.begin(), allLocales.end(), - [](const QLocale& l1, const QLocale& l2) { - return l1.name() < l2.name(); - }); - foreach (const QLocale& locale, allLocales) { - QString str = QString("[%1] %2 (%3)") - .arg(locale.name(), locale.nativeLanguageName(), - locale.nativeCountryName()); - if (mComboBox->findData(locale.name()) < 0) { - mComboBox->addItem(str, locale.name()); - } - } - mComboBox->setCurrentIndex(mComboBox->findData(QLocale().name())); - - // create all buttons - mBtnUp.reset(new QToolButton()); - mBtnDown.reset(new QToolButton()); - mBtnAdd.reset(new QToolButton()); - mBtnRemove.reset(new QToolButton()); - mBtnUp->setArrowType(Qt::UpArrow); - mBtnDown->setArrowType(Qt::DownArrow); - mBtnAdd->setIcon(QIcon(":/img/actions/plus_2.png")); - mBtnRemove->setIcon(QIcon(":/img/actions/minus.png")); - connect(mBtnUp.data(), &QToolButton::clicked, this, - &WSI_LibraryLocaleOrder::btnUpClicked); - connect(mBtnDown.data(), &QToolButton::clicked, this, - &WSI_LibraryLocaleOrder::btnDownClicked); - connect(mBtnAdd.data(), &QToolButton::clicked, this, - &WSI_LibraryLocaleOrder::btnAddClicked); - connect(mBtnRemove.data(), &QToolButton::clicked, this, - &WSI_LibraryLocaleOrder::btnRemoveClicked); - - // create the QWidget - mWidget.reset(new QWidget()); - QVBoxLayout* outerLayout = new QVBoxLayout(mWidget.data()); - outerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addWidget(mListWidget.data()); - QHBoxLayout* innerLayout = new QHBoxLayout(); - innerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addLayout(innerLayout); - innerLayout->addWidget(mComboBox.data()); - innerLayout->addWidget(mBtnAdd.data()); - innerLayout->addWidget(mBtnRemove.data()); - innerLayout->addWidget(mBtnUp.data()); - innerLayout->addWidget(mBtnDown.data()); -} - -WSI_LibraryLocaleOrder::~WSI_LibraryLocaleOrder() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_LibraryLocaleOrder::restoreDefault() noexcept { - mListTmp.clear(); - foreach (const QString& localeStr, QLocale::system().uiLanguages()) { - QLocale locale(localeStr); - if ((!locale.name().isEmpty()) && (!mListTmp.contains(locale.name()))) { - mListTmp.append(locale.name()); - } - } - updateListWidgetItems(); -} - -void WSI_LibraryLocaleOrder::apply() noexcept { - mList = mListTmp; -} - -void WSI_LibraryLocaleOrder::revert() noexcept { - mListTmp = mList; - updateListWidgetItems(); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_LibraryLocaleOrder::btnUpClicked() noexcept { - int row = mListWidget->currentRow(); - if (row > 0) { - mListTmp.move(row, row - 1); - mListWidget->insertItem(row - 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row - 1); - } -} - -void WSI_LibraryLocaleOrder::btnDownClicked() noexcept { - int row = mListWidget->currentRow(); - if ((row >= 0) && (row < mListWidget->count() - 1)) { - mListTmp.move(row, row + 1); - mListWidget->insertItem(row + 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row + 1); - } -} - -void WSI_LibraryLocaleOrder::btnAddClicked() noexcept { - if (mComboBox->currentIndex() >= 0) { - QString locale = mComboBox->currentData().toString(); - if (!mListTmp.contains(locale)) { - mListTmp.append(locale); - updateListWidgetItems(); - } - } -} - -void WSI_LibraryLocaleOrder::btnRemoveClicked() noexcept { - if (mListWidget->currentRow() >= 0) { - mListTmp.removeAt(mListWidget->currentRow()); - delete mListWidget->item(mListWidget->currentRow()); - } -} - -void WSI_LibraryLocaleOrder::updateListWidgetItems() noexcept { - mListWidget->clear(); - foreach (const QString& localeStr, mListTmp) { - QLocale locale(localeStr); - QString str = QString("[%1] %2 (%3)") - .arg(localeStr, locale.nativeLanguageName(), - locale.nativeCountryName()); - QListWidgetItem* item = new QListWidgetItem(str, mListWidget.data()); - item->setData(Qt::UserRole, localeStr); - } -} - -void WSI_LibraryLocaleOrder::serialize(SExpression& root) const { - SExpression& child = root.appendList("library_locale_order", true); - foreach (const QString& locale, mList) { - child.appendChild("locale", locale, true); - } -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.h b/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.h deleted file mode 100644 index ecf04e8ee7..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_librarylocaleorder.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_LIBRARYLOCALEORDER_H -#define LIBREPCB_WSI_LIBRARYLOCALEORDER_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_LibraryLocaleOrder - ******************************************************************************/ - -/** - * @brief The WSI_LibraryLocaleOrder class contains a list of locales which - * should be used for all (translatable) strings in library elements (in the - * specified order) - */ -class WSI_LibraryLocaleOrder final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_LibraryLocaleOrder() = delete; - WSI_LibraryLocaleOrder(const WSI_LibraryLocaleOrder& other) = delete; - explicit WSI_LibraryLocaleOrder(const SExpression& node); - ~WSI_LibraryLocaleOrder() noexcept; - - // Getters - const QStringList& getLocaleOrder() const noexcept { return mList; } - - // Getters: Widgets - QString getLabelText() const noexcept { - return tr("Preferred Languages:\n(Highest priority at top)"); - } - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_LibraryLocaleOrder& operator=(const WSI_LibraryLocaleOrder& rhs) = delete; - -private: // Methods - void btnUpClicked() noexcept; - void btnDownClicked() noexcept; - void btnAddClicked() noexcept; - void btnRemoveClicked() noexcept; - void updateListWidgetItems() noexcept; - -private: // Data - /** - * @brief The list of locales (like "de_CH") in the right order - * - * The locale which should be used first is at index 0 of the list. If no - * translation strings are found for all locales in this list, the fallback - * locale "en_US" will be used automatically, so the list do not have to - * contain "en_US". An empty list is also valid, then the fallback locale - * "en_US" will be used. - */ - QStringList mList; - QStringList mListTmp; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mListWidget; - QScopedPointer mComboBox; - QScopedPointer mBtnUp; - QScopedPointer mBtnDown; - QScopedPointer mBtnAdd; - QScopedPointer mBtnRemove; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_LIBRARYLOCALEORDER_H diff --git a/libs/librepcb/workspace/settings/items/wsi_librarynormorder.cpp b/libs/librepcb/workspace/settings/items/wsi_librarynormorder.cpp deleted file mode 100644 index 498b40a74d..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_librarynormorder.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_librarynormorder.h" - -#include - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_LibraryNormOrder::WSI_LibraryNormOrder(const SExpression& node) - : WSI_Base() { - if (const SExpression* child = node.tryGetChildByPath("library_norm_order")) { - foreach (const SExpression& childchild, child->getChildren()) { - mList.append(childchild.getValueOfFirstChild()); - } - } - mList.removeDuplicates(); - mList.removeAll(""); - mListTmp = mList; - - // create the QListWidget - mListWidget.reset(new QListWidget()); - updateListWidgetItems(); - - // create a QComboBox with all available norms - mComboBox.reset(new QComboBox()); - mComboBox->setEditable(true); - mComboBox->addItems(getAvailableNorms()); - mComboBox->clearEditText(); - - // create all buttons - mBtnUp.reset(new QToolButton()); - mBtnDown.reset(new QToolButton()); - mBtnAdd.reset(new QToolButton()); - mBtnRemove.reset(new QToolButton()); - mBtnUp->setArrowType(Qt::UpArrow); - mBtnDown->setArrowType(Qt::DownArrow); - mBtnAdd->setIcon(QIcon(":/img/actions/plus_2.png")); - mBtnRemove->setIcon(QIcon(":/img/actions/minus.png")); - connect(mBtnUp.data(), &QToolButton::clicked, this, - &WSI_LibraryNormOrder::btnUpClicked); - connect(mBtnDown.data(), &QToolButton::clicked, this, - &WSI_LibraryNormOrder::btnDownClicked); - connect(mBtnAdd.data(), &QToolButton::clicked, this, - &WSI_LibraryNormOrder::btnAddClicked); - connect(mBtnRemove.data(), &QToolButton::clicked, this, - &WSI_LibraryNormOrder::btnRemoveClicked); - - // create the QWidget - mWidget.reset(new QWidget()); - QVBoxLayout* outerLayout = new QVBoxLayout(mWidget.data()); - outerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addWidget(mListWidget.data()); - QHBoxLayout* innerLayout = new QHBoxLayout(); - innerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addLayout(innerLayout); - innerLayout->addWidget(mComboBox.data()); - innerLayout->addWidget(mBtnAdd.data()); - innerLayout->addWidget(mBtnRemove.data()); - innerLayout->addWidget(mBtnUp.data()); - innerLayout->addWidget(mBtnDown.data()); -} - -WSI_LibraryNormOrder::~WSI_LibraryNormOrder() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_LibraryNormOrder::restoreDefault() noexcept { - mListTmp.clear(); - updateListWidgetItems(); -} - -void WSI_LibraryNormOrder::apply() noexcept { - mList = mListTmp; -} - -void WSI_LibraryNormOrder::revert() noexcept { - mListTmp = mList; - updateListWidgetItems(); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_LibraryNormOrder::btnUpClicked() noexcept { - int row = mListWidget->currentRow(); - if (row > 0) { - mListTmp.move(row, row - 1); - mListWidget->insertItem(row - 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row - 1); - } -} - -void WSI_LibraryNormOrder::btnDownClicked() noexcept { - int row = mListWidget->currentRow(); - if ((row >= 0) && (row < mListWidget->count() - 1)) { - mListTmp.move(row, row + 1); - mListWidget->insertItem(row + 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row + 1); - } -} - -void WSI_LibraryNormOrder::btnAddClicked() noexcept { - if (!mComboBox->currentText().isEmpty()) { - if (!mListTmp.contains(mComboBox->currentText())) { - mListTmp.append(mComboBox->currentText()); - updateListWidgetItems(); - } - } -} - -void WSI_LibraryNormOrder::btnRemoveClicked() noexcept { - if (mListWidget->currentRow() >= 0) { - mListTmp.removeAt(mListWidget->currentRow()); - delete mListWidget->item(mListWidget->currentRow()); - } -} - -void WSI_LibraryNormOrder::updateListWidgetItems() noexcept { - mListWidget->clear(); - mListWidget->addItems(mListTmp); -} - -void WSI_LibraryNormOrder::serialize(SExpression& root) const { - SExpression& child = root.appendList("library_norm_order", true); - foreach (const QString& norm, mList) { - child.appendChild("norm", norm, true); - } -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_librarynormorder.h b/libs/librepcb/workspace/settings/items/wsi_librarynormorder.h deleted file mode 100644 index 2b68c06ba6..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_librarynormorder.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_LIBRARYNORMORDER_H -#define LIBREPCB_WSI_LIBRARYNORMORDER_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_LibraryNormOrder - ******************************************************************************/ - -/** - * @brief The WSI_LibraryNormOrder class contains a list of norms which should - * be used for all library elements (in the specified order) - */ -class WSI_LibraryNormOrder final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_LibraryNormOrder() = delete; - WSI_LibraryNormOrder(const WSI_LibraryNormOrder& other) = delete; - explicit WSI_LibraryNormOrder(const SExpression& node); - ~WSI_LibraryNormOrder() noexcept; - - // Getters - const QStringList& getNormOrder() const noexcept { return mList; } - - // Getters: Widgets - QString getLabelText() const noexcept { - return tr("Preferred Norms:\n(Highest priority at top)"); - } - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_LibraryNormOrder& operator=(const WSI_LibraryNormOrder& rhs) = delete; - -private: // Methods - void btnUpClicked() noexcept; - void btnDownClicked() noexcept; - void btnAddClicked() noexcept; - void btnRemoveClicked() noexcept; - void updateListWidgetItems() noexcept; - -private: // Data - /** - * @brief The list of norms (like "DIN EN 81346") in the right order - * - * The norm which should be used first is at index 0 of the list. - */ - QStringList mList; - QStringList mListTmp; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mListWidget; - QScopedPointer mComboBox; - QScopedPointer mBtnUp; - QScopedPointer mBtnDown; - QScopedPointer mBtnAdd; - QScopedPointer mBtnRemove; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_LIBRARYNORMORDER_H diff --git a/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.cpp b/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.cpp deleted file mode 100644 index de1c60ffd0..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_projectautosaveinterval.h" - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_ProjectAutosaveInterval::WSI_ProjectAutosaveInterval( - const SExpression& node) - : WSI_Base(), mInterval(600), mIntervalTmp(mInterval) { - if (const SExpression* child = - node.tryGetChildByPath("project_autosave_interval")) { - mInterval = child->getValueOfFirstChild(); - } - - if (mInterval % 60 != 0) { - mInterval += 60 - (mInterval % 60); // round up to the next full minute - } - mIntervalTmp = mInterval; - - // create a spinbox - mSpinBox.reset(new QSpinBox()); - mSpinBox->setMinimum(0); - mSpinBox->setMaximum(60); - mSpinBox->setValue(mInterval / 60); - mSpinBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(mSpinBox.data(), - static_cast(&QSpinBox::valueChanged), this, - &WSI_ProjectAutosaveInterval::spinBoxValueChanged); - - // create a QWidget - mWidget.reset(new QWidget()); - QHBoxLayout* layout = new QHBoxLayout(mWidget.data()); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(mSpinBox.data()); - layout->addWidget(new QLabel(tr("Minutes (0 = disable autosave)"))); -} - -WSI_ProjectAutosaveInterval::~WSI_ProjectAutosaveInterval() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_ProjectAutosaveInterval::restoreDefault() noexcept { - mIntervalTmp = 600; - mSpinBox->setValue(mIntervalTmp / 60); -} - -void WSI_ProjectAutosaveInterval::apply() noexcept { - mInterval = mIntervalTmp; -} - -void WSI_ProjectAutosaveInterval::revert() noexcept { - mIntervalTmp = mInterval; - mSpinBox->setValue(mIntervalTmp / 60); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_ProjectAutosaveInterval::spinBoxValueChanged(int value) noexcept { - mIntervalTmp = value * 60; -} - -void WSI_ProjectAutosaveInterval::serialize(SExpression& root) const { - root.appendChild("project_autosave_interval", mInterval, true); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.h b/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.h deleted file mode 100644 index 4dac36d37e..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_projectautosaveinterval.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WSI_PROJECTAUTOSAVEINTERVAL_H -#define LIBREPCB_WSI_PROJECTAUTOSAVEINTERVAL_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_ProjectAutosaveInterval - ******************************************************************************/ - -/** - * @brief The WSI_ProjectAutosaveInterval class represents the project autosave - * interval setting - * - * This setting is used by the class ::librepcb::project::Project for the - * autosave mechanism. A value of zero means that the autosave mechanism is - * disabled! A value greater than zero defines the time interval in seconds. - */ -class WSI_ProjectAutosaveInterval final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_ProjectAutosaveInterval() = delete; - WSI_ProjectAutosaveInterval(const WSI_ProjectAutosaveInterval& other) = - delete; - explicit WSI_ProjectAutosaveInterval(const SExpression& node); - ~WSI_ProjectAutosaveInterval() noexcept; - - // Getters - unsigned int getInterval() const noexcept { return mInterval; } - - // Getters: Widgets - QString getLabelText() const noexcept { - return tr("Project Autosave Interval:"); - } - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_ProjectAutosaveInterval& operator =( - const WSI_ProjectAutosaveInterval& rhs) = delete; - -private: // Methods - void spinBoxValueChanged(int value) noexcept; - -private: // Data - // General Attributes - - /** - * @brief the autosave interval [seconds] (0 = autosave disabled) - * - * Default: 600 seconds - */ - uint mInterval; - uint mIntervalTmp; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mSpinBox; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WSI_PROJECTAUTOSAVEINTERVAL_H diff --git a/libs/librepcb/workspace/settings/items/wsi_repositories.cpp b/libs/librepcb/workspace/settings/items/wsi_repositories.cpp deleted file mode 100644 index d8fbfbcfd8..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_repositories.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_repositories.h" - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_Repositories::WSI_Repositories(const SExpression& node) : WSI_Base() { - if (const SExpression* child = node.tryGetChildByPath("repositories")) { - foreach (const SExpression& repo, child->getChildren()) { - mUrls.append(repo.getChildByIndex(0).getValue()); // can throw - } - } else { - mUrls.append(QUrl("https://api.librepcb.org")); - } - mUrlsTmp = mUrls; - - // create the QListWidget - mListWidget.reset(new QListWidget()); - updateListWidgetItems(); - - // create a QLineEdit - mLineEdit.reset(new QLineEdit()); - mLineEdit->setMaxLength(255); - - // create all buttons - mBtnUp.reset(new QToolButton()); - mBtnDown.reset(new QToolButton()); - mBtnAdd.reset(new QToolButton()); - mBtnRemove.reset(new QToolButton()); - mBtnUp->setArrowType(Qt::UpArrow); - mBtnDown->setArrowType(Qt::DownArrow); - mBtnAdd->setIcon(QIcon(":/img/actions/plus_2.png")); - mBtnRemove->setIcon(QIcon(":/img/actions/minus.png")); - connect(mBtnUp.data(), &QToolButton::clicked, this, - &WSI_Repositories::btnUpClicked); - connect(mBtnDown.data(), &QToolButton::clicked, this, - &WSI_Repositories::btnDownClicked); - connect(mBtnAdd.data(), &QToolButton::clicked, this, - &WSI_Repositories::btnAddClicked); - connect(mBtnRemove.data(), &QToolButton::clicked, this, - &WSI_Repositories::btnRemoveClicked); - - // create the QWidget - mWidget.reset(new QWidget()); - QVBoxLayout* outerLayout = new QVBoxLayout(mWidget.data()); - outerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addWidget(mListWidget.data()); - QHBoxLayout* innerLayout = new QHBoxLayout(); - innerLayout->setContentsMargins(0, 0, 0, 0); - outerLayout->addLayout(innerLayout); - innerLayout->addWidget(mLineEdit.data()); - innerLayout->addWidget(mBtnAdd.data()); - innerLayout->addWidget(mBtnRemove.data()); - innerLayout->addWidget(mBtnUp.data()); - innerLayout->addWidget(mBtnDown.data()); -} - -WSI_Repositories::~WSI_Repositories() noexcept { -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_Repositories::restoreDefault() noexcept { - mUrlsTmp.clear(); - mUrlsTmp.append(QUrl("https://api.librepcb.org")); - updateListWidgetItems(); -} - -void WSI_Repositories::apply() noexcept { - mUrls = mUrlsTmp; -} - -void WSI_Repositories::revert() noexcept { - mUrlsTmp = mUrls; - updateListWidgetItems(); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_Repositories::btnUpClicked() noexcept { - int row = mListWidget->currentRow(); - if (row > 0) { - mUrlsTmp.move(row, row - 1); - mListWidget->insertItem(row - 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row - 1); - } -} - -void WSI_Repositories::btnDownClicked() noexcept { - int row = mListWidget->currentRow(); - if ((row >= 0) && (row < mListWidget->count() - 1)) { - mUrlsTmp.move(row, row + 1); - mListWidget->insertItem(row + 1, mListWidget->takeItem(row)); - mListWidget->setCurrentRow(row + 1); - } -} - -void WSI_Repositories::btnAddClicked() noexcept { - QUrl url = QUrl::fromUserInput(mLineEdit->text().trimmed()); - if (url.isValid()) { - mUrlsTmp.append(url); - updateListWidgetItems(); - mLineEdit->setText(""); - } else { - QMessageBox::critical(mWidget.data(), tr("Error"), - tr("The URL is not valid.")); - } -} - -void WSI_Repositories::btnRemoveClicked() noexcept { - if (mListWidget->currentRow() >= 0) { - mUrlsTmp.removeAt(mListWidget->currentRow()); - delete mListWidget->item(mListWidget->currentRow()); - } -} - -void WSI_Repositories::updateListWidgetItems() noexcept { - mListWidget->clear(); - foreach (const QUrl& url, mUrlsTmp) { - QListWidgetItem* item = - new QListWidgetItem(url.toDisplayString(), mListWidget.data()); - item->setData(Qt::UserRole, url); - } -} - -void WSI_Repositories::serialize(SExpression& root) const { - SExpression& child = root.appendList("repositories", true); - foreach (const QUrl& url, mUrls) { - child.appendChild("repository", url, true); - } -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_repositories.h b/libs/librepcb/workspace/settings/items/wsi_repositories.h deleted file mode 100644 index fb24b97331..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_repositories.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WORKSPACE_WSI_REPOSITORIES_H -#define LIBREPCB_WORKSPACE_WSI_REPOSITORIES_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_Repositories - ******************************************************************************/ - -/** - * @brief The WSI_Repositories class contains a list of used repositories - */ -class WSI_Repositories final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_Repositories() = delete; - WSI_Repositories(const WSI_Repositories& other) = delete; - explicit WSI_Repositories(const SExpression& node); - ~WSI_Repositories() noexcept; - - // Getters - const QList& getUrls() const noexcept { return mUrls; } - - // Getters: Widgets - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_Repositories& operator=(const WSI_Repositories& rhs) = delete; - -private: // Methods - void btnUpClicked() noexcept; - void btnDownClicked() noexcept; - void btnAddClicked() noexcept; - void btnRemoveClicked() noexcept; - void updateListWidgetItems() noexcept; - -private: // Data - /** - * @brief The list of repository URLs in the right order - * - * The repository with the highest priority is at index 0 of the list. In case - * of version conflicts, the repository with the higher priority will be used. - */ - QList mUrls; - QList mUrlsTmp; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mListWidget; - QScopedPointer mLineEdit; - QScopedPointer mBtnUp; - QScopedPointer mBtnDown; - QScopedPointer mBtnAdd; - QScopedPointer mBtnRemove; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WORKSPACE_WSI_REPOSITORIES_H diff --git a/libs/librepcb/workspace/settings/items/wsi_user.cpp b/libs/librepcb/workspace/settings/items/wsi_user.cpp deleted file mode 100644 index befa6b8a11..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_user.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_user.h" - -#include - -#include -#include - -/******************************************************************************* - * Namespace - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Constructors / Destructor - ******************************************************************************/ - -WSI_User::WSI_User(const SExpression& node) : WSI_Base() { - if (const SExpression* child = node.tryGetChildByPath("user")) { - mName = child->getValueOfFirstChild(); - } else { - // Fallback to system's username if no user name defined. This should - // actually only happen once when upgrading older workspace settings. - mName = SystemInfo::getFullUsername(); - } - - // create widget - mWidget.reset(new QWidget()); - QVBoxLayout* layout = new QVBoxLayout(mWidget.data()); - layout->setContentsMargins(0, 0, 0, 0); - mNameEdit.reset(new QLineEdit(mName)); - mNameEdit->setMaxLength(100); - mNameEdit->setPlaceholderText(tr("e.g. \"John Doe\"")); - layout->addWidget(mNameEdit.data()); - layout->addWidget( - new QLabel(tr("This name will be used as author when creating new " - "projects or libraries."))); -} - -WSI_User::~WSI_User() noexcept { -} - -/******************************************************************************* - * Direct Access - ******************************************************************************/ - -void WSI_User::setName(const QString& name) noexcept { - mName = name; - mNameEdit->setText(name); -} - -/******************************************************************************* - * General Methods - ******************************************************************************/ - -void WSI_User::restoreDefault() noexcept { - mNameEdit->setText(SystemInfo::getFullUsername()); -} - -void WSI_User::apply() noexcept { - mName = mNameEdit->text(); -} - -void WSI_User::revert() noexcept { - mNameEdit->setText(mName); -} - -/******************************************************************************* - * Private Methods - ******************************************************************************/ - -void WSI_User::serialize(SExpression& root) const { - root.appendChild("user", mName, true); -} - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb diff --git a/libs/librepcb/workspace/settings/items/wsi_user.h b/libs/librepcb/workspace/settings/items/wsi_user.h deleted file mode 100644 index 6f6788a0f7..0000000000 --- a/libs/librepcb/workspace/settings/items/wsi_user.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * LibrePCB - Professional EDA for everyone! - * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. - * https://librepcb.org/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIBREPCB_WORKSPACE_WSI_USER_H -#define LIBREPCB_WORKSPACE_WSI_USER_H - -/******************************************************************************* - * Includes - ******************************************************************************/ -#include "wsi_base.h" - -/******************************************************************************* - * Namespace / Forward Declarations - ******************************************************************************/ -namespace librepcb { -namespace workspace { - -/******************************************************************************* - * Class WSI_User - ******************************************************************************/ - -/** - * @brief The WSI_User class contains the default author used for projects and - * libraries - */ -class WSI_User final : public WSI_Base { - Q_OBJECT - -public: - // Constructors / Destructor - WSI_User() = delete; - WSI_User(const WSI_User& other) = delete; - explicit WSI_User(const SExpression& node); - ~WSI_User() noexcept; - - // Direct Access - void setName(const QString& name) noexcept; - const QString& getName() const noexcept { return mName; } - - // Getters: Widgets - QString getLabelText() const noexcept { return tr("User Name:"); } - QWidget* getWidget() const noexcept { return mWidget.data(); } - - // General Methods - void restoreDefault() noexcept override; - void apply() noexcept override; - void revert() noexcept override; - - /// @copydoc librepcb::SerializableObject::serialize() - void serialize(SExpression& root) const override; - - // Operator Overloadings - WSI_User& operator=(const WSI_User& rhs) = delete; - -private: // Data - QString mName; - - // Widgets - QScopedPointer mWidget; - QScopedPointer mNameEdit; -}; - -/******************************************************************************* - * End of File - ******************************************************************************/ - -} // namespace workspace -} // namespace librepcb - -#endif // LIBREPCB_WORKSPACE_WSI_USER_H diff --git a/libs/librepcb/workspace/settings/workspacesettings.cpp b/libs/librepcb/workspace/settings/workspacesettings.cpp index 5a23a2c5f6..0800526526 100644 --- a/libs/librepcb/workspace/settings/workspacesettings.cpp +++ b/libs/librepcb/workspace/settings/workspacesettings.cpp @@ -22,10 +22,6 @@ ******************************************************************************/ #include "workspacesettings.h" -#include "../workspace.h" -#include "workspacesettingsdialog.h" - -#include #include #include @@ -41,85 +37,68 @@ namespace workspace { * Constructors / Destructor ******************************************************************************/ -WorkspaceSettings::WorkspaceSettings(const Workspace& workspace) - : QObject(nullptr), - mFilePath(workspace.getMetadataPath().getPathTo("settings.lp")) { - qDebug("Load workspace settings..."); - +WorkspaceSettings::WorkspaceSettings(const FilePath& fp, QObject* parent) + : QObject(parent), + mFilePath(fp), + // Initialize settings items. Their constructor will register them as + // child objects of this object, this way we will access them later. + userName("user", "", this), + applicationLocale("application_locale", "", this), + defaultLengthUnit("default_length_unit", LengthUnit::millimeters(), this), + projectAutosaveIntervalSeconds("project_autosave_interval", 600U, this), + useOpenGl("use_opengl", false, this), + libraryLocaleOrder("library_locale_order", "locale", QStringList(), this), + libraryNormOrder("library_norm_order", "norm", QStringList(), this), + repositoryUrls("repositories", "repository", + QList{QUrl("https://api.librepcb.org")}, this) { // load settings if the settings file exists - SExpression root; if (mFilePath.isExistingFile()) { - root = SExpression::parse(FileUtils::readFile(mFilePath), mFilePath); + qDebug("Load workspace settings..."); + SExpression root = + SExpression::parse(FileUtils::readFile(mFilePath), mFilePath); + foreach (WorkspaceSettingsItem* item, getAllItems()) { + try { + item->load(root); // can throw + } catch (const Exception& e) { + qCritical() << "Could not load workspace settings item:" << e.getMsg(); + } + } + qDebug("Workspace settings loaded."); } else { qInfo("Workspace settings file not found, default settings will be used."); } - - // load all settings - loadSettingsItem(mUser, root); - loadSettingsItem(mAppLocale, root); - loadSettingsItem(mAppDefMeasUnits, root); - loadSettingsItem(mProjectAutosaveInterval, root); - loadSettingsItem(mAppearance, root); - loadSettingsItem(mLibraryLocaleOrder, root); - loadSettingsItem(mLibraryNormOrder, root); - loadSettingsItem(mRepositories, root); - loadSettingsItem(mDebugTools, root); - - // load the settings dialog - mDialog.reset(new WorkspaceSettingsDialog(*this)); - - qDebug("Workspace settings successfully loaded!"); } WorkspaceSettings::~WorkspaceSettings() noexcept { - mDialog.reset(); // the dialog must be deleted *before* any settings object! - mItems.clear(); } /******************************************************************************* - * General Methods + * Public Methods ******************************************************************************/ void WorkspaceSettings::restoreDefaults() noexcept { - foreach (WSI_Base* item, mItems) { item->restoreDefault(); } -} - -void WorkspaceSettings::applyAll() { - foreach (WSI_Base* item, mItems) { item->apply(); } - - saveToFile(); // can throw -} - -void WorkspaceSettings::revertAll() noexcept { - foreach (WSI_Base* item, mItems) { item->revert(); } + foreach (WorkspaceSettingsItem* item, getAllItems()) { + item->restoreDefault(); + } } -/******************************************************************************* - * Public Slots - ******************************************************************************/ - -void WorkspaceSettings::showSettingsDialog() noexcept { - mDialog->exec(); // this is blocking +void WorkspaceSettings::saveToFile() const { + SExpression doc(serializeToDomElement("librepcb_workspace_settings")); + FileUtils::writeFile(mFilePath, doc.toByteArray()); // can throw } /******************************************************************************* * Private Methods ******************************************************************************/ -template -void WorkspaceSettings::loadSettingsItem(QScopedPointer& member, - SExpression& root) { - member.reset(new T(root)); // can throw - mItems.append(member.data()); -} - -void WorkspaceSettings::saveToFile() const { - SExpression doc(serializeToDomElement("librepcb_workspace_settings")); - FileUtils::writeFile(mFilePath, doc.toByteArray()); // can throw +QList WorkspaceSettings::getAllItems() const noexcept { + return findChildren(); } void WorkspaceSettings::serialize(SExpression& root) const { - foreach (WSI_Base* item, mItems) { item->serialize(root); } + foreach (const WorkspaceSettingsItem* item, getAllItems()) { + item->serialize(root); // can throw + } } /******************************************************************************* diff --git a/libs/librepcb/workspace/settings/workspacesettings.h b/libs/librepcb/workspace/settings/workspacesettings.h index 3e6ff6f7a5..bdf04d9469 100644 --- a/libs/librepcb/workspace/settings/workspacesettings.h +++ b/libs/librepcb/workspace/settings/workspacesettings.h @@ -23,45 +23,37 @@ /******************************************************************************* * Includes ******************************************************************************/ +#include "workspacesettingsitem_genericvalue.h" +#include "workspacesettingsitem_genericvaluelist.h" + #include #include +#include #include -// All Settings Classes -#include "items/wsi_appdefaultmeasurementunits.h" -#include "items/wsi_appearance.h" -#include "items/wsi_applocale.h" -#include "items/wsi_debugtools.h" -#include "items/wsi_librarylocaleorder.h" -#include "items/wsi_librarynormorder.h" -#include "items/wsi_projectautosaveinterval.h" -#include "items/wsi_repositories.h" -#include "items/wsi_user.h" - /******************************************************************************* * Namespace / Forward Declarations ******************************************************************************/ namespace librepcb { namespace workspace { -class Workspace; -class WorkspaceSettingsDialog; - /******************************************************************************* * Class WorkspaceSettings ******************************************************************************/ /** - * @brief The WorkspaceSettings class manages all workspace related settings + * @brief Container for all workspace related settings * * The "settings.lp" file in a workspace is used to store workspace related - * settings. This class is an interface to these settings. A WorkspaceSettings - * object is created in the constructor of the Workspace object. + * settings. This class is an interface to those settings. A + * ::librepcb::workspace::WorkspaceSettings object is created in the + * constructor of the ::librepcb::workspace::Workspace object. + * + * Each settings item is represented by an instance of a + * ::librepcb::workspace::WorkspaceSettingsItem subclass. * - * This class also provides a graphical dialog to show and edit all these - * settings. For this purpose, the WorkspaceSettingsDialog class is used. It can - * be shown by calling the slot #showSettingsDialog(). + * @see ::librepcb::workspace::WorkspaceSettingsItem */ class WorkspaceSettings final : public QObject, public SerializableObject { Q_OBJECT @@ -70,69 +62,115 @@ class WorkspaceSettings final : public QObject, public SerializableObject { // Constructors / Destructor WorkspaceSettings() = delete; WorkspaceSettings(const WorkspaceSettings& other) = delete; - explicit WorkspaceSettings(const Workspace& workspace); + explicit WorkspaceSettings(const FilePath& fp, QObject* parent = nullptr); ~WorkspaceSettings() noexcept; - // Getters: Settings Items - WSI_User& getUser() const noexcept { return *mUser; } - WSI_AppLocale& getAppLocale() const noexcept { return *mAppLocale; } - WSI_AppDefaultMeasurementUnits& getAppDefMeasUnits() const noexcept { - return *mAppDefMeasUnits; - } - WSI_ProjectAutosaveInterval& getProjectAutosaveInterval() const noexcept { - return *mProjectAutosaveInterval; - } - WSI_Appearance& getAppearance() const noexcept { return *mAppearance; } - WSI_LibraryLocaleOrder& getLibLocaleOrder() const noexcept { - return *mLibraryLocaleOrder; - } - WSI_LibraryNormOrder& getLibNormOrder() const noexcept { - return *mLibraryNormOrder; - } - WSI_Repositories& getRepositories() const noexcept { return *mRepositories; } - WSI_DebugTools& getDebugTools() const noexcept { return *mDebugTools; } - - // General Methods + /** + * @brief Reset all settings to their default value + */ void restoreDefaults() noexcept; - void applyAll(); - void revertAll() noexcept; + + /** + * @brief Save all settings to the file + */ + void saveToFile() const; // Operator Overloadings WorkspaceSettings& operator=(const WorkspaceSettings& rhs) = delete; -public slots: - +private: // Methods /** - * @brief Open the workspace settings dialog + * @brief Get all ::librepcb::workspace::WorkspaceSettingsItem objects * - * @note The dialog is application modal, so this method is blocking while the - * dialog is open. This method will not return before the dialog is closed. + * @return List of ::librepcb::workspace::WorkspaceSettingsItem objects */ - void showSettingsDialog() noexcept; + QList getAllItems() const noexcept; -private: // Methods - template - void loadSettingsItem(QScopedPointer& member, SExpression& root); - void saveToFile() const; - /// @copydoc librepcb::SerializableObject::serialize() + /// @copydoc ::librepcb::SerializableObject::serialize() void serialize(SExpression& root) const override; -private: // Data - // General Attributes +private: // Data FilePath mFilePath; ///< path to the "settings.lp" file - QScopedPointer mDialog; ///< the settings dialog - - // Settings Items - QList mItems; ///< contains all settings items - QScopedPointer mUser; - QScopedPointer mAppLocale; - QScopedPointer mAppDefMeasUnits; - QScopedPointer mProjectAutosaveInterval; - QScopedPointer mAppearance; - QScopedPointer mLibraryLocaleOrder; - QScopedPointer mLibraryNormOrder; - QScopedPointer mRepositories; - QScopedPointer mDebugTools; + +public: + // All settings item objects below, in the same order as they are safed in + // the settings file. + // + // Note: Generally we don't make member variables public, but in this case + // it would create a lot of boilerplate to wrap all objects with + // both const- and non-const methods, and it's totally safe to access + // them directly. + + /** + * @brief User name + * + * Used when creating new library elements or projects. + * + * Default: "" (but gets initialized when creating a new workspace) + */ + WorkspaceSettingsItem_GenericValue userName; + + /** + * @brief The application's locale (e.g. "en_US") + * + * An empty string means that the system locale will be used. + * + * Default: "" + */ + WorkspaceSettingsItem_GenericValue applicationLocale; + + /** + * @brief The application's default length unit + * + * Default: millimeters + */ + WorkspaceSettingsItem_GenericValue defaultLengthUnit; + + /** + * @brief Project autosave interval [seconds] (0 = autosave disabled) + * + * Default: 600 + */ + WorkspaceSettingsItem_GenericValue projectAutosaveIntervalSeconds; + + /** + * @brief Use OpenGL hardware acceleration + * + * Default: False + */ + WorkspaceSettingsItem_GenericValue useOpenGl; + + /** + * @brief Preferred library locales (like "de_CH") in the right order + * + * The locale which should be used first is at index 0 of the list. If no + * translation strings are found for all locales in this list, the fallback + * locale "en_US" will be used automatically, so the list do not have to + * contain "en_US". An empty list is also valid, then the fallback locale + * "en_US" will be used. + * + * Default: [] + */ + WorkspaceSettingsItem_GenericValueList libraryLocaleOrder; + + /** + * @brief Preferred library norms (like "DIN EN 81346") in the right order + * + * The norm which should be used first is at index 0 of the list. + * + * Default: [] + */ + WorkspaceSettingsItem_GenericValueList libraryNormOrder; + + /** + * @brief The list of API repository URLs in the right order + * + * The repository with the highest priority is at index 0 of the list. In case + * of version conflicts, the repository with the higher priority will be used. + * + * Default: ["https://api.librepcb.org"] + */ + WorkspaceSettingsItem_GenericValueList> repositoryUrls; }; /******************************************************************************* diff --git a/libs/librepcb/workspace/settings/workspacesettingsdialog.cpp b/libs/librepcb/workspace/settings/workspacesettingsdialog.cpp index c809c06107..f7845b4007 100644 --- a/libs/librepcb/workspace/settings/workspacesettingsdialog.cpp +++ b/libs/librepcb/workspace/settings/workspacesettingsdialog.cpp @@ -26,6 +26,12 @@ #include "ui_workspacesettingsdialog.h" #include "workspacesettings.h" +#include +#include +#include +#include +#include + #include #include @@ -39,145 +45,239 @@ namespace workspace { * Constructors / Destructor ******************************************************************************/ -WorkspaceSettingsDialog::WorkspaceSettingsDialog(WorkspaceSettings& settings) - : QDialog(0), mUi(new Ui::WorkspaceSettingsDialog), mSettings(settings) { +WorkspaceSettingsDialog::WorkspaceSettingsDialog(WorkspaceSettings& settings, + QWidget* parent) + : QDialog(parent), + mSettings(settings), + mLibLocaleOrderModel(new LibraryLocaleOrderModel()), + mLibNormOrderModel(new LibraryNormOrderModel()), + mRepositoryUrlsModel(new RepositoryUrlModel()), + mUi(new Ui::WorkspaceSettingsDialog) { mUi->setupUi(this); - // Add all settings widgets - - // tab: general - mUi->generalLayout->addRow(mSettings.getUser().getLabelText(), - mSettings.getUser().getWidget()); - mUi->generalLayout->addRow(mSettings.getAppLocale().getLabelText(), - mSettings.getAppLocale().getWidget()); - mUi->generalLayout->addRow( - mSettings.getAppDefMeasUnits().getLengthUnitLabelText(), - mSettings.getAppDefMeasUnits().getLengthUnitComboBox()); - mUi->generalLayout->addRow( - mSettings.getProjectAutosaveInterval().getLabelText(), - mSettings.getProjectAutosaveInterval().getWidget()); - - // tab: appearance - mUi->appearanceLayout->addRow( - mSettings.getAppearance().getUseOpenGlLabelText(), - mSettings.getAppearance().getUseOpenGlWidget()); - - // tab: library - mUi->libraryLayout->addRow(mSettings.getLibLocaleOrder().getLabelText(), - mSettings.getLibLocaleOrder().getWidget()); - mUi->libraryLayout->addRow(mSettings.getLibNormOrder().getLabelText(), - mSettings.getLibNormOrder().getWidget()); - - // tab: repositories - mUi->repositoriesLayout->addWidget(mSettings.getRepositories().getWidget()); - - // tab: debug tools -#ifdef QT_DEBUG - mUi->tabWidget->addTab(mSettings.getDebugTools().getWidget(), - tr("Debug Tools")); -#endif - - // load the window geometry + // Initialize library locale order + { + QList locales = QLocale::matchingLocales( + QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + QStringList localesStr; + foreach (const QLocale& l, locales) { localesStr.append(l.name()); } + mLibLocaleOrderModel->setPlaceholderText(tr("Click here a add a locale")); + mLibLocaleOrderModel->setDefaultValue(QString("")); + mLibLocaleOrderModel->setChoices(localesStr); + mUi->tblLibLocaleOrder->setShowMoveButtons(true); + mUi->tblLibLocaleOrder->setModel(mLibLocaleOrderModel.data()); + mUi->tblLibLocaleOrder->setItemDelegateForColumn( + LibraryLocaleOrderModel::COLUMN_TEXT, + new ComboBoxDelegate(false, this)); + mUi->tblLibLocaleOrder->horizontalHeader()->setSectionResizeMode( + LibraryLocaleOrderModel::COLUMN_TEXT, QHeaderView::Stretch); + mUi->tblLibLocaleOrder->horizontalHeader()->setSectionResizeMode( + LibraryLocaleOrderModel::COLUMN_ACTIONS, QHeaderView::ResizeToContents); + connect(mUi->tblLibLocaleOrder, &EditableTableWidget::btnAddClicked, + mLibLocaleOrderModel.data(), &LibraryLocaleOrderModel::addItem); + connect(mUi->tblLibLocaleOrder, &EditableTableWidget::btnRemoveClicked, + mLibLocaleOrderModel.data(), &LibraryLocaleOrderModel::removeItem); + connect(mUi->tblLibLocaleOrder, &EditableTableWidget::btnMoveUpClicked, + mLibLocaleOrderModel.data(), &LibraryLocaleOrderModel::moveItemUp); + connect(mUi->tblLibLocaleOrder, &EditableTableWidget::btnMoveDownClicked, + mLibLocaleOrderModel.data(), + &LibraryLocaleOrderModel::moveItemDown); + } + + // Initialize library norm order + { + mLibNormOrderModel->setPlaceholderText(tr("Click here a add a norm")); + mLibNormOrderModel->setDefaultValue(QString("")); + mLibNormOrderModel->setChoices(getAvailableNorms()); + mUi->tblLibNormOrder->setShowMoveButtons(true); + mUi->tblLibNormOrder->setModel(mLibNormOrderModel.data()); + mUi->tblLibNormOrder->setItemDelegateForColumn( + LibraryNormOrderModel::COLUMN_TEXT, new ComboBoxDelegate(true, this)); + mUi->tblLibNormOrder->horizontalHeader()->setSectionResizeMode( + LibraryNormOrderModel::COLUMN_TEXT, QHeaderView::Stretch); + mUi->tblLibNormOrder->horizontalHeader()->setSectionResizeMode( + LibraryNormOrderModel::COLUMN_ACTIONS, QHeaderView::ResizeToContents); + connect(mUi->tblLibNormOrder, &EditableTableWidget::btnAddClicked, + mLibNormOrderModel.data(), &LibraryNormOrderModel::addItem); + connect(mUi->tblLibNormOrder, &EditableTableWidget::btnRemoveClicked, + mLibNormOrderModel.data(), &LibraryNormOrderModel::removeItem); + connect(mUi->tblLibNormOrder, &EditableTableWidget::btnMoveUpClicked, + mLibNormOrderModel.data(), &LibraryNormOrderModel::moveItemUp); + connect(mUi->tblLibNormOrder, &EditableTableWidget::btnMoveDownClicked, + mLibNormOrderModel.data(), &LibraryNormOrderModel::moveItemDown); + } + + // Initialize repository URLs + mRepositoryUrlsModel->setPlaceholderText(tr("Click here a add an URL")); + mUi->tblRepositoryUrls->setShowMoveButtons(true); + mUi->tblRepositoryUrls->setModel(mRepositoryUrlsModel.data()); + mUi->tblRepositoryUrls->horizontalHeader()->setSectionResizeMode( + RepositoryUrlModel::COLUMN_TEXT, QHeaderView::Stretch); + mUi->tblRepositoryUrls->horizontalHeader()->setSectionResizeMode( + RepositoryUrlModel::COLUMN_ACTIONS, QHeaderView::ResizeToContents); + connect(mUi->tblRepositoryUrls, &EditableTableWidget::btnAddClicked, + mRepositoryUrlsModel.data(), &RepositoryUrlModel::addItem); + connect(mUi->tblRepositoryUrls, &EditableTableWidget::btnRemoveClicked, + mRepositoryUrlsModel.data(), &RepositoryUrlModel::removeItem); + connect(mUi->tblRepositoryUrls, &EditableTableWidget::btnMoveUpClicked, + mRepositoryUrlsModel.data(), &RepositoryUrlModel::moveItemUp); + connect(mUi->tblRepositoryUrls, &EditableTableWidget::btnMoveDownClicked, + mRepositoryUrlsModel.data(), &RepositoryUrlModel::moveItemDown); + + // Application Locale + { + mUi->cbxAppLocale->clear(); + mUi->cbxAppLocale->addItem(tr("System Language"), QString("")); + QMap map; // map will be sorted by key + foreach (const QString& locale, qApp->getAvailableTranslationLocales()) { + map.insert(Toolbox::prettyPrintLocale(locale), locale); + } + QMap::const_iterator i = map.constBegin(); + while (i != map.constEnd()) { + mUi->cbxAppLocale->addItem(i.key(), i.value()); + ++i; + } + } + + // Now load all current settings + loadSettings(); + + // Load the window geometry QSettings clientSettings; restoreGeometry( clientSettings.value("workspace_settings_dialog/window_geometry") .toByteArray()); - // just in case that the wrong tab is selected in the UI designer: + // Just in case that the wrong tab is selected in the UI designer: mUi->tabWidget->setCurrentIndex(0); + + // Connect event handlers + connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, + &WorkspaceSettingsDialog::buttonBoxClicked); } WorkspaceSettingsDialog::~WorkspaceSettingsDialog() { - // save the window geometry + // Save the window geometry QSettings clientSettings; clientSettings.setValue("workspace_settings_dialog/window_geometry", saveGeometry()); - - // Remove all settings widgets from the dialog (important for memory - // management!) - - // tab: general - mSettings.getUser().getWidget()->setParent(0); - mSettings.getAppLocale().getWidget()->setParent(0); - mSettings.getAppDefMeasUnits().getLengthUnitComboBox()->setParent(0); - mSettings.getProjectAutosaveInterval().getWidget()->setParent(0); - - // tab: appearance - mSettings.getAppearance().getUseOpenGlWidget()->setParent(0); - - // tab: library - mSettings.getLibLocaleOrder().getWidget()->setParent(0); - mSettings.getLibNormOrder().getWidget()->setParent(0); - - // tab: repositories - mSettings.getRepositories().getWidget()->setParent(0); - - // tab: debug tools -#ifdef QT_DEBUG - mUi->tabWidget->removeTab( - mUi->tabWidget->indexOf(mSettings.getDebugTools().getWidget())); - mSettings.getDebugTools().getWidget()->setParent(0); -#endif - - // delete private member objects - delete mUi; - mUi = 0; -} - -/******************************************************************************* - * Inherited from QDialog - ******************************************************************************/ - -void WorkspaceSettingsDialog::accept() { - try { - mSettings.applyAll(); // can throw - QDialog::accept(); - } catch (const Exception& e) { - QMessageBox::critical(this, tr("Error"), e.getMsg()); - QDialog::reject(); - } -} - -void WorkspaceSettingsDialog::reject() { - mSettings.revertAll(); - QDialog::reject(); } /******************************************************************************* * Private Slots for the GUI elements ******************************************************************************/ -void WorkspaceSettingsDialog::on_buttonBox_clicked(QAbstractButton* button) { +void WorkspaceSettingsDialog::buttonBoxClicked( + QAbstractButton* button) noexcept { switch (mUi->buttonBox->buttonRole(button)) { - case QDialogButtonBox::AcceptRole: - case QDialogButtonBox::ApplyRole: - try { - mSettings.applyAll(); // can throw - } catch (const Exception& e) { - QMessageBox::critical(this, tr("Error"), e.getMsg()); - } + case QDialogButtonBox::RejectRole: { + reject(); + break; + } + + case QDialogButtonBox::AcceptRole: { + saveSettings(); + accept(); break; + } - case QDialogButtonBox::RejectRole: - mSettings.revertAll(); + case QDialogButtonBox::ApplyRole: { + saveSettings(); break; + } case QDialogButtonBox::ResetRole: { int answer = QMessageBox::question( this, tr("Restore default settings"), - tr("Are you sure to reset all settings to their default values?\n" - "After applying you cannot undo this change.")); - if (answer == QMessageBox::Yes) mSettings.restoreDefaults(); + tr("Are you sure to reset all settings to their default values?\n\n" + "Attention: This will be applied immediately and cannot be " + "undone!")); + if (answer == QMessageBox::Yes) { + mSettings.restoreDefaults(); + loadSettings(); // updating all widgets with the new values + saveSettings(); // save now since "cancel" does not revert! + } break; } default: - qCritical() << "invalid button role:" - << mUi->buttonBox->buttonRole(button); + Q_ASSERT(false); break; } } +void WorkspaceSettingsDialog::loadSettings() noexcept { + // User Name + mUi->edtUserName->setText(mSettings.userName.get()); + + // Application Locale + mUi->cbxAppLocale->setCurrentIndex( + mUi->cbxAppLocale->findData(mSettings.applicationLocale.get())); + + // Default Length Unit + mUi->cbxDefaultLengthUnit->clear(); + foreach (const LengthUnit& unit, LengthUnit::getAllUnits()) { + mUi->cbxDefaultLengthUnit->addItem(unit.toStringTr(), unit.getIndex()); + } + mUi->cbxDefaultLengthUnit->setCurrentIndex( + mSettings.defaultLengthUnit.get().getIndex()); + + // Autosave Interval + mUi->spbAutosaveInterval->setValue( + mSettings.projectAutosaveIntervalSeconds.get()); + + // Use OpenGL + mUi->cbxUseOpenGl->setChecked(mSettings.useOpenGl.get()); + + // Library Locale Order + mLibLocaleOrderModel->setValues(mSettings.libraryLocaleOrder.get()); + + // Library Norm Order + mLibNormOrderModel->setValues(mSettings.libraryNormOrder.get()); + + // Repository URLs + mRepositoryUrlsModel->setValues(mSettings.repositoryUrls.get()); +} + +void WorkspaceSettingsDialog::saveSettings() noexcept { + try { + // User Name + mSettings.userName.set(mUi->edtUserName->text().trimmed()); + + // Application Locale + if (mUi->cbxAppLocale->currentIndex() >= 0) { + mSettings.applicationLocale.set( + mUi->cbxAppLocale->currentData().toString()); + } + + // Default Length Unit + if (mUi->cbxDefaultLengthUnit->currentIndex() >= 0) { + mSettings.defaultLengthUnit.set(LengthUnit::fromIndex( + mUi->cbxDefaultLengthUnit->currentIndex())); // can throw + } + + // Autosave Interval + mSettings.projectAutosaveIntervalSeconds.set( + mUi->spbAutosaveInterval->value()); + + // Use OpenGL + mSettings.useOpenGl.set(mUi->cbxUseOpenGl->isChecked()); + + // Library Locale Order + mSettings.libraryLocaleOrder.set(mLibLocaleOrderModel->getValues()); + + // Library Norm Order + mSettings.libraryNormOrder.set(mLibNormOrderModel->getValues()); + + // Repository URLs + mSettings.repositoryUrls.set(mRepositoryUrlsModel->getValues()); + + mSettings.saveToFile(); // can throw + } catch (const Exception& e) { + QMessageBox::critical(this, tr("Error"), e.getMsg()); + } +} + /******************************************************************************* * End of File ******************************************************************************/ diff --git a/libs/librepcb/workspace/settings/workspacesettingsdialog.h b/libs/librepcb/workspace/settings/workspacesettingsdialog.h index c994a69985..b2ae372be4 100644 --- a/libs/librepcb/workspace/settings/workspacesettingsdialog.h +++ b/libs/librepcb/workspace/settings/workspacesettingsdialog.h @@ -23,6 +23,8 @@ /******************************************************************************* * Includes ******************************************************************************/ +#include + #include #include @@ -43,40 +45,39 @@ class WorkspaceSettings; ******************************************************************************/ /** - * @brief The WorkspaceSettingsDialog class - * - * This dialog class implements a GUI for all workspace settings. An instance of - * WorkspaceSettingsDialog is created in the class WorkspaceSettings. There must - * not exist more than one instance of this class at the same time in the same - * application instance! + * @brief Dialog (GUI) to view and modify workspace settings */ class WorkspaceSettingsDialog final : public QDialog { Q_OBJECT + using LibraryLocaleOrderModel = + EditableListModel; + using LibraryNormOrderModel = EditableListModel; + using RepositoryUrlModel = EditableListModel>; + public: // Constructors / Destructor - explicit WorkspaceSettingsDialog(WorkspaceSettings& settings); + WorkspaceSettingsDialog() = delete; + WorkspaceSettingsDialog(const WorkspaceSettingsDialog& other) = delete; + explicit WorkspaceSettingsDialog(WorkspaceSettings& settings, + QWidget* parent = nullptr); ~WorkspaceSettingsDialog(); -protected: - // Inherited from QDialog - void accept(); - void reject(); + // Operator Overloadings + WorkspaceSettingsDialog& operator=(const WorkspaceSettingsDialog& rhs) = + delete; -private slots: - - // Private Slots for the GUI elements - void on_buttonBox_clicked(QAbstractButton* button); +private: + void buttonBoxClicked(QAbstractButton* button) noexcept; + void loadSettings() noexcept; + void saveSettings() noexcept; private: - // make some methods inaccessible... - WorkspaceSettingsDialog(); - WorkspaceSettingsDialog(const WorkspaceSettingsDialog& other); - WorkspaceSettingsDialog& operator=(const WorkspaceSettingsDialog& rhs); - - // General Attributes - Ui::WorkspaceSettingsDialog* mUi; - WorkspaceSettings& mSettings; ///< a pointer to the WorkspaceSettings object + WorkspaceSettings& mSettings; ///< Reference to the WorkspaceSettings object + QScopedPointer mLibLocaleOrderModel; + QScopedPointer mLibNormOrderModel; + QScopedPointer mRepositoryUrlsModel; + QScopedPointer mUi; }; /******************************************************************************* diff --git a/libs/librepcb/workspace/settings/workspacesettingsdialog.ui b/libs/librepcb/workspace/settings/workspacesettingsdialog.ui index f1cc30fc8c..562b4957ad 100644 --- a/libs/librepcb/workspace/settings/workspacesettingsdialog.ui +++ b/libs/librepcb/workspace/settings/workspacesettingsdialog.ui @@ -26,28 +26,137 @@ - 3 + 0 General - - - + + + + + Application Language: + + - - - - Qt::Vertical + + + + 3 + + + + + QComboBox::NoInsert + + + + + + + + 0 + 0 + + + + Changing the language requires to restart the application. + + + true + + + + + + + + + Default Length Unit: - - - 20 - 40 - + + + + + + QComboBox::NoInsert + + + + + + + User Name: - + + + + + + 3 + + + + + + + + 100 + + + e.g. "John Doe" + + + true + + + + + + + + 0 + 0 + + + + This name will be used as author when creating new projects or libraries. + + + true + + + + + + + + + Autosave Interval: + + + + + + + + + 10000 + + + 60 + + + + + + + Seconds (0 = disable autosave) + + + + @@ -55,22 +164,40 @@ Appearance - - - - - - - - Qt::Vertical - - - - 20 - 262 - + + + + + Rendering Method: - + + + + + + + + Use OpenGL Hardware Acceleration + + + + + + + + 0 + 0 + + + + This setting will be applied only to newly opened windows. + + + true + + + + @@ -78,22 +205,48 @@ Library - - - + + + + + Preferred Languages: +(Highest priority at top) + + - - - - Qt::Vertical + + + + Preferred Norms: +(Highest priority at top) + + + + + + + QAbstractItemView::AllEditTriggers - - - 20 - 262 - + + false + + + false + + + + + + + QAbstractItemView::AllEditTriggers - + + false + + + false + + @@ -103,18 +256,27 @@ - - - - - <html><head/><body><p>Repositories are used to browse, download and update libraries.<br/>You can add any server to this list which implements the LibrePCB API.<br/>The official LibrePCB server is <a href="https://api.librepcb.org"><span style=" text-decoration: underline; color:#007af4;">https://api.librepcb.org</span></a>.</p></body></html> - - - true - - - - + + + <html><head/><body><p>Repositories are used to browse, download and update libraries.<br/>You can add any server to this list which implements the LibrePCB API.<br/>The official LibrePCB server is <a href="https://api.librepcb.org"><span style=" text-decoration: underline; color:#007af4;">https://api.librepcb.org</span></a>.</p></body></html> + + + true + + + + + + + QAbstractItemView::AllEditTriggers + + + false + + + false + + @@ -132,39 +294,13 @@ + + + librepcb::EditableTableWidget + QTableView +
librepcb/common/widgets/editabletablewidget.h
+
+
- - - buttonBox - accepted() - librepcb::workspace::WorkspaceSettingsDialog - accept() - - - 257 - 533 - - - 157 - 274 - - - - - buttonBox - rejected() - librepcb::workspace::WorkspaceSettingsDialog - reject() - - - 325 - 533 - - - 286 - 274 - - - - + diff --git a/libs/librepcb/workspace/settings/items/wsi_base.cpp b/libs/librepcb/workspace/settings/workspacesettingsitem.cpp similarity index 89% rename from libs/librepcb/workspace/settings/items/wsi_base.cpp rename to libs/librepcb/workspace/settings/workspacesettingsitem.cpp index cee2367514..2e6f00a98f 100644 --- a/libs/librepcb/workspace/settings/items/wsi_base.cpp +++ b/libs/librepcb/workspace/settings/workspacesettingsitem.cpp @@ -20,13 +20,9 @@ /******************************************************************************* * Includes ******************************************************************************/ -#include "wsi_base.h" - -#include "../../workspace.h" -#include "../workspacesettings.h" +#include "workspacesettingsitem.h" #include -#include /******************************************************************************* * Namespace @@ -38,10 +34,11 @@ namespace workspace { * Constructors / Destructor ******************************************************************************/ -WSI_Base::WSI_Base() noexcept : QObject(0) { +WorkspaceSettingsItem::WorkspaceSettingsItem(QObject* parent) noexcept + : QObject(parent) { } -WSI_Base::~WSI_Base() noexcept { +WorkspaceSettingsItem::~WorkspaceSettingsItem() noexcept { } /******************************************************************************* diff --git a/libs/librepcb/workspace/settings/items/wsi_base.h b/libs/librepcb/workspace/settings/workspacesettingsitem.h similarity index 51% rename from libs/librepcb/workspace/settings/items/wsi_base.h rename to libs/librepcb/workspace/settings/workspacesettingsitem.h index 55227fad5b..da97ea2ae8 100644 --- a/libs/librepcb/workspace/settings/items/wsi_base.h +++ b/libs/librepcb/workspace/settings/workspacesettingsitem.h @@ -17,16 +17,15 @@ * along with this program. If not, see . */ -#ifndef LIBREPCB_WSI_BASE_H -#define LIBREPCB_WSI_BASE_H +#ifndef LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_H +#define LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_H /******************************************************************************* * Includes ******************************************************************************/ -#include +#include #include -#include /******************************************************************************* * Namespace / Forward Declarations @@ -35,32 +34,62 @@ namespace librepcb { namespace workspace { /******************************************************************************* - * Class WSI_Base + * Class WorkspaceSettingsItem ******************************************************************************/ /** - * @brief The WSI_Base class is the base class of all workspace settings items + * @brief Base class for all workspace settings items * - * Every workspace setting is represented by a separate object. All of these - * objects have this class as base class. The name of all Workspace Settings - * Items begin with the prefix "WSI_" to easily recognize them. + * For simple settings, see + * ::librepcb::workspace::WorkspaceSettingsItem_GenericValue and + * ::librepcb::workspace::WorkspaceSettingsItem_GenericValueList. + * + * @see ::librepcb::workspace::WorkspaceSettingsItem_GenericValue + * @see ::librepcb::workspace::WorkspaceSettingsItem_GenericValueList */ -class WSI_Base : public QObject, public SerializableObject { +class WorkspaceSettingsItem : public QObject { Q_OBJECT public: // Constructors / Destructor - WSI_Base() noexcept; - WSI_Base(const WSI_Base& other) = delete; - virtual ~WSI_Base() noexcept; + explicit WorkspaceSettingsItem(QObject* parent = nullptr) noexcept; + WorkspaceSettingsItem(const WorkspaceSettingsItem& other) = delete; + ~WorkspaceSettingsItem() noexcept; - // General Methods + /** + * @brief Restore default value + * + * @note Implementation must emit the #edited() signal. + */ virtual void restoreDefault() noexcept = 0; - virtual void apply() noexcept = 0; - virtual void revert() noexcept = 0; + + /** + * @brief Load value from S-Expression node + * + * @param root Root node of the settings file. + * + * @note Implementation must emit the #edited() signal. + * + * @note Implementation must be atomic, i.e. either the value must be loaded + * completely from file, or left at the old value (in case of errors). + */ + virtual void load(const SExpression& root) = 0; + + /** + * @brief Serialize the value into S-Expression node + * + * @param root Root node of the settings file. + */ + virtual void serialize(SExpression& root) const = 0; // Operator Overloadings - WSI_Base& operator=(const WSI_Base& rhs) = delete; + WorkspaceSettingsItem& operator=(const WorkspaceSettingsItem& rhs) = delete; + +signals: + /** + * @brief Signal to notify about changes of the settings value + */ + void edited(); }; /******************************************************************************* @@ -70,4 +99,4 @@ class WSI_Base : public QObject, public SerializableObject { } // namespace workspace } // namespace librepcb -#endif // LIBREPCB_WSI_BASE_H +#endif // LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_H diff --git a/libs/librepcb/workspace/settings/workspacesettingsitem_genericvalue.h b/libs/librepcb/workspace/settings/workspacesettingsitem_genericvalue.h new file mode 100644 index 0000000000..54a5ba3e23 --- /dev/null +++ b/libs/librepcb/workspace/settings/workspacesettingsitem_genericvalue.h @@ -0,0 +1,120 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUE_H +#define LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUE_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "workspacesettingsitem.h" + +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { +namespace workspace { + +/******************************************************************************* + * Class WorkspaceSettingsItem_GenericValue + ******************************************************************************/ + +/** + * @brief Generic implementation of ::librepcb::workspace::WorkspaceSettingsItem + * for simple, value-type settings + */ +template +class WorkspaceSettingsItem_GenericValue final : public WorkspaceSettingsItem { +public: + // Constructors / Destructor + WorkspaceSettingsItem_GenericValue() = delete; + WorkspaceSettingsItem_GenericValue( + const WorkspaceSettingsItem_GenericValue& other) = delete; + explicit WorkspaceSettingsItem_GenericValue( + const QString& key, const T& defaultValue, + QObject* parent = nullptr) noexcept + : WorkspaceSettingsItem(parent), + mKey(key), + mDefaultValue(defaultValue), + mCurrentValue(defaultValue) {} + ~WorkspaceSettingsItem_GenericValue() noexcept {} + + /** + * @brief Get the current value + * + * @return Current value + */ + const T& get() const noexcept { return mCurrentValue; } + + /** + * @brief Set the value + * + * @param value The new value + */ + void set(const T& value) noexcept { + mCurrentValue = value; + emit edited(); + } + + /** + * @brief Get the default value + * + * @return Default value + */ + const T& getDefault() const noexcept { return mDefaultValue; } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::restoreDefault() + */ + virtual void restoreDefault() noexcept override { set(mDefaultValue); } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::load() + */ + void load(const SExpression& root) override { + set(root.getChildByPath(mKey).template getValueOfFirstChild()); + } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::serialize() + */ + void serialize(SExpression& root) const override { + root.appendChild(mKey, mCurrentValue, true); + } + + // Operator Overloadings + WorkspaceSettingsItem_GenericValue& operator =( + const WorkspaceSettingsItem_GenericValue& rhs) = delete; + +private: + QString mKey; ///< Key used for serialization + T mDefaultValue; ///< Initial, default value + T mCurrentValue; ///< Current value +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace workspace +} // namespace librepcb + +#endif // LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUE_H diff --git a/libs/librepcb/workspace/settings/workspacesettingsitem_genericvaluelist.h b/libs/librepcb/workspace/settings/workspacesettingsitem_genericvaluelist.h new file mode 100644 index 0000000000..77389bbfd0 --- /dev/null +++ b/libs/librepcb/workspace/settings/workspacesettingsitem_genericvaluelist.h @@ -0,0 +1,132 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUELIST_H +#define LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUELIST_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "workspacesettingsitem.h" + +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { +namespace workspace { + +/******************************************************************************* + * Class WorkspaceSettingsItem_GenericValueList + ******************************************************************************/ + +/** + * @brief Generic implementation of ::librepcb::workspace::WorkspaceSettingsItem + * for simple, value-in-list-type settings + */ +template +class WorkspaceSettingsItem_GenericValueList final + : public WorkspaceSettingsItem { +public: + // Constructors / Destructor + WorkspaceSettingsItem_GenericValueList() = delete; + WorkspaceSettingsItem_GenericValueList( + const WorkspaceSettingsItem_GenericValueList& other) = delete; + explicit WorkspaceSettingsItem_GenericValueList( + const QString& listKey, const QString& itemKey, const T& defaultValue, + QObject* parent = nullptr) noexcept + : WorkspaceSettingsItem(parent), + mListKey(listKey), + mItemKey(itemKey), + mDefaultValue(defaultValue), + mCurrentValue(defaultValue) {} + ~WorkspaceSettingsItem_GenericValueList() noexcept {} + + /** + * @brief Get the current value + * + * @return Current value + */ + const T& get() const noexcept { return mCurrentValue; } + + /** + * @brief Set the value + * + * @param value The new value + */ + void set(const T& value) noexcept { + mCurrentValue = value; + emit edited(); + } + + /** + * @brief Get the default value + * + * @return Default value + */ + const T& getDefault() const noexcept { return mDefaultValue; } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::restoreDefault() + */ + virtual void restoreDefault() noexcept override { set(mDefaultValue); } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::load() + */ + void load(const SExpression& root) override { + T values; // temporary object to make this method atomic + foreach (const SExpression& child, + root.getChildByPath(mListKey).getChildren(mItemKey)) { + values.append( + child.template getValueOfFirstChild()); + } + set(values); + } + + /** + * @copydoc ::librepcb::workspace::WorkspaceSettingsItem::serialize() + */ + void serialize(SExpression& root) const override { + SExpression& child = root.appendList(mListKey, true); + foreach (const auto& item, mCurrentValue) { + child.appendChild(mItemKey, item, true); + } + } + + // Operator Overloadings + WorkspaceSettingsItem_GenericValueList& operator =( + const WorkspaceSettingsItem_GenericValueList& rhs) = delete; + +private: + QString mListKey; ///< Outer key used for serialization + QString mItemKey; ///< Inner key used for serialization + T mDefaultValue; ///< Initial, default value + T mCurrentValue; ///< Current value +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace workspace +} // namespace librepcb + +#endif // LIBREPCB_WORKSPACE_WORKSPACESETTINGSITEM_GENERICVALUELIST_H diff --git a/libs/librepcb/workspace/workspace.cpp b/libs/librepcb/workspace/workspace.cpp index ab9a0f4bf5..44888cfdbc 100644 --- a/libs/librepcb/workspace/workspace.cpp +++ b/libs/librepcb/workspace/workspace.cpp @@ -114,7 +114,8 @@ Workspace::Workspace(const FilePath& wsPath) // all OK, let's load the workspace stuff! // load workspace settings - mWorkspaceSettings.reset(new WorkspaceSettings(*this)); + mWorkspaceSettings.reset( + new WorkspaceSettings(mMetadataPath.getPathTo("settings.lp"), this)); // load library database mLibraryDb.reset(new WorkspaceLibraryDb(*this)); // can throw diff --git a/libs/librepcb/workspace/workspace.pro b/libs/librepcb/workspace/workspace.pro index 6782f9ba46..c8ce9e92a7 100644 --- a/libs/librepcb/workspace/workspace.pro +++ b/libs/librepcb/workspace/workspace.pro @@ -31,18 +31,9 @@ SOURCES += \ library/workspacelibraryscanner.cpp \ projecttreemodel.cpp \ recentprojectsmodel.cpp \ - settings/items/wsi_appdefaultmeasurementunits.cpp \ - settings/items/wsi_appearance.cpp \ - settings/items/wsi_applocale.cpp \ - settings/items/wsi_base.cpp \ - settings/items/wsi_debugtools.cpp \ - settings/items/wsi_librarylocaleorder.cpp \ - settings/items/wsi_librarynormorder.cpp \ - settings/items/wsi_projectautosaveinterval.cpp \ - settings/items/wsi_repositories.cpp \ - settings/items/wsi_user.cpp \ settings/workspacesettings.cpp \ settings/workspacesettingsdialog.cpp \ + settings/workspacesettingsitem.cpp \ workspace.cpp \ HEADERS += \ @@ -54,18 +45,11 @@ HEADERS += \ library/workspacelibraryscanner.h \ projecttreemodel.h \ recentprojectsmodel.h \ - settings/items/wsi_appdefaultmeasurementunits.h \ - settings/items/wsi_appearance.h \ - settings/items/wsi_applocale.h \ - settings/items/wsi_base.h \ - settings/items/wsi_debugtools.h \ - settings/items/wsi_librarylocaleorder.h \ - settings/items/wsi_librarynormorder.h \ - settings/items/wsi_projectautosaveinterval.h \ - settings/items/wsi_repositories.h \ - settings/items/wsi_user.h \ settings/workspacesettings.h \ settings/workspacesettingsdialog.h \ + settings/workspacesettingsitem.h \ + settings/workspacesettingsitem_genericvalue.h \ + settings/workspacesettingsitem_genericvaluelist.h \ workspace.h \ FORMS += \