Add saving and loading the configuration to a file (discussion #610)

Revives #640, closed only to clear a review backlog. Two entries in
the Configuration menu: "Enregistrer la configuration sous..." saves
the settings to a .conf file, "Charger une configuration..." replaces
them with one. The file is always ini format, so a profile made on one
platform loads on the others.

Changes from #640:
- Window sizes, positions and dock layouts (".../geometry",
  ".../state") and the recent-files lists stay out of a profile and
  are kept on load: they describe this computer, not a preference.
- A saved file carries a format marker; loading refuses files that
  QElectroTech did not save.
- Loading closes QElectroTech and asks the user to start it again,
  instead of starting a second copy: a second copy started while this
  one is still running hands its arguments over and exits (main.cpp).
- The colour dialog's custom colours are reloaded from the profile
  before quitting, since ~QETApp() saves them over the loaded ones.
- Both actions are registered with ShortcutManager, so they appear in
  command search and can be given a shortcut.
- The copy rules live in the header-only utils/configprofile.h and
  are unit tested (tst_configprofile).

Loading still replaces rather than merges: a setting the profile does
not have is removed, or switching profiles would keep settings from the
previous one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-30 10:42:26 +13:00
parent bae336ef5b
commit 473f792bac
7 changed files with 330 additions and 0 deletions
+13
View File
@@ -92,6 +92,16 @@ void QETMainWindow::initCommonActions()
}
});
export_config_action_ = new QAction(QET::Icons::DocumentExport, tr("Enregistrer la configuration sous..."), this);
export_config_action_ -> setStatusTip(tr("Enregistre les réglages de QElectroTech dans un fichier", "status bar tip"));
connect(export_config_action_, &QAction::triggered, qet_app, &QETApp::exportConfiguration);
ShortcutManager::instance().registerAction(export_config_action_, "mainwindow.export_configuration", tr("Général"), QKeySequence());
import_config_action_ = new QAction(QET::Icons::DocumentImport, tr("Charger une configuration..."), this);
import_config_action_ -> setStatusTip(tr("Remplace les réglages de QElectroTech par ceux d'un fichier, puis ferme QElectroTech", "status bar tip"));
connect(import_config_action_, &QAction::triggered, qet_app, &QETApp::importConfiguration);
ShortcutManager::instance().registerAction(import_config_action_, "mainwindow.import_configuration", tr("Général"), QKeySequence());
fullscreen_action_ = new QAction(this);
updateFullScreenAction();
connect(fullscreen_action_, &QAction::triggered, this, &QETMainWindow::toggleFullScreen);
@@ -170,6 +180,9 @@ void QETMainWindow::initCommonMenus()
settings_menu_ = new QMenu(tr("&Configuration", "window menu"), this);
settings_menu_ -> addAction(fullscreen_action_);
settings_menu_ -> addAction(configure_action_);
settings_menu_ -> addSeparator();
settings_menu_ -> addAction(export_config_action_);
settings_menu_ -> addAction(import_config_action_);
connect(settings_menu_, &QMenu::aboutToShow, this, &QETMainWindow::checkToolbarsmenu);
help_menu_ = new QMenu(tr("&Aide", "window menu"), this);