Refactor config into generic key-value base class and settings-specific child class

This commit is contained in:
Marcus Huderle
2018-12-25 14:41:06 -06:00
parent 7758124235
commit 525ef8c67c
3 changed files with 122 additions and 93 deletions

View File

@@ -9,25 +9,46 @@ enum MapSortOrder {
Layout = 2,
};
class Config
class KeyValueConfigBase
{
public:
static void save();
static void load();
static void setRecentProject(QString project);
static void setRecentMap(QString map);
static void setMapSortOrder(MapSortOrder order);
static void setPrettyCursors(bool enabled);
static QString getRecentProject();
static QString getRecentMap();
static MapSortOrder getMapSortOrder();
static bool getPrettyCursors();
private:
static void parseConfigKeyValue(QString key, QString value);
static QString recentProject;
static QString recentMap;
static MapSortOrder mapSortOrder;
static bool prettyCursors;
void save();
void load();
virtual ~KeyValueConfigBase();
protected:
QString configFilename;
virtual void parseConfigKeyValue(QString key, QString value) = 0;
virtual QMap<QString, QString> getKeyValueMap() = 0;
};
class PorymapConfig: public KeyValueConfigBase
{
public:
PorymapConfig() {
this->configFilename = "porymap.cfg";
this->recentProject = "";
this->recentMap = "";
this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true;
}
void setRecentProject(QString project);
void setRecentMap(QString map);
void setMapSortOrder(MapSortOrder order);
void setPrettyCursors(bool enabled);
QString getRecentProject();
QString getRecentMap();
MapSortOrder getMapSortOrder();
bool getPrettyCursors();
protected:
void parseConfigKeyValue(QString key, QString value);
QMap<QString, QString> getKeyValueMap();
private:
QString recentProject;
QString recentMap;
MapSortOrder mapSortOrder;
bool prettyCursors;
};
extern PorymapConfig porymapConfig;
#endif // CONFIG_H