Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions cmake/DtkTools/DtkDConfigMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function(dtk_add_config_to_cpp OUTPUT_VAR JSON_FILE)
cmake_parse_arguments(
"arg"
""
"OUTPUT_FILE_NAME;CLASS_NAME;USE_QPROPERTY;GET_IS_DEFAULT_VALUE"
"OUTPUT_FILE_NAME;CLASS_NAME;USE_QPROPERTY"
""
${ARGN}
)
Expand Down Expand Up @@ -45,16 +45,10 @@ function(dtk_add_config_to_cpp OUTPUT_VAR JSON_FILE)
set(USE_QPROPERTY_ARG "")
endif()

if (arg_GET_IS_DEFAULT_VALUE)
set(GET_IS_DEFAULT_VALUE_ARG "--get-is-default-value")
else()
set(GET_IS_DEFAULT_VALUE_ARG "")
endif()

# Add a custom command to run dconfig2cpp
add_custom_command(
OUTPUT ${OUTPUT_HEADER}
COMMAND ${DTK_DCONFIG2CPP} -o ${OUTPUT_HEADER} ${CLASS_NAME_ARG} ${USE_QPROPERTY_ARG} ${GET_IS_DEFAULT_VALUE_ARG} ${JSON_FILE}
COMMAND ${DTK_DCONFIG2CPP} -o ${OUTPUT_HEADER} ${CLASS_NAME_ARG} ${USE_QPROPERTY_ARG} ${JSON_FILE}
DEPENDS ${JSON_FILE} ${DTK_XML2CPP}
COMMENT "Generating ${OUTPUT_HEADER} from ${JSON_FILE}"
VERBATIM
Expand Down
58 changes: 45 additions & 13 deletions src/log/dconfig_org_deepin_dtk_preference.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This file is generated by dconfig2cpp.
* Command line arguments: /home/zccrs/projects/dtkcore/build/unknown-Debug/tools/dconfig2cpp/dconfig2cpp --get-is-default-value /home/zccrs/projects/dtkcommon/configs/org.deepin.dtk.preference.json
* Generation time: 2025-02-20T19:16:13
* Command line arguments: /home/zccrs/projects/dtkcore/build/unknown-Debug/tools/dconfig2cpp/dconfig2cpp /home/zccrs/projects/dtkcommon/configs/org.deepin.dtk.preference.json
* Generation time: 2025-02-21T13:49:21
* JSON file version: 1.0
*
* WARNING: DO NOT MODIFY THIS FILE MANUALLY.
Expand All @@ -28,6 +28,10 @@
Q_PROPERTY(qlonglong themeType READ themeType WRITE setThemeType NOTIFY themeTypeChanged RESET resetThemeType)
Q_PROPERTY(qlonglong titlebarHeight READ titlebarHeight WRITE setTitlebarHeight NOTIFY titlebarHeightChanged RESET resetTitlebarHeight)
Q_PROPERTY(bool underlineShortcut READ underlineShortcut WRITE setUnderlineShortcut NOTIFY underlineShortcutChanged RESET resetUnderlineShortcut)
Q_CLASSINFO("DConfigKeyList", "autoDisplayFeature;featureUpdated;keyboardsearchDisabled;rules;themeType;titlebarHeight;underlineShortcut")
Q_CLASSINFO("DConfigFileName", "org.deepin.dtk.preference")
Q_CLASSINFO("DConfigFileVersion", "1.0")

public:
explicit dconfig_org_deepin_dtk_preference(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId, const QString &subpath, QObject *parent)
: QObject(parent) {
Expand Down Expand Up @@ -76,22 +80,50 @@
}
}

DTK_CORE_NAMESPACE::DConfig *config() const {
Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const {

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function

Check warning on line 83 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'config' shadows outer function
return m_config.loadRelaxed();
}

bool isInitializeSucceed() const {
Q_INVOKABLE bool isInitializeSucceed() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Succeed);
}

bool isInitializeFailed() const {
Q_INVOKABLE bool isInitializeFailed() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Failed);
}

bool isInitializing() const {
Q_INVOKABLE bool isInitializing() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Invalid);
}

Q_INVOKABLE QStringList keyList() const {
return { QStringLiteral(u"\u0061\u0075\u0074\u006f\u0044\u0069\u0073\u0070\u006c\u0061\u0079\u0046\u0065\u0061\u0074\u0075\u0072\u0065"),
QStringLiteral(u"\u0066\u0065\u0061\u0074\u0075\u0072\u0065\u0055\u0070\u0064\u0061\u0074\u0065\u0064"),
QStringLiteral(u"\u006b\u0065\u0079\u0062\u006f\u0061\u0072\u0064\u0073\u0065\u0061\u0072\u0063\u0068\u0044\u0069\u0073\u0061\u0062\u006c\u0065\u0064"),
QStringLiteral(u"\u0072\u0075\u006c\u0065\u0073"),
QStringLiteral(u"\u0074\u0068\u0065\u006d\u0065\u0054\u0079\u0070\u0065"),
QStringLiteral(u"\u0074\u0069\u0074\u006c\u0065\u0062\u0061\u0072\u0048\u0065\u0069\u0067\u0068\u0074"),
QStringLiteral(u"\u0075\u006e\u0064\u0065\u0072\u006c\u0069\u006e\u0065\u0053\u0068\u006f\u0072\u0074\u0063\u0075\u0074")};
}

Q_INVOKABLE bool isDefaultValue(const QString &key) const {
if (key == QStringLiteral(u"\u0061\u0075\u0074\u006f\u0044\u0069\u0073\u0070\u006c\u0061\u0079\u0046\u0065\u0061\u0074\u0075\u0072\u0065"))
return autoDisplayFeatureIsDefaultValue();
if (key == QStringLiteral(u"\u0066\u0065\u0061\u0074\u0075\u0072\u0065\u0055\u0070\u0064\u0061\u0074\u0065\u0064"))
return featureUpdatedIsDefaultValue();
if (key == QStringLiteral(u"\u006b\u0065\u0079\u0062\u006f\u0061\u0072\u0064\u0073\u0065\u0061\u0072\u0063\u0068\u0044\u0069\u0073\u0061\u0062\u006c\u0065\u0064"))
return keyboardsearchDisabledIsDefaultValue();
if (key == QStringLiteral(u"\u0072\u0075\u006c\u0065\u0073"))
return rulesIsDefaultValue();
if (key == QStringLiteral(u"\u0074\u0068\u0065\u006d\u0065\u0054\u0079\u0070\u0065"))
return themeTypeIsDefaultValue();
if (key == QStringLiteral(u"\u0074\u0069\u0074\u006c\u0065\u0062\u0061\u0072\u0048\u0065\u0069\u0067\u0068\u0074"))
return titlebarHeightIsDefaultValue();
if (key == QStringLiteral(u"\u0075\u006e\u0064\u0065\u0072\u006c\u0069\u006e\u0065\u0053\u0068\u006f\u0072\u0074\u0063\u0075\u0074"))
return underlineShortcutIsDefaultValue();
return false;
}

bool autoDisplayFeature() const {
return p_autoDisplayFeature;
}
Expand All @@ -116,7 +148,7 @@
});
}
}
bool autoDisplayFeatureIsDefaultValue() const {
Q_INVOKABLE bool autoDisplayFeatureIsDefaultValue() const {
return !testPropertySet(0);
}
bool featureUpdated() const {
Expand All @@ -143,7 +175,7 @@
});
}
}
bool featureUpdatedIsDefaultValue() const {
Q_INVOKABLE bool featureUpdatedIsDefaultValue() const {
return !testPropertySet(1);
}
bool keyboardsearchDisabled() const {
Expand All @@ -170,7 +202,7 @@
});
}
}
bool keyboardsearchDisabledIsDefaultValue() const {
Q_INVOKABLE bool keyboardsearchDisabledIsDefaultValue() const {
return !testPropertySet(2);
}
QString rules() const {
Expand All @@ -197,7 +229,7 @@
});
}
}
bool rulesIsDefaultValue() const {
Q_INVOKABLE bool rulesIsDefaultValue() const {
return !testPropertySet(3);
}
qlonglong themeType() const {
Expand All @@ -224,7 +256,7 @@
});
}
}
bool themeTypeIsDefaultValue() const {
Q_INVOKABLE bool themeTypeIsDefaultValue() const {
return !testPropertySet(4);
}
qlonglong titlebarHeight() const {
Expand All @@ -251,7 +283,7 @@
});
}
}
bool titlebarHeightIsDefaultValue() const {
Q_INVOKABLE bool titlebarHeightIsDefaultValue() const {
return !testPropertySet(5);
}
bool underlineShortcut() const {
Expand All @@ -278,7 +310,7 @@
});
}
}
bool underlineShortcutIsDefaultValue() const {
Q_INVOKABLE bool underlineShortcutIsDefaultValue() const {
return !testPropertySet(6);
}
Q_SIGNALS:
Expand Down
48 changes: 32 additions & 16 deletions tools/dconfig2cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ int main(int argc, char *argv[]) {
QLatin1String("Force request thread to create DConfig instance"));
parser.addOption(forceRequestThread);

QCommandLineOption getIsDefaultValue(QStringList() << QLatin1String("get-is-default-value"),
QLatin1String("Generate *IsDefaultValue method"));
parser.addOption(getIsDefaultValue);

QCommandLineOption noComment(QStringList() << QLatin1String("no-comment"),
QLatin1String("Do not generate comments in the generated code"));
parser.addOption(noComment);
Expand Down Expand Up @@ -189,15 +185,19 @@ int main(int argc, char *argv[]) {
QJsonValue defaultValue;
};
QList<Property> properties;
QStringList propertyNames;
QStringList propertyNameStrings;

static QStringList usedKeywords = {
className,
"create",
"createByName",
"config",
"keyList",
"isInitializeSucceed",
"isInitializeFailed",
"isInitializing",
"isDefaultValue",
"m_config",
"m_status",
};
Expand Down Expand Up @@ -232,21 +232,27 @@ int main(int argc, char *argv[]) {
capitalizedPropertyName[0] = capitalizedPropertyName[0].toUpper();
}

propertyNames << propertyName;
properties.append(Property({
typeName,
propertyName,
capitalizedPropertyName,
"QStringLiteral(u\"" + toUnicodeEscape(propertyName) + "\")",
obj[QLatin1String("value")]
}));
propertyNameStrings << properties.last().propertyNameString;

const QString readFunction = usedKeywords.contains(propertyName) ? QLatin1String(" READ get") + capitalizedPropertyName
: QLatin1String(" READ ") + propertyName;
headerStream << " Q_PROPERTY(" << typeName << " " << propertyName << readFunction
<< " WRITE set" << capitalizedPropertyName << " NOTIFY " << propertyName << "Changed"
<< " RESET reset" << capitalizedPropertyName << ")\n";
}
headerStream << "public:\n"

