There shouldn't be any radio buttons in a settings class. Settings are data.
your gui might be 2 group boxes with 3 radio buttons each, but this only represents two variables, each with 3 possible values
e.g. gui:
speed group box
- fast
- medium
- slow
size group box
- big
- medium
- small
That represents data (speed, size):
struct Config
{
};
struct Config
{
QString speed;
QString size;
};
To copy to clipboard, switch view to plain text mode
That would be held in some config store:
class IConfigSource
{
public:
virtual Config config() const;
virtual void setConfig(const Config& cfg);
};
class ConfigSource : public IConfigSource
{
public:
Config config() const {return config_;}
void setConfig(const Config& cfg) {config_ = cfg;}
private:
Config config_;
};
class IConfigSource
{
public:
virtual Config config() const;
virtual void setConfig(const Config& cfg);
};
class ConfigSource : public IConfigSource
{
public:
Config config() const {return config_;}
void setConfig(const Config& cfg) {config_ = cfg;}
private:
Config config_;
};
To copy to clipboard, switch view to plain text mode
which could be updated via something lile
{
Q_OBJECT
public:
ConfigUpdater(IConfigSource& src) : src_(src) {}
public slots:
void apply() {src_.setConfig(tempConfig);}
void cancel() (tempConfig = src_.config();)
void updateSpeed
(QString s
) {tempConfig_.
Speed = s;
} void updateSize
(QString s
) {tempConfig_.
Size = s;
}
private:
Config tempConfig_;
IConfigSource& src_
};
class ConfigUpdater : QObject
{
Q_OBJECT
public:
ConfigUpdater(IConfigSource& src) : src_(src) {}
public slots:
void apply() {src_.setConfig(tempConfig);}
void cancel() (tempConfig = src_.config();)
void updateSpeed(QString s) {tempConfig_.Speed = s;}
void updateSize(QString s) {tempConfig_.Size = s;}
private:
Config tempConfig_;
IConfigSource& src_
};
To copy to clipboard, switch view to plain text mode
Of course, still to be considered is how to deal with valid options for particular variables, but let's not do that right now...
Bookmarks