mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-04 10:43:19 +00:00
Add tags settings in UI
This commit is contained in:
parent
01037b1717
commit
e5328c15d4
10 changed files with 233 additions and 22 deletions
|
@ -197,7 +197,10 @@ void Backend::rebuildQMLTasksList()
|
|||
|
||||
QMLTags.clear();
|
||||
for (auto &tag : mirai.getTags()) {
|
||||
QMLTags.push_back(QString::fromStdString(tag));
|
||||
QMLTags.push_back({
|
||||
.name = QString::fromStdString(tag),
|
||||
.color = getTagColor(QString::fromStdString(tag)),
|
||||
});
|
||||
}
|
||||
|
||||
QMLActiveTagsFilter.clear();
|
||||
|
@ -248,3 +251,45 @@ QString Backend::getTagColor(QString tag)
|
|||
}
|
||||
return tagsConfig[tag];
|
||||
}
|
||||
|
||||
void Backend::saveTagsColor(QVariant modifiedTags)
|
||||
{
|
||||
auto aa = modifiedTags.toList();
|
||||
for (auto bb : aa) {
|
||||
auto cc = bb.toMap();
|
||||
std::cout << cc["name"].toString().toStdString() << ": "
|
||||
<< cc["color"].toString().toStdString() << std::endl;
|
||||
tagsConfig[cc["name"].toString()] = cc["color"].toString();
|
||||
}
|
||||
rebuildQMLTasksList();
|
||||
emit tagsChanged();
|
||||
emit tasksChanged();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
void Backend::saveConfig()
|
||||
{
|
||||
QJsonObject rootJson;
|
||||
|
||||
QJsonArray filesJson;
|
||||
for (auto &file : mirai.getFiles()) {
|
||||
filesJson.append(QString::fromStdString(file->getPath()));
|
||||
}
|
||||
rootJson["files"] = filesJson;
|
||||
|
||||
QJsonObject tagsJson;
|
||||
for (auto &tag : tagsConfig.keys()) {
|
||||
QJsonObject tagConfig;
|
||||
tagConfig["color"] = getTagColor(tag);
|
||||
tagsJson[tag] = tagConfig;
|
||||
}
|
||||
rootJson["tags"] = tagsJson;
|
||||
|
||||
QFile configFile(QDir::homePath() + "/.config/mirai/config.json");
|
||||
if (!configFile.open(QIODevice::WriteOnly)) {
|
||||
qWarning() << "Cannot save config";
|
||||
return;
|
||||
}
|
||||
configFile.write(QJsonDocument(rootJson).toJson());
|
||||
configFile.close();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue