added some doc and moved code out of utils

This commit is contained in:
Patrick von Reth 2015-07-05 12:24:59 +02:00
parent b08310d869
commit 884363e67f
5 changed files with 45 additions and 22 deletions

View File

@ -58,8 +58,19 @@ public:
virtual bool deinitialize();
bool isInitialized() const;
/**
* Returns the name of the plugin.
*/
const QString &name() const;
/**
* Returns the plugin type.
*/
PluginTypes type() const;
/**
* Returns the name of the plugin type.
*/
const QString typeName() const;
QVariant settingsValue(const QString &key, SettingsType type = GLOBAL_SETTING) const;
@ -69,6 +80,9 @@ public:
virtual PluginSettingsWidget *settingsWidget();
protected:
/**
* Returns the version suffix used for the plugin settings.
*/
virtual QString settingsVersion() const;
private:

View File

@ -102,9 +102,7 @@ public:
Q_INVOKABLE static void raiseWindowToFront(qlonglong wid);
/**
*
* @param string A string to encode if needed.
* @return if the string was rhichtext html encode string is returnd otherwise the original string.
* Removes unsupported markup tags from a string.
*/
static QString normalizeMarkup(QString string, MARKUP_FLAGS tags);
@ -116,11 +114,20 @@ public:
return QString::fromUtf8(QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex());
}
/**
* Version number prefix for the settings.
*/
static inline QString settingsVersionSchema()
{
return QLatin1String("v1");
}
/**
* Returns the SettingsKey formated with type and version.
* @param key The key.
* @param type The Type.
* @param application The application's name.
*/
static inline QString normalizeSettingsKey(const QString &key, SettingsType type, const QString &application)
{
if (type == LOCAL_SETTING) {
@ -130,23 +137,6 @@ public:
}
}
template<typename Func>
static QStringList allSettingsKeysWithPrefix(const QString &prefix, QSettings &settings, Func fun)
{
QStringList groups = prefix.split(QLatin1Char('/'));
QStringList out;
for (const QString group : groups) {
settings.beginGroup(group);
}
out = fun(settings);
for (int i = 0; i < groups.size(); ++i) {
settings.endGroup();
}
return out;
}
private:
#ifdef Q_OS_WIN
static int attatchToActiveProcess();

View File

@ -44,7 +44,7 @@ void listSettings(SettingsType type, const QString &application)
};
cout << qPrintable(application) << endl;
for (const QString &key : Utils::allSettingsKeysWithPrefix(
for (const QString &key : SettingsWindow::allSettingsKeysWithPrefix(
Utils::normalizeSettingsKey(QLatin1String(""), type, application), settings, getAllKeys)) {
cout << " " << qPrintable(key) << ": " << qPrintable(settings.value(Utils::normalizeSettingsKey(key, type, application)).toString()) << endl;
}

View File

@ -31,7 +31,7 @@ SettingsWindow::~SettingsWindow()
QStringList SettingsWindow::knownApps()
{
return Utils::allSettingsKeysWithPrefix(Utils::settingsVersionSchema() + QLatin1String("/LocalSettings"), settings(),
return allSettingsKeysWithPrefix(Utils::settingsVersionSchema() + QLatin1String("/LocalSettings"), settings(),
[](QSettings & settings) {
return settings.childGroups();
});

View File

@ -23,6 +23,25 @@ public:
static QSettings &settings();
template<typename Func>
static QStringList allSettingsKeysWithPrefix(const QString &prefix, QSettings &settings, Func fun)
{
QStringList groups = prefix.split(QLatin1Char('/'));
QStringList out;
for (const QString group : groups) {
settings.beginGroup(group);
}
out = fun(settings);
for (int i = 0; i < groups.size(); ++i) {
settings.endGroup();
}
return out;
}
private Q_SLOTS:
void on_buttonBox_clicked(QAbstractButton *button);
void on_comboBox_currentIndexChanged(const QString &arg1);