gwenhywfar 5.14.1
qt5/w_listbox.cpp
Go to the documentation of this file.
1/***************************************************************************
2 begin : Mon Feb 15 2010
3 copyright : (C) 2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10
11#include <gwen-gui-cpp/cppwidget.hpp>
12
13
15public:
18
19
20
23
24
25
26 virtual int setup() {
27 QTreeWidget *qw;
28 uint32_t flags;
29 GWEN_WIDGET *wParent;
30 QSizePolicy::Policy hpolicy=QSizePolicy::Minimum;
31 QSizePolicy::Policy vpolicy=QSizePolicy::Minimum;
32 QT5_GuiDialog *qtDialog;
33
35 wParent=GWEN_Widget_Tree_GetParent(_widget);
36
37 qw=new QTreeWidget();
38 qw->setAllColumnsShowFocus(true);
39 qw->setSortingEnabled(true);
40 qw->setRootIsDecorated(false);
41 qw->setItemsExpandable(false);
42 qw->setSelectionBehavior(QAbstractItemView::SelectRows);
43
44 /* handle flags */
45 if (flags & GWEN_WIDGET_FLAGS_FILLX)
46 hpolicy=QSizePolicy::Expanding;
47 if (flags & GWEN_WIDGET_FLAGS_FILLY)
48 vpolicy=QSizePolicy::Expanding;
49 qw->setSizePolicy(hpolicy, vpolicy);
50
52
53 qtDialog=dynamic_cast<QT5_GuiDialog*>(getDialog());
54 assert(qtDialog);
55
56 qw->connect(qw, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
57 qtDialog->getMainWindow(),
58 SLOT(slotActivated()));
59
60 if (wParent)
62 return 0;
63 }
64
65
66
68 int index,
69 int value,
70 int doSignal) {
71 QTreeWidget *qw;
72
74 assert(qw);
75
76 switch(prop) {
78 qw->clear();
79 return 0;
80
82 QTreeWidgetItem *item;
83
84 item=qw->topLevelItem(index);
85
86 if (item==NULL) {
87 DBG_ERROR(GWEN_LOGDOMAIN, "Value %d out of range", value);
88 return GWEN_ERROR_INVALID;
89 }
90
91 qw->setCurrentItem(item);
92 return 0;
93 }
94
96 qw->setColumnWidth(index, value);
97 return 0;
98
100 switch(value) {
102 qw->setSelectionMode(QAbstractItemView::NoSelection);
103 return 0;
105 qw->setSelectionMode(QAbstractItemView::SingleSelection);
106 return 0;
108 qw->setSelectionMode(QAbstractItemView::ExtendedSelection);
109 return 0;
110 ;
111 }
112 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d", value);
113 return GWEN_ERROR_INVALID;
114
116 switch(value) {
118 qw->sortByColumn(-1, Qt::AscendingOrder);
119 break;
121 qw->sortByColumn(index, Qt::AscendingOrder);
122 break;
124 qw->sortByColumn(index, Qt::DescendingOrder);
125 break;
126 }
127 return 0;
128
130 int c;
131
132 c=qw->sortColumn();
133 if (c!=-1) {
134 QHeaderView *h;
135
136 h=qw->header();
137 qw->sortItems(c, h->sortIndicatorOrder());
138 }
139 return 0;
140 }
141
142 default:
143 return Qt5_W_Widget::setIntProperty(prop, index, value, doSignal);
144 }
145 };
146
147
148
150 int index,
151 int defaultValue) {
152 QTreeWidget *qw;
153
155 assert(qw);
156
157 switch(prop) {
159 QTreeWidgetItem *item;
160 int i=-1;
161
162 item=qw->currentItem();
163 while(item) {
164 item=qw->itemAbove(item);
165 i++;
166 }
167
168 return i;
169 }
170
172 return qw->columnWidth(index);
173
175 switch(qw->selectionMode()) {
176 case QAbstractItemView::NoSelection:
178 case QAbstractItemView::SingleSelection:
180 case QAbstractItemView::ExtendedSelection:
182 default:
183 break;
184 }
185 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d",
186 qw->selectionMode());
187 return GWEN_ERROR_INVALID;
188
190 if (qw->sortColumn()!=index)
192 else {
193 switch(qw->header()->sortIndicatorOrder()) {
194 case Qt::AscendingOrder:
196 case Qt::DescendingOrder:
198 default:
200 }
201 }
202 break;
203
204 default:
205 return Qt5_W_Widget::getIntProperty(prop, index, defaultValue);
206 }
207 };
208
209
210
212 int index,
213 const char *value,
214 int doSignal) {
215 QTreeWidget *qw;
216 QString text;
217
219 assert(qw);
220
221 if (value)
222 text=QT5_Gui::extractHtml(value);
223
224 switch(prop) {
226 QString str;
227 QString t;
228 QStringList sl;
229 int n=0;
230
231 /* remove all columns */
232 qw->header()->reset();
233
234 str=text;
235 while(!(t=str.section('\t', n, n)).isEmpty()) {
236 sl+=t;
237 n++;
238 }
239 qw->setHeaderLabels(sl);
240 return 0;
241 }
242
244 qw->clear();
245 return 0;
246
248 QString str;
249 QString t;
250 int n=0;
251 QStringList sl;
252 /*QTreeWidgetItem *item;*/
253
254 str=text;
255 while(!(t=str.section('\t', n, n)).isEmpty()) {
256 sl+=t;
257 n++;
258 }
259 /*item=*/new QTreeWidgetItem(qw, sl);
260 return 0;
261 }
262
263 default:
264 return Qt5_W_Widget::setCharProperty(prop, index, value, doSignal);
265 }
266 };
267
268
269
271 int index,
272 const char *defaultValue) {
273 QTreeWidget *qw;
274 QString str;
275
277 assert(qw);
278
279 switch(prop) {
281 QTreeWidgetItem *item;
282
283 item=qw->headerItem();
284 if (item) {
285 int i;
286
287 for (i=0; i<qw->columnCount(); i++) {
288 if (i)
289 str+='\t';
290 str+=item->text(i);
291 }
292 if (str.isEmpty())
293 return defaultValue;
294 else {
297 }
298 }
299 return defaultValue;
300 }
301
303 QTreeWidgetItem *item;
304 int i;
305
306 item=qw->topLevelItem(index);
307
308 if (item==NULL) {
309 DBG_ERROR(GWEN_LOGDOMAIN, "Value %d out of range", index);
310 return defaultValue;
311 }
312
313 for (i=0; i<qw->columnCount(); i++) {
314 if (i)
315 str+='\t';
316 str+=item->text(i);
317 }
318 if (str.isEmpty())
319 return defaultValue;
320 else {
323 }
324 }
325
326 default:
327 return Qt5_W_Widget::getCharProperty(prop, index, defaultValue);
328 }
329 };
330
331};
332
333
334
335
336
337
338
#define NULL
Definition binreloc.c:300
GWEN_WIDGET * _widget
Definition cppwidget.hpp:66
CppDialog * getDialog()
QT5_DialogBox * getMainWindow()
static QString extractHtml(const char *text)
Definition qt5_gui.cpp:64
virtual int setup()
int setIntProperty(GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
const char * getCharProperty(GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
int getIntProperty(GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Qt5_W_ListBox(GWEN_WIDGET *w)
int setCharProperty(GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Qt5_W_Widget(GWEN_WIDGET *w)
int setCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, GWEN_UNUSED const char *value, GWEN_UNUSED int doSignal)
int setIntProperty(GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int value, GWEN_UNUSED int doSignal)
const char * getCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, const char *defaultValue)
int getIntProperty(GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int defaultValue)
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
#define GWEN_WIDGET_FLAGS_FILLY
Definition dialog.h:62
@ GWEN_DialogSortDirection_None
Definition dialog.h:297
@ GWEN_DialogSortDirection_Up
Definition dialog.h:298
@ GWEN_DialogSortDirection_Down
Definition dialog.h:299
#define GWEN_WIDGET_FLAGS_FILLX
Definition dialog.h:61
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
@ GWEN_DialogProperty_AddValue
Definition dialog.h:268
@ GWEN_DialogProperty_ColumnWidth
Definition dialog.h:271
@ GWEN_DialogProperty_Title
Definition dialog.h:263
@ GWEN_DialogProperty_Sort
Definition dialog.h:279
@ GWEN_DialogProperty_ClearValues
Definition dialog.h:269
@ GWEN_DialogProperty_SelectionMode
Definition dialog.h:274
@ GWEN_DialogProperty_SortDirection
Definition dialog.h:278
@ GWEN_DialogProperty_Value
Definition dialog.h:264
@ GWEN_Dialog_SelectionMode_None
Definition dialog.h:290
@ GWEN_Dialog_SelectionMode_Multi
Definition dialog.h:292
@ GWEN_Dialog_SelectionMode_Single
Definition dialog.h:291
#define GWEN_ERROR_INVALID
Definition error.h:67
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define QT5_DIALOG_STRING_TITLE
#define QT5_DIALOG_STRING_VALUE
#define QT5_DIALOG_WIDGET_REAL
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition widget.c:836
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition widget.c:136
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition widget.c:122
void GWEN_Widget_SetText(GWEN_WIDGET *w, int idx, const char *s)
Definition widget.c:304
const char * GWEN_Widget_GetText(const GWEN_WIDGET *w, int idx)
Definition widget.c:293
uint32_t GWEN_Widget_GetFlags(const GWEN_WIDGET *w)
Definition widget.c:149
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34