mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-23 15:34:12 +02:00
dfec60a3a5
A terminal's label is written as it is read off the plan, "X1:1", and
the symbol draws it as one field. On a long strip that field is long
enough to reach into the next terminal, and a user who wants the number
next to the screw and the label out of the way has no way to say so.
Settings > General > Appearance now has a "Display of the terminal
labelling" group with two choices: the label and its terminal number in
one field, the way it has always been drawn, or the two split. The
first is what every drawing gets, so nothing moves until the user asks
for it, and choosing the other one redraws the drawings already open --
nothing needs to be closed and opened again.
A symbol made for the split carries a text field bound to the new
"Terminal number" information (in the element editor's list, next to
the label, and as the %{terminal_number} variable of a composite text):
the label field then shows "X1" and the number field "1", each placed
where the symbol wants it, and hideable when it must be. A symbol which
has no such field -- every symbol drawn until now -- gets the number on
its own line inside the label field, so switching the setting on can
never make a number vanish, and never needs a symbol to be touched
first. A field which becomes, or stops being, the number field tells
the label fields of its symbol to draw themselves again.
Only the drawing reacts. What the element stores, the numbering, the
sorting in the terminal strip editor, the automatic strip import and
every export keep the whole label: the split is read where the text is
drawn (Element::labelForDisplay() and friends), not where the label is
made.
The new test covers both choices, with and without the number field, a
label with no colon at all, and the way back to the whole label. The
full test suite passes (124/124).
318 lines
9.8 KiB
C++
318 lines
9.8 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech 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 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qetsettings.h"
|
|
#include <QSettings>
|
|
#include <QVariant>
|
|
#include <QByteArray>
|
|
|
|
namespace QetSettings
|
|
{
|
|
/**
|
|
* @brief setHdpiScaleFactorRoundingPolicy
|
|
* Write the value of HdpiScaleFactorRoundingPolicy in
|
|
* QElectroTech settings
|
|
* the value is in form of a string.
|
|
* @a policy can be : Round, Ceil, Floor, RoundPreferFloor, PassThrough
|
|
* In case of wrong policy, PassThrough is use as default value.
|
|
* The value is stored with key : hdpi_scale_factor_rounding_policy
|
|
* @sa Qt::HighDpiScaleFactorRoundingPolicy
|
|
* @param policy
|
|
*/
|
|
void setHdpiScaleFactorRoundingPolicy(const QString &policy_str)
|
|
{
|
|
auto policy = QString("PassThrough");
|
|
if (policy_str == QLatin1String("Round")) {
|
|
policy = "Round";
|
|
} else if (policy_str == QLatin1String("Ceil")) {
|
|
policy = "Ceil";
|
|
} else if (policy_str == QLatin1String("Floor")) {
|
|
policy = "Floor";
|
|
} else if (policy_str == QLatin1String("RoundPreferFloor")) {
|
|
policy = "RoundPreferFloor";
|
|
}
|
|
QSettings settings;
|
|
settings.setValue("hdpi_scale_factor_rounding_policy", policy);
|
|
}
|
|
|
|
/**
|
|
* @brief setHdpiScaleFactorRoundingPolicy
|
|
* Overload function
|
|
* @sa void setHdpiScaleFactorRoundingPolicy(const QString &policy_str)
|
|
* @param policy
|
|
*/
|
|
void setHdpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy)
|
|
{
|
|
QString policy_str;
|
|
switch (policy) {
|
|
case Qt::HighDpiScaleFactorRoundingPolicy::Round:
|
|
policy_str = "Round";
|
|
break;
|
|
case Qt::HighDpiScaleFactorRoundingPolicy::Ceil:
|
|
policy_str = "Ceil";
|
|
break;
|
|
case Qt::HighDpiScaleFactorRoundingPolicy::Floor:
|
|
policy_str = "Floor";
|
|
break;
|
|
case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor:
|
|
policy_str = "RoundPreferFloor";
|
|
break;
|
|
default:
|
|
policy_str = "PassThrough";
|
|
break;
|
|
}
|
|
|
|
QSettings settings;
|
|
settings.setValue("hdpi_scale_factor_rounding_policy", policy_str);
|
|
}
|
|
|
|
/**
|
|
* @brief hdpiScaleFactorRoundingPolicy
|
|
* @param default_policy
|
|
* @return the hdpiScaleFactorRoundingPolicy value stored in current settings.
|
|
* @sa setHdpiScaleFactorRoundingPolicy
|
|
*/
|
|
Qt::HighDpiScaleFactorRoundingPolicy hdpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy default_policy)
|
|
{
|
|
QSettings settings;
|
|
auto value_ = settings.value("hdpi_scale_factor_rounding_policy");
|
|
|
|
if (value_ == QLatin1String("Round")) {
|
|
return Qt::HighDpiScaleFactorRoundingPolicy::Round;
|
|
} else if (value_ == QLatin1String("Ceil")) {
|
|
return Qt::HighDpiScaleFactorRoundingPolicy::Ceil;
|
|
} else if (value_ == QLatin1String("Floor")) {
|
|
return Qt::HighDpiScaleFactorRoundingPolicy::Floor;
|
|
} else if (value_ == QLatin1String("RoundPreferFloor")) {
|
|
return Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor;
|
|
} else if (value_ == QLatin1String("PassThrough")) {
|
|
return Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
|
|
} else {
|
|
return default_policy;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief scriptingForcedByEnvironment
|
|
* @return true if QET_ENABLE_SCRIPTING is set to 1 in the environment.
|
|
*
|
|
* The way to turn scripting on where there is nobody to tick a box:
|
|
* a headless run, a CI job, a build server. Those have no settings
|
|
* file worth writing to -- and on a machine whose HOME is created
|
|
* fresh for the run, writing one would not survive anyway.
|
|
*/
|
|
bool scriptingForcedByEnvironment()
|
|
{
|
|
return qgetenv("QET_ENABLE_SCRIPTING") == QByteArray("1");
|
|
}
|
|
|
|
/**
|
|
* @brief scriptingEnabled
|
|
* @return whether QElectroTech may run a JavaScript script.
|
|
*
|
|
* Off unless the user turned it on. A script reaches the whole project
|
|
* and the filesystem through the export calls, so it is capability the
|
|
* great majority of users never asked for; leaving it on by default
|
|
* would hand it to them anyway. @sa setScriptingEnabled
|
|
*
|
|
* The environment override wins over the stored value, and is checked
|
|
* first so that a machine with no settings at all still answers.
|
|
*/
|
|
bool scriptingEnabled()
|
|
{
|
|
if (scriptingForcedByEnvironment()) {
|
|
return true;
|
|
}
|
|
QSettings settings;
|
|
return settings.value("scripting/enabled", false).toBool();
|
|
}
|
|
|
|
/**
|
|
* @brief setScriptingEnabled
|
|
* Store whether scripting is allowed. @sa scriptingEnabled
|
|
* @param enabled
|
|
*/
|
|
void setScriptingEnabled(bool enabled)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue("scripting/enabled", enabled);
|
|
}
|
|
|
|
/**
|
|
* @brief liveAssistantEnabled
|
|
* @return whether an AI assistant may connect to this QElectroTech and
|
|
* act on the open project while the user watches (live mode, see
|
|
* LiveServer). Off unless the user turned it on, and even then every
|
|
* start asks before anything can connect. No environment override:
|
|
* this is a choice made by the person in front of the window.
|
|
*/
|
|
bool liveAssistantEnabled()
|
|
{
|
|
QSettings settings;
|
|
return settings.value("scripting/live_assistant", false).toBool();
|
|
}
|
|
|
|
void setLiveAssistantEnabled(bool enabled)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue("scripting/live_assistant", enabled);
|
|
//Turned off and on again: the start warning comes back, so
|
|
//"don't ask again" never outlives the choice it was made for
|
|
if (!enabled) settings.remove("scripting/live_skip_warning");
|
|
}
|
|
|
|
/**
|
|
* @brief liveSkipStartWarning
|
|
* @return true when the user ticked "don't ask again" in live mode's
|
|
* start warning: live mode then opens at every start without asking,
|
|
* until it is switched off in the settings. False unless they did.
|
|
*/
|
|
bool liveSkipStartWarning()
|
|
{
|
|
QSettings settings;
|
|
return settings.value("scripting/live_skip_warning", false).toBool();
|
|
}
|
|
|
|
void setLiveSkipStartWarning(bool skip)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue("scripting/live_skip_warning", skip);
|
|
}
|
|
|
|
/**
|
|
* @brief liveAskFirst
|
|
* @return whether live mode shows each script the assistant wrote and
|
|
* asks before running it. On unless the user chose "always".
|
|
*/
|
|
bool liveAskFirst()
|
|
{
|
|
QSettings settings;
|
|
return settings.value("scripting/live_ask_first", true).toBool();
|
|
}
|
|
|
|
void setLiveAskFirst(bool ask)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue("scripting/live_ask_first", ask);
|
|
}
|
|
|
|
/**
|
|
* @brief houseStyle
|
|
* @return this installation's drawing conventions, in the user's own
|
|
* words -- empty when nobody has set any.
|
|
*/
|
|
QString houseStyle()
|
|
{
|
|
QSettings settings;
|
|
return settings.value("assistant/house_style", QString()).toString();
|
|
}
|
|
|
|
void setHouseStyle(const QString &text)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue("assistant/house_style", text);
|
|
}
|
|
|
|
/**
|
|
* @brief setSheetBackground
|
|
* Store the sheet background last picked in the diagram editor, so the
|
|
* next start opens on it for every project, old or new. @sa sheetBackground
|
|
* @param background
|
|
*/
|
|
void setSheetBackground(const SheetBackground &background)
|
|
{
|
|
QSettings settings;
|
|
//HexRgb, not HexArgb, on purpose: Diagram::background_color is
|
|
//temporarily given an alpha of 0 by the SVG export to make the
|
|
//background transparent, and that transient value must never end
|
|
//up here as a stored transparent sheet.
|
|
settings.setValue(QStringLiteral("diagrameditor/sheet_background_color"),
|
|
background.color.name(QColor::HexRgb));
|
|
settings.setValue(QStringLiteral("diagrameditor/sheet_background_custom"),
|
|
background.custom);
|
|
}
|
|
|
|
/**
|
|
* @brief sheetBackground
|
|
* @return the sheet background stored by setSheetBackground(), or the
|
|
* built-in default (white, following the system) when there is none.
|
|
* @sa setSheetBackground
|
|
*/
|
|
SheetBackground sheetBackground()
|
|
{
|
|
QSettings settings;
|
|
SheetBackground background;
|
|
background.custom = settings.value(
|
|
QStringLiteral("diagrameditor/sheet_background_custom"),
|
|
false).toBool();
|
|
const QColor stored(settings.value(
|
|
QStringLiteral("diagrameditor/sheet_background_color"),
|
|
QStringLiteral("#ffffff")).toString());
|
|
background.color = stored.isValid() ? stored : QColor(Qt::white);
|
|
return background;
|
|
}
|
|
|
|
/**
|
|
* @brief sheetBackgroundRecentColors
|
|
* @return the "recently used" sheet background colours, most recent
|
|
* first. Empty until the user has picked a non-preset colour.
|
|
* @sa setSheetBackgroundRecentColors
|
|
*/
|
|
QStringList sheetBackgroundRecentColors()
|
|
{
|
|
QSettings settings;
|
|
return settings.value(QStringLiteral("diagrameditor/sheet_background_recent")).toStringList();
|
|
}
|
|
|
|
/**
|
|
* @brief setSheetBackgroundRecentColors
|
|
* Store the "recently used" sheet background colours, most recent first.
|
|
* @sa sheetBackgroundRecentColors
|
|
* @param colors
|
|
*/
|
|
void setSheetBackgroundRecentColors(const QStringList &colors)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue(QStringLiteral("diagrameditor/sheet_background_recent"), colors);
|
|
}
|
|
|
|
/**
|
|
* @brief terminalLabelSplit
|
|
* @return whether a terminal's label is drawn split, the label and
|
|
* the terminal number each in their own text field, instead of the
|
|
* whole label ("X1:1") in one field. Off unless the user turned it
|
|
* on, so an existing drawing keeps its look. @sa setTerminalLabelSplit
|
|
*/
|
|
bool terminalLabelSplit()
|
|
{
|
|
QSettings settings;
|
|
return settings.value(QStringLiteral("element/terminal_label_split"), false).toBool();
|
|
}
|
|
|
|
/**
|
|
* @brief setTerminalLabelSplit
|
|
* Store whether a terminal's label is drawn split. @sa terminalLabelSplit
|
|
* @param split
|
|
*/
|
|
void setTerminalLabelSplit(bool split)
|
|
{
|
|
QSettings settings;
|
|
settings.setValue(QStringLiteral("element/terminal_label_split"), split);
|
|
}
|
|
}
|