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
5#include "grid_p.h"
8
9#include <actioneditor_p.h>
10
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/abstractsettings.h>
13
14#include <QtCore/qstringlist.h>
15#include <QtCore/qdir.h>
16#include <QtCore/qvariant.h>
17#include <QtCore/qcoreapplication.h>
18#include <QtCore/qsize.h>
19
21
22using namespace Qt::StringLiterals;
23
24static constexpr auto defaultGridKey = "defaultGrid"_L1;
25static constexpr auto previewKey = "Preview"_L1;
26static constexpr auto enabledKey = "Enabled"_L1;
27static constexpr auto userDeviceSkinsKey= "UserDeviceSkins"_L1;
28static constexpr auto zoomKey = "zoom"_L1;
29static constexpr auto zoomEnabledKey = "zoomEnabled"_L1;
30static constexpr auto deviceProfileIndexKey = "DeviceProfileIndex"_L1;
31static constexpr auto deviceProfilesKey = "DeviceProfiles"_L1;
32static constexpr auto formTemplatePathsKey = "FormTemplatePaths"_L1;
33static constexpr auto formTemplateKey = "FormTemplate"_L1;
34static constexpr auto newFormSizeKey = "NewFormSize"_L1;
35static constexpr auto namingModeKey = "naming"_L1;
36static constexpr auto underScoreNamingMode = "underscore"_L1;
37static constexpr auto camelCaseNamingMode = "camelcase"_L1;
38
39static bool checkTemplatePath(const QString &path, bool create)
40{
41 QDir current(QDir::current());
42 if (current.exists(path))
43 return true;
44
45 if (!create)
46 return false;
47
48 if (current.mkpath(path))
49 return true;
50
51 qdesigner_internal::designerWarning(QCoreApplication::translate("QDesignerSharedSettings", "The template path %1 could not be created.").arg(path));
52 return false;
53}
54
55namespace qdesigner_internal {
56
61
71
76
78{
79 static QStringList rc;
80 if (rc.isEmpty()) {
81 // Ensure default form template paths
82 const auto templatePath = "/templates"_L1;
83 // home
85 if (checkTemplatePath(path, true))
86 rc += path;
87
88 // designer/bin: Might be owned by root in some installations, do not force it.
91 if (checkTemplatePath(path, false))
92 rc += path;
93 }
94 return rc;
95}
96
97// Migrate templates from $HOME/.designer to standard paths in Qt 7
98// ### FIXME Qt 8: Remove (QTBUG-96005)
100{
101 const QString templatePath = u"/templates"_s;
103 if (QFileInfo::exists(path))
104 return;
105 if (!QDir().mkpath(path))
106 return;
108 if (!QFileInfo::exists(path))
109 return;
111 for (const auto &file : files) {
112 const QString newPath = path + u'/' + file.fileName();
114 }
115}
116
122
127
132
137
145
147{
148 // get template paths excluding internal ones
152 if (index != -1)
154 }
155 return rc;
156}
157
162
164{
165 if (s.isNull()) {
167 } else {
169 }
170}
171
172
179
184
192
199
208
215
217{
218 return m_settings->value(zoomKey, 100).toInt();
219}
220
225
232
239
241{
242 return m_settings->value(zoomEnabledKey, false).toBool();
243}
244
249
254
259
264
265static inline QString msgWarnDeviceProfileXml(const QString &msg)
266{
267 return QCoreApplication::translate("QDesignerSharedSettings", "An error has been encountered while parsing device profile XML: %1").arg(msg);
268}
269
271{
273 if (idx < 0)
274 return rc;
276 if (idx >= xmls.size())
277 return rc;
279 if (!rc.fromXml(xmls.at(idx), &errorMessage)) {
280 rc.clear();
282 }
283 return rc;
284}
285
287{
289}
290
292{
295 if (xmls.isEmpty())
296 return rc;
297 // De-serialize
300 for (const auto &xml : xmls) {
301 if (dp.fromXml(xml, &errorMessage)) {
302 rc.push_back(dp);
303 } else {
305 }
306 }
307 return rc;
308}
309
317}
318
319QT_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