Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
shared_settings.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
6#include "grid_p.h"
9
10#include <actioneditor_p.h>
11
12#include <QtDesigner/abstractformeditor.h>
13#include <QtDesigner/abstractsettings.h>
14
15#include <QtCore/qstringlist.h>
16#include <QtCore/qdir.h>
17#include <QtCore/qvariant.h>
18#include <QtCore/qcoreapplication.h>
19#include <QtCore/qsize.h>
20
22
23using namespace Qt::StringLiterals;
24
25static constexpr auto defaultGridKey = "defaultGrid"_L1;
26static constexpr auto previewKey = "Preview"_L1;
27static constexpr auto enabledKey = "Enabled"_L1;
28static constexpr auto userDeviceSkinsKey= "UserDeviceSkins"_L1;
29static constexpr auto zoomKey = "zoom"_L1;
30static constexpr auto zoomEnabledKey = "zoomEnabled"_L1;
31static constexpr auto deviceProfileIndexKey = "DeviceProfileIndex"_L1;
32static constexpr auto deviceProfilesKey = "DeviceProfiles"_L1;
33static constexpr auto formTemplatePathsKey = "FormTemplatePaths"_L1;
34static constexpr auto formTemplateKey = "FormTemplate"_L1;
35static constexpr auto newFormSizeKey = "NewFormSize"_L1;
36static constexpr auto namingModeKey = "naming"_L1;
37static constexpr auto underScoreNamingMode = "underscore"_L1;
38static constexpr auto camelCaseNamingMode = "camelcase"_L1;
39
40static bool checkTemplatePath(const QString &path, bool create)
41{
42 QDir current(QDir::current());
43 if (current.exists(path))
44 return true;
45
46 if (!create)
47 return false;
48
49 if (current.mkpath(path))
50 return true;
51
52 qdesigner_internal::designerWarning(QCoreApplication::translate("QDesignerSharedSettings", "The template path %1 could not be created.").arg(path));
53 return false;
54}
55
56namespace qdesigner_internal {
57
62
72
77
79{
80 static QStringList rc;
81 if (rc.isEmpty()) {
82 // Ensure default form template paths
83 const auto templatePath = "/templates"_L1;
84 // home
86 if (checkTemplatePath(path, true))
87 rc += path;
88
89 // designer/bin: Might be owned by root in some installations, do not force it.
92 if (checkTemplatePath(path, false))
93 rc += path;
94 }
95 return rc;
96}
97
98// Migrate templates from $HOME/.designer to standard paths in Qt 7
99// ### FIXME Qt 8: Remove (QTBUG-96005)
101{
102 const QString templatePath = u"/templates"_s;
104 if (QFileInfo::exists(path))
105 return;
106 if (!QDir().mkpath(path))
107 return;
109 if (!QFileInfo::exists(path))
110 return;
112 for (const auto &file : files) {
113 const QString newPath = path + u'/' + file.fileName();
115 }
116}
117
123
128
133
138
146
148{
149 // get template paths excluding internal ones
153 if (index != -1)
155 }
156 return rc;
157}
158
163
165{
166 if (s.isNull()) {
168 } else {
170 }
171}
172
173
180
185
193
200
209
216
218{
219 return m_settings->value(zoomKey, 100).toInt();
220}
221
226
233
240
242{
243 return m_settings->value(zoomEnabledKey, false).toBool();
244}
245
250
255
260
265
266static inline QString msgWarnDeviceProfileXml(const QString &msg)
267{
268 return QCoreApplication::translate("QDesignerSharedSettings", "An error has been encountered while parsing device profile XML: %1").arg(msg);
269}
270
272{
274 if (idx < 0)
275 return rc;
277 if (idx >= xmls.size())
278 return rc;
280 if (!rc.fromXml(xmls.at(idx), &errorMessage)) {
281 rc.clear();
283 }
284 return rc;
285}
286
288{
290}
291
293{
296 if (xmls.isEmpty())
297 return rc;
298 // De-serialize
301 for (const auto &xml : xmls) {
302 if (dp.fromXml(xml, &errorMessage)) {
303 rc.push_back(dp);
304 } else {
306 }
307 }
308 return rc;
309}
310
318}
319
320QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QString msgWarnDeviceProfileXml(const QString &msg)
static constexpr auto zoomKey
static constexpr auto deviceProfileIndexKey
static constexpr auto formTemplatePathsKey
static constexpr auto userDeviceSkinsKey
static constexpr auto previewKey
static constexpr auto underScoreNamingMode
static constexpr auto defaultGridKey
static constexpr auto deviceProfilesKey
static constexpr auto camelCaseNamingMode
static bool checkTemplatePath(const QString &path, bool create)
static constexpr auto enabledKey
static constexpr auto namingModeKey
static constexpr auto newFormSizeKey
static constexpr auto zoomEnabledKey
static constexpr auto formTemplateKey