add formatters configuration to ui

This commit is contained in:
2016-05-18 12:46:50 +03:00
parent 906ad56c46
commit f717c984b7
14 changed files with 128 additions and 50 deletions

View File

@ -90,6 +90,31 @@ QStringList AWFormatterHelper::knownFormatters() const
}
bool AWFormatterHelper::writeFormatters(const QStringList keys) const
{
qCDebug(LOG_AW) << "Remove formatters" << keys;
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
QSettings settings(fileName, QSettings::IniFormat);
qCInfo(LOG_AW) << "Configuration file" << fileName;
settings.beginGroup(QString("Formatters"));
QStringList foundKeys = settings.childKeys();
for (auto key : foundKeys) {
if (keys.contains(key))
continue;
settings.remove(key);
}
settings.endGroup();
settings.sync();
return (settings.status() == QSettings::NoError);
}
bool AWFormatterHelper::writeFormatters(
const QHash<QString, QString> configuration) const
{
@ -112,6 +137,14 @@ bool AWFormatterHelper::writeFormatters(
}
void AWFormatterHelper::editItems()
{
repaintList();
int ret = exec();
qCInfo(LOG_AW) << "Dialog returns" << ret;
}
AWFormatterHelper::FormatterClass
AWFormatterHelper::defineFormatterClass(const QString stringType) const
{
@ -193,9 +226,14 @@ void AWFormatterHelper::initKeys()
QString name = settings.value(key).toString();
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
<< "in" << settings.fileName();
if (name.isEmpty()) {
qCInfo(LOG_AW) << "Skip empty formatter for" << key;
continue;
}
if (!m_formattersClasses.contains(name)) {
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
<< key;
continue;
}
m_formatters[key] = m_formattersClasses[name];
}