|
a/utils/confgui.h |
|
b/utils/confgui.h |
1 |
/* Copyright (C) 2007-2016 J.F.Dockes
|
1 |
/* Copyright (C) 2007-2018 J.F.Dockes
|
2 |
* This program is free software; you can redistribute it and/or modify
|
2 |
* This program is free software; you can redistribute it and/or modify
|
3 |
* it under the terms of the GNU General Public License as published by
|
3 |
* it under the terms of the GNU General Public License as published by
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
5 |
* (at your option) any later version.
|
5 |
* (at your option) any later version.
|
6 |
*
|
6 |
*
|
|
... |
|
... |
33 |
*
|
33 |
*
|
34 |
* The widgets are typically linked to a temporary configuration object, which
|
34 |
* The widgets are typically linked to a temporary configuration object, which
|
35 |
* is then copied to the actual configuration if the data is accepted, or
|
35 |
* is then copied to the actual configuration if the data is accepted, or
|
36 |
* destroyed and recreated as a copy if Cancel is pressed (you have to
|
36 |
* destroyed and recreated as a copy if Cancel is pressed (you have to
|
37 |
* delete/recreate the widgets in this case as the links are no longer valid).
|
37 |
* delete/recreate the widgets in this case as the links are no longer valid).
|
|
|
38 |
*
|
|
|
39 |
* The set() methods of the link objects are only called if the
|
|
|
40 |
* current value() differs from the value obtained by get() when the
|
|
|
41 |
* object was initialized. This can be used to avoid cluttering the
|
|
|
42 |
* output with values which are unmodified from the defaults.
|
|
|
43 |
*
|
|
|
44 |
* The file also defines a multi-tabbed dialog container for the
|
|
|
45 |
* parameter objects, with simple interface methods to create/add
|
|
|
46 |
* panels and elements.
|
38 |
*/
|
47 |
*/
|
39 |
|
48 |
|
40 |
#include <string>
|
49 |
#include <string>
|
41 |
#include <limits.h>
|
50 |
#include <limits.h>
|
42 |
|
51 |
|
|
... |
|
... |
83 |
virtual ~ConfPanelWIF() {}
|
92 |
virtual ~ConfPanelWIF() {}
|
84 |
virtual void storeValues() = 0;
|
93 |
virtual void storeValues() = 0;
|
85 |
virtual void loadValues() = 0;
|
94 |
virtual void loadValues() = 0;
|
86 |
};
|
95 |
};
|
87 |
|
96 |
|
88 |
/** The top level widget has tabs, each tab/panel has multiple widgets
|
|
|
89 |
* for setting parameter values
|
|
|
90 |
*/
|
|
|
91 |
class ConfPanelW;
|
97 |
class ConfPanelW;
|
92 |
class ConfParamW;
|
98 |
class ConfParamW;
|
|
|
99 |
|
|
|
100 |
/** The top level widget has tabs, each tab/panel has multiple widgets
|
|
|
101 |
* for setting parameter values */
|
93 |
class ConfTabsW : public QDialog {
|
102 |
class ConfTabsW : public QDialog {
|
94 |
Q_OBJECT;
|
103 |
Q_OBJECT;
|
95 |
|
104 |
|
96 |
public:
|
105 |
public:
|
97 |
ConfTabsW(QWidget *parent, const QString& title, ConfLinkFact *linkfact);
|
106 |
ConfTabsW(QWidget *parent, const QString& title, ConfLinkFact *linkfact);
|
98 |
|
107 |
|
99 |
enum ParamType {CFPT_BOOL, CFPT_INT, CFPT_STR, CFPT_CSTR, CFPT_FN,
|
108 |
enum ParamType {CFPT_BOOL, CFPT_INT, CFPT_STR, CFPT_CSTR, CFPT_FN,
|
100 |
CFPT_STRL, CFPT_DNL, CFPT_CSTRL
|
109 |
CFPT_STRL, CFPT_DNL, CFPT_CSTRL
|
101 |
};
|
110 |
};
|
102 |
|
111 |
|
103 |
/** Add tab and return its identifier / index */
|
112 |
/** Add tab and return its identifier / index */
|
104 |
int addPanel(const QString& title);
|
113 |
int addPanel(const QString& title);
|
105 |
|
114 |
|
106 |
/** Add foreign tab where we only know to call loadvalues/storevalues.
|
115 |
/** Add foreign tab where we only know to call loadvalues/storevalues.
|
|
... |
|
... |
112 |
const QString& varname, const QString& label,
|
121 |
const QString& varname, const QString& label,
|
113 |
const QString& tooltip, int isdirorminval = 0,
|
122 |
const QString& tooltip, int isdirorminval = 0,
|
114 |
int maxval = 0, const QStringList* sl = 0);
|
123 |
int maxval = 0, const QStringList* sl = 0);
|
115 |
bool enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert = false);
|
124 |
bool enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert = false);
|
116 |
void endOfList(int tabindex);
|
125 |
void endOfList(int tabindex);
|
|
|
126 |
|
|
|
127 |
/** Find param widget associated with given variable name */
|
117 |
ConfParamW *findParamW(const QString& varname);
|
128 |
ConfParamW *findParamW(const QString& varname);
|
118 |
|
129 |
|
|
|
130 |
void hideButtons();
|
|
|
131 |
|
119 |
public slots:
|
132 |
public slots:
|
120 |
void acceptChanges();
|
133 |
void acceptChanges();
|
121 |
void rejectChanges();
|
134 |
void rejectChanges();
|
122 |
void reloadPanels();
|
135 |
void reloadPanels();
|
123 |
void setCurrentIndex(int);
|
136 |
void setCurrentIndex(int);
|
124 |
|
137 |
|
125 |
signals:
|
138 |
signals:
|
|
|
139 |
/** This is emitted when acceptChanges() is called, after the
|
|
|
140 |
* values have been stored */
|
126 |
void sig_prefsChanged();
|
141 |
void sig_prefsChanged();
|
127 |
|
142 |
|
128 |
private:
|
143 |
private:
|
129 |
ConfLinkFact *m_makelink;
|
144 |
ConfLinkFact *m_makelink{nullptr};
|
130 |
std::vector<ConfPanelW *> m_panels;
|
145 |
std::vector<ConfPanelW *> m_panels;
|
131 |
// "Foreign" panels
|
146 |
// "Foreign" panels
|
132 |
std::vector<ConfPanelWIF *> m_widgets;
|
147 |
std::vector<ConfPanelWIF *> m_widgets;
|
133 |
// All params
|
148 |
// All params
|
134 |
std::vector<ConfParamW *> m_params;
|
149 |
std::vector<ConfParamW *> m_params;
|
135 |
QTabWidget *tabWidget;
|
150 |
QTabWidget *tabWidget{nullptr};
|
136 |
QDialogButtonBox *buttonBox;
|
151 |
QDialogButtonBox *buttonBox{nullptr};
|
137 |
};
|
152 |
};
|
138 |
|
153 |
|
139 |
/////////////////////////////////////////////////
|
154 |
/////////////////////////////////////////////////
|
140 |
// All the rest could be moved to the C++ file ?
|
155 |
// The rest of the class definitions are only useful if you need to
|
|
|
156 |
// access a specific element for customisation (use findParamW() and a
|
|
|
157 |
// dynamic cast).
|
141 |
|
158 |
|
142 |
/** A panel/tab contains multiple controls for parameters */
|
159 |
/** A panel/tab contains multiple controls for parameters */
|
143 |
class ConfPanelW : public QWidget {
|
160 |
class ConfPanelW : public QWidget {
|
144 |
Q_OBJECT
|
161 |
Q_OBJECT
|
145 |
public:
|
162 |
public:
|
|
... |
|
... |
373 |
* <grouptitle>MPD parameters</grouptitle>
|
390 |
* <grouptitle>MPD parameters</grouptitle>
|
374 |
* <var name="mpdhost" type="string">
|
391 |
* <var name="mpdhost" type="string">
|
375 |
* <brief>Host MPD runs on.</brief>
|
392 |
* <brief>Host MPD runs on.</brief>
|
376 |
* <descr>Defaults to localhost. This can also be specified as -h</descr>
|
393 |
* <descr>Defaults to localhost. This can also be specified as -h</descr>
|
377 |
* </var>
|
394 |
* </var>
|
|
|
395 |
* mpdhost = default-host
|
378 |
* <var name="mpdport" type="int" values="0 65635 6600">
|
396 |
* <var name="mpdport" type="int" values="0 65635 6600">
|
379 |
* <brief>IP port used by MPD</brief>.
|
397 |
* <brief>IP port used by MPD</brief>.
|
380 |
* <descr>Can also be specified as -p port. Defaults to the...</descr>
|
398 |
* <descr>Can also be specified as -p port. Defaults to the...</descr>
|
381 |
* </var>
|
399 |
* </var>
|
|
|
400 |
* mpdport = defport
|
382 |
* <var name="ownqueue" type="bool" values="1">
|
401 |
* <var name="ownqueue" type="bool" values="1">
|
383 |
* <brief>Set if we own the MPD queue.</brief>
|
402 |
* <brief>Set if we own the MPD queue.</brief>
|
384 |
* <descr>If this is set (on by default), we own the MPD...</descr>
|
403 |
* <descr>If this is set (on by default), we own the MPD...</descr>
|
385 |
* </var>
|
404 |
* </var>
|
|
|
405 |
* ownqueue =
|
386 |
* </confcomments>
|
406 |
* </confcomments>
|
387 |
*
|
407 |
*
|
388 |
* <grouptitle> creates a panel in which the following <var> are set.
|
408 |
* <grouptitle> creates a panel in which the following <var> are set.
|
389 |
* The <var> attributes should be self-explanatory. "values"
|
409 |
* The <var> attributes should be self-explanatory. "values"
|
390 |
* is used for different things depending on the var type
|
410 |
* is used for different things depending on the var type
|
|
... |
|
... |
396 |
*
|
416 |
*
|
397 |
* This means that the reference configuration file can generate both
|
417 |
* This means that the reference configuration file can generate both
|
398 |
* the documentation and the GUI interface.
|
418 |
* the documentation and the GUI interface.
|
399 |
*
|
419 |
*
|
400 |
* @param xml the input xml
|
420 |
* @param xml the input xml
|
401 |
* @param toptxt on output: the top level text. This will be evaluated
|
421 |
* @param[output] toptxt the top level XML text (text not inside <var>,
|
|
|
422 |
* normally commented variable assignments). This will be evaluated
|
402 |
* as a config for default values.
|
423 |
* as a config for default values.
|
403 |
* @lnkf factory to create the objects which link the GUI to the
|
424 |
* @lnkf factory to create the objects which link the GUI to the
|
404 |
* storage mechanism.
|
425 |
* storage mechanism.
|
405 |
*/
|
426 |
*/
|
406 |
extern ConfTabsW *xmlToConfGUI(const std::string& xml,
|
427 |
extern ConfTabsW *xmlToConfGUI(const std::string& xml,
|