Add saving and loading part of the settings (discussion #1405)

Save settings as... now asks which parts to save: toolbars, keyboard
shortcuts and mouse gestures; defaults for new projects (folio, title
block, wires, numbering); everything else. All three ticked writes the
same complete file as before (format 1, collection folders included).

A file with only some parts is format 2 and lists its parts. Loading it
replaces those parts and keeps every other setting. The folders of the
collections are never in such a file: they rarely exist on another
computer. A QElectroTech that only knows format 1 refuses it rather than
loading it as complete and losing every other setting.

A file holding only the defaults for new projects loads without closing
QElectroTech, since QETProject reads them again for every new project.

Which part a key belongs to is ConfigProfile::partOf(); a key it does
not list falls in "everything else", so a new setting can never be left
out of every part. The test checks that what BorderProperties writes for
the folio defaults lands in the new-project part.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-09 21:16:15 +13:00
parent e89c69719a
commit 24e67da33c
4 changed files with 414 additions and 26 deletions
+5 -2
View File
@@ -187,10 +187,13 @@ target_link_libraries(tst_symbolscale PRIVATE Qt::Test)
# configprofile.h is header-only: which settings a saved configuration
# profile carries, and how loading one replaces the live settings.
add_executable(tst_configprofile tst_configprofile.cpp)
# borderproperties.cpp: the real writer of the folio size defaults, to check
# that what it writes falls in the part for new projects.
add_executable(tst_configprofile tst_configprofile.cpp
${QET_DIR}/sources/borderproperties.cpp)
add_test(NAME tst_configprofile COMMAND tst_configprofile)
target_include_directories(tst_configprofile PRIVATE ${QET_DIR}/sources)
target_link_libraries(tst_configprofile PRIVATE Qt::Test Qt::Gui)
target_link_libraries(tst_configprofile PRIVATE Qt::Test Qt::Gui Qt::Xml)
# itemgroups.cpp keeps group membership and the selection rule apart from
# Diagram, so it is tested here on a plain scene of rectangles.
+128
View File
@@ -2,6 +2,7 @@
#include <QTemporaryDir>
#include "utils/configprofile.h"
#include "borderproperties.h"
class tst_configprofile : public QObject
{
@@ -87,6 +88,133 @@ private slots:
QCOMPARE(b.value(k), a.value(k));
}
// Every key belongs to one part; keys nobody listed are Other.
void partOfKeys()
{
using P = ConfigProfile::Part;
QCOMPARE(ConfigProfile::partOf("shortcuts/mainwindow.fullscreen"), P::Controls);
QCOMPARE(ConfigProfile::partOf("toolbars/icon_size"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/toolbars/diagram"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/custom_toolbars/names"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/shortcut_bar/canvas"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/gestures/directions"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/mouse_gestures"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/context_toolbar"), P::Controls);
QCOMPARE(ConfigProfile::partOf("diagrameditor/defaultconductortype"), P::NewProject);
QCOMPARE(ConfigProfile::partOf("diagrameditor/defaultreportlabel"), P::NewProject);
QCOMPARE(ConfigProfile::partOf("diagrameditor/defaultxrefcoil"), P::NewProject);
QCOMPARE(ConfigProfile::partOf("diagrameditor/defaultguides/1/position"), P::NewProject);
QCOMPARE(ConfigProfile::partOf("autonum/conductor/current"), P::NewProject);
QCOMPARE(ConfigProfile::partOf("elements-collections/custom-collection-path"), P::Folders);
QCOMPARE(ConfigProfile::partOf("elements-collections/macros-path"), P::Folders);
QCOMPARE(ConfigProfile::partOf("diagrameditor/Xgrid"), P::Other);
QCOMPARE(ConfigProfile::partOf("diagrameditor/auto_break_conductor"), P::Other);
QCOMPARE(ConfigProfile::partOf("lang"), P::Other);
QCOMPARE(ConfigProfile::partOf("customColors"), P::Other);
}
// What the New project page writes for the folio size is the
// NewProject part, whatever key names BorderProperties uses.
void folioDefaultsAreNewProject()
{
QSettings live(path("live_border.conf"), QSettings::IniFormat);
BorderProperties().toSettings(live, "diagrameditor/default");
const QStringList keys = live.allKeys();
QVERIFY(!keys.isEmpty());
for (const QString &key : keys)
QCOMPARE(ConfigProfile::partOf(key), ConfigProfile::Part::NewProject);
}
// A file of some parts holds only their keys, never the folders, and
// is format 2 so that an older QElectroTech refuses it.
void exportSomeParts()
{
QSettings live(path("live4.conf"), QSettings::IniFormat);
live.setValue("shortcuts/mainwindow.fullscreen", "F11");
live.setValue("diagrameditor/defaultconductortype", "Multi");
live.setValue("diagrameditor/Xgrid", 7);
live.setValue("elements-collections/custom-collection-path", "/home/a/sym");
QSettings file(path("profile4.conf"), QSettings::IniFormat);
QCOMPARE(ConfigProfile::exportTo(live, file, {ConfigProfile::Part::NewProject}), 1);
QCOMPARE(file.value(ConfigProfile::marker_key).toInt(), 2);
QVERIFY(ConfigProfile::isProfile(file));
QCOMPARE(ConfigProfile::partsOf(file), QList<ConfigProfile::Part>{ConfigProfile::Part::NewProject});
QVERIFY(file.contains("diagrameditor/defaultconductortype"));
QVERIFY(!file.contains("shortcuts/mainwindow.fullscreen"));
QVERIFY(!file.contains("diagrameditor/Xgrid"));
QVERIFY(!file.contains("elements-collections/custom-collection-path"));
//Other without the two others: still no folders
QSettings file2(path("profile4b.conf"), QSettings::IniFormat);
ConfigProfile::exportTo(live, file2, {ConfigProfile::Part::Other});
QVERIFY(file2.contains("diagrameditor/Xgrid"));
QVERIFY(!file2.contains("elements-collections/custom-collection-path"));
}
// Every choosable part is a complete profile: format 1, folders
// included, readable by the QElectroTech that only knows format 1.
void exportEveryPartIsComplete()
{
QSettings live(path("live5.conf"), QSettings::IniFormat);
live.setValue("diagrameditor/Xgrid", 7);
live.setValue("elements-collections/custom-collection-path", "/home/a/sym");
QSettings file(path("profile5.conf"), QSettings::IniFormat);
ConfigProfile::exportTo(live, file, ConfigProfile::choosableParts());
QCOMPARE(file.value(ConfigProfile::marker_key).toInt(), 1);
QVERIFY(!file.contains(ConfigProfile::parts_key));
QVERIFY(file.contains("elements-collections/custom-collection-path"));
QCOMPARE(ConfigProfile::partsOf(file).size(), 4);
}
// Loading some parts replaces those parts only, removes their keys the
// file lacks, and keeps every other setting, folders included.
void importSomePartsKeepsTheRest()
{
QSettings file(path("profile6.conf"), QSettings::IniFormat);
file.setValue("diagrameditor/defaultconductortype", "Single");
file.setValue("diagrameditor/Xgrid", 99); // not in its parts: ignored
file.setValue(ConfigProfile::marker_key, 2);
file.setValue(ConfigProfile::parts_key, "newproject");
QSettings live(path("live6.conf"), QSettings::IniFormat);
live.setValue("diagrameditor/defaultconductortype", "Multi");
live.setValue("autonum/folio/current", "mine");
live.setValue("diagrameditor/Xgrid", 10);
live.setValue("shortcuts/mainwindow.fullscreen", "F11");
live.setValue("elements-collections/custom-collection-path", "/home/me/sym");
ConfigProfile::importFrom(file, live);
QCOMPARE(live.value("diagrameditor/defaultconductortype").toString(), QString("Single"));
QVERIFY(!live.contains("autonum/folio/current"));
QCOMPARE(live.value("diagrameditor/Xgrid").toInt(), 10);
QCOMPARE(live.value("shortcuts/mainwindow.fullscreen").toString(), QString("F11"));
QCOMPARE(live.value("elements-collections/custom-collection-path").toString(),
QString("/home/me/sym"));
QVERIFY(!live.contains(ConfigProfile::parts_key));
}
void restartOnlyWhenNeeded()
{
using P = ConfigProfile::Part;
QVERIFY(!ConfigProfile::needsRestart({P::NewProject}));
QVERIFY(ConfigProfile::needsRestart({P::NewProject, P::Controls}));
QVERIFY(ConfigProfile::needsRestart({P::Other}));
}
// A file of format 2 naming no known part is refused by the caller.
void unknownPartsGiveNothing()
{
QSettings file(path("profile7.conf"), QSettings::IniFormat);
file.setValue(ConfigProfile::marker_key, 2);
file.setValue(ConfigProfile::parts_key, "colours");
QVERIFY(ConfigProfile::partsOf(file).isEmpty());
}
void plainFileIsNotAProfile()
{
QSettings other(path("other.conf"), QSettings::IniFormat);