gwenhywfar  4.7.0beta
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 
14 class Qt4_W_ListBox: public Qt4_W_Widget {
15 public:
17  }
18 
19 
20 
22  }
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  QT4_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<QT4_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 Qt4_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 Qt4_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=QT4_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 Qt4_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 Qt4_W_Widget::getCharProperty(prop, index, defaultValue);
328  }
329  };
330 
331 };
332 
333 
334 
335 
336 
337 
338