From f0990fae4bc6e54837764c0ded1461b9f1770401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 25 Aug 2013 22:48:41 +0200 Subject: Many improvements PermGen can be tweaked from the settings menu Groups are saved on change/exit Install target is no longer completely broken All the deplibs are now static Added notes dialog Fixed ini file format support (can save strings with newlines, tabs. UTF-8 is explicitly used!) Rename button now uses line breaks so it doesn't grow ever wider (Added a custom tool button subclass) There is now a CAT button. Meow. --- logic/lists/InstanceList.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++- logic/lists/InstanceList.h | 7 ++--- 2 files changed, 74 insertions(+), 5 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 39f55f7b..b2c9ec6d 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -36,6 +37,73 @@ InstanceList::InstanceList(const QString &instDir, QObject *parent) : } +InstanceList::~InstanceList() +{ + saveGroupList(); +} + + +void InstanceList::groupChanged() +{ + // save the groups. save all of them. + saveGroupList(); +} + +void InstanceList::saveGroupList() +{ + QString groupFileName = m_instDir + "/instgroups.json"; + QFile groupFile(groupFileName); + + // if you can't open the file, fail + if (!groupFile.open(QIODevice::WriteOnly| QIODevice::Truncate)) + { + // An error occurred. Ignore it. + qDebug("Failed to read instance group file."); + return; + } + QTextStream out(&groupFile); + QMap > groupMap; + for(auto instance: m_instances) + { + QString id = instance->id(); + QString group = instance->group(); + if(group.isEmpty()) + continue; + if(!groupMap.count(group)) + { + QSet set; + set.insert(id); + groupMap[group] = set; + } + else + { + QSet &set = groupMap[group]; + set.insert(id); + } + } + QJsonObject toplevel; + toplevel.insert("formatVersion",QJsonValue(QString("1"))); + QJsonObject groupsArr; + for(auto iter = groupMap.begin(); iter != groupMap.end(); iter++) + { + auto list = iter.value(); + auto name = iter.key(); + QJsonObject groupObj; + QJsonArray instanceArr; + groupObj.insert("hidden",QJsonValue(QString("false"))); + for(auto item: list) + { + instanceArr.append(QJsonValue(item)); + } + groupObj.insert("instances",instanceArr); + groupsArr.insert(name,groupObj); + } + toplevel.insert("groups",groupsArr); + QJsonDocument doc(toplevel); + groupFile.write(doc.toJson(QJsonDocument::Indented)); + groupFile.close(); +} + void InstanceList::loadGroupList(QMap & groupMap) { QString groupFileName = m_instDir + "/instgroups.json"; @@ -176,12 +244,13 @@ InstanceList::InstListError InstanceList::loadList() auto iter = groupMap.find(inst->id()); if(iter != groupMap.end()) { - inst->setGroup((*iter)); + inst->setGroupInitial((*iter)); } qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); m_instances.append(inst); connect(instPtr, SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*))); + connect(instPtr, SIGNAL(groupChanged()),this, SLOT(groupChanged())); } } emit invalidated(); @@ -191,6 +260,7 @@ InstanceList::InstListError InstanceList::loadList() /// Clear all instances. Triggers notifications. void InstanceList::clear() { + saveGroupList(); m_instances.clear(); emit invalidated(); }; diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h index 82ef0ea4..50ba56f3 100644 --- a/logic/lists/InstanceList.h +++ b/logic/lists/InstanceList.h @@ -26,13 +26,12 @@ class InstanceList : public QObject { Q_OBJECT private: - /*! - * \brief Get the instance groups - */ void loadGroupList(QMap & groupList); + void saveGroupList(); public: explicit InstanceList(const QString &instDir, QObject *parent = 0); + virtual ~InstanceList(); /*! * \brief Error codes returned by functions in the InstanceList class. @@ -84,7 +83,7 @@ signals: private slots: void propertiesChanged(BaseInstance * inst); - + void groupChanged(); protected: QString m_instDir; QList< InstancePtr > m_instances; -- cgit v1.2.3