Parent: [2456f5] (diff)

Child: [c80095] (diff)

Download this file

confgui.h    194 lines (168 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef _confgui_h_included_
#define _confgui_h_included_
/* @(#$Id: confgui.h,v 1.4 2007-10-01 06:35:31 dockes Exp $ (C) 2007 J.F.Dockes */
#include <string>
#include <qglobal.h>
#include <qstring.h>
#include <qwidget.h>
#if QT_VERSION < 0x040000
#define QHBOXLAYOUT QHBoxLayout
#define QLISTBOX QListBox
#else
#define QHBOXLAYOUT Q3HBoxLayout
#define QLISTBOX Q3ListBox
#endif
#include "refcntr.h"
using std::string;
class QHBOXLAYOUT;
class QLineEdit;
class QLISTBOX;
class RclConfig;
class QSpinBox;
class QComboBox;
class QCheckBox;
namespace confgui {
// A class to isolate the gui widget from the config storage mechanism
class ConfLinkRep {
public:
virtual ~ConfLinkRep() {}
virtual bool set(const string& val) = 0;
virtual bool get(string& val) = 0;
};
typedef RefCntr<ConfLinkRep> ConfLink;
class ConfLinkNullRep : public ConfLinkRep {
public:
virtual ~ConfLinkNullRep() {}
virtual bool set(const string&)
{
//fprintf(stderr, "Setting value to [%s]\n", val.c_str());
return true;
}
virtual bool get(string& val) {val = ""; return true;}
};
// A widget to let the user change one configuration
// parameter. Subclassed for specific parameter types
class ConfParamW : public QWidget {
Q_OBJECT
public:
ConfParamW(QWidget *parent, ConfLink cflink)
: QWidget(parent), m_cflink(cflink)
{
}
virtual void loadValue() = 0;
protected:
ConfLink m_cflink;
QHBOXLAYOUT *m_hl;
virtual bool createCommon(const QString& lbltxt,
const QString& tltptxt);
protected slots:
void setValue(const QString& newvalue);
void setValue(int newvalue);
void setValue(bool newvalue);
};
// Widgets for setting the different types of configuration parameters:
// Int
class ConfParamIntW : public ConfParamW {
public:
ConfParamIntW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt,
int minvalue = INT_MIN,
int maxvalue = INT_MAX);
virtual void loadValue();
protected:
QSpinBox *m_sb;
};
// Arbitrary string
class ConfParamStrW : public ConfParamW {
public:
ConfParamStrW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt);
virtual void loadValue();
protected:
QLineEdit *m_le;
};
// Constrained string: choose from list
class ConfParamCStrW : public ConfParamW {
public:
ConfParamCStrW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt, const QStringList& sl);
virtual void loadValue();
protected:
QComboBox *m_cmb;
};
// Boolean
class ConfParamBoolW : public ConfParamW {
public:
ConfParamBoolW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt);
virtual void loadValue();
protected:
QCheckBox *m_cb;
};
// File name
class ConfParamFNW : public ConfParamW {
Q_OBJECT
public:
ConfParamFNW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt, bool isdir = false);
virtual void loadValue();
protected slots:
void showBrowserDialog();
protected:
QLineEdit *m_le;
bool m_isdir;
};
// String list
class ConfParamSLW : public ConfParamW {
Q_OBJECT
public:
ConfParamSLW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt);
virtual void loadValue();
QLISTBOX *getListBox() {return m_lb;}
protected slots:
virtual void showInputDialog();
void deleteSelected();
signals:
void entryDeleted(QString);
protected:
QLISTBOX *m_lb;
void listToConf();
};
// Dir name list
class ConfParamDNLW : public ConfParamSLW {
Q_OBJECT
public:
ConfParamDNLW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt)
: ConfParamSLW(parent, cflink, lbltxt, tltptxt)
{
}
protected slots:
virtual void showInputDialog();
};
// Constrained string list (chose from predefined)
class ConfParamCSLW : public ConfParamSLW {
Q_OBJECT
public:
ConfParamCSLW(QWidget *parent, ConfLink cflink,
const QString& lbltxt,
const QString& tltptxt,
const QStringList& sl)
: ConfParamSLW(parent, cflink, lbltxt, tltptxt), m_sl(sl)
{
}
protected slots:
virtual void showInputDialog();
protected:
const QStringList m_sl;
};
}
#endif /* _confgui_h_included_ */