headerStream << " Q_CLASSINFO(\"DConfigKeyList\", \"" << propertyNames.join(";") <<"\")\n"
<< " Q_CLASSINFO(\"DConfigFileName\", \"" << QString(jsonFileName).replace("\n", "\\n").replace("\r", "\\r") <<"\")\n"
<< " Q_CLASSINFO(\"DConfigFileVersion\", \"" << version <<"\")\n\n"
<< "public:\n"
<< " explicit " << className
<< R"((QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId, const QString &subpath, QObject *parent)
: QObject(parent) {
Expand Down Expand Up @@ -313,24 +319,36 @@ int main(int argc, char *argv[]) {
}
}

DTK_CORE_NAMESPACE::DConfig *config() const {
Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const {
return m_config.loadRelaxed();
}

bool isInitializeSucceed() const {
Q_INVOKABLE bool isInitializeSucceed() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Succeed);
}

bool isInitializeFailed() const {
Q_INVOKABLE bool isInitializeFailed() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Failed);
}

bool isInitializing() const {
Q_INVOKABLE bool isInitializing() const {
return m_status.loadRelaxed() == static_cast<int>(Status::Invalid);
}

)";

headerStream << " Q_INVOKABLE QStringList keyList() const {\n"
<< " return { " << propertyNameStrings.join(",\n ") << "};\n"
<< " }\n\n";

headerStream << " Q_INVOKABLE bool isDefaultValue(const QString &key) const {\n";
for (int i = 0; i < properties.size(); ++i) {
headerStream << " if (key == " << properties.at(i).propertyNameString << ")\n"
<< " return " << properties.at(i).propertyName << "IsDefaultValue();\n";
}
headerStream << " return false;\n"
<< " }\n\n";

// Generate property getter and setter methods
for (int i = 0; i < properties.size(); ++i) {
const Property &property = properties[i];
Expand Down Expand Up @@ -367,11 +385,10 @@ int main(int argc, char *argv[]) {
<< " return QBindable<" << property.typeName << ">(this, " << property.propertyNameString << ");\n"
<< " }\n";
}
if (parser.isSet(getIsDefaultValue)) {
headerStream << " bool " << property.propertyName << "IsDefaultValue() const {\n"
<< " return !testPropertySet(" << i << ");\n"
<< " }\n";
}

headerStream << " Q_INVOKABLE bool " << property.propertyName << "IsDefaultValue() const {\n"
<< " return !testPropertySet(" << i << ");\n"
<< " }\n";
}

// Generate signals for property changes
Expand Down Expand Up @@ -418,8 +435,7 @@ int main(int argc, char *argv[]) {
const Property &property = properties.at(i);
headerStream << " if (key == " << property.propertyNameString << ") {\n";

if (parser.isSet(getIsDefaultValue))
headerStream << " markPropertySet(" << i << ", !m_config.loadRelaxed()->isDefaultValue(key));\n";
headerStream << " markPropertySet(" << i << ", !m_config.loadRelaxed()->isDefaultValue(key));\n";

headerStream << " auto newValue = qvariant_cast<" << property.typeName << ">(value);\n"
<< " QMetaObject::invokeMethod(this, [this, newValue, key, value]() {\n"
Expand Down