Debian Codegraph @

gui/src/qcheckedlistwidget.h

raw symbols SCIP
1 /*****************************************************************************
2 ** QNapi
3 ** Copyright (C) 2008-2017 Piotr KrzemiƄski <[email protected]>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 *****************************************************************************/
14
15 #ifndef __QCHECKEDLISTWIDGET__H__
16 #define __QCHECKEDLISTWIDGET__H__
17
18 #include <QtWidgets>
19
20 class QCheckedListWidget : public QListWidget {
21 public:
22 QCheckedListWidget(QWidget* parent = 0) : QListWidget(parent) {
23 setMouseTracking(true);
24 }
25
26 void setItemCheckState(int i, Qt::CheckState state) {
27 QListWidgetItem* it = item(i);
28 if (it) it->setCheckState(state);
29 }
30
31 Qt::CheckState itemCheckState(int i) {
32 QListWidgetItem* it = item(i);
33 return it ? it->checkState() : Qt::Unchecked;
34 }
35
36 void selectAll() {
37 for (int i = 0; i < count(); ++i) {
38 item(i)->setCheckState(Qt::Checked);
39 }
40 }
41
42 void unselectAll() {
43 for (int i = 0; i < count(); ++i) {
44 item(i)->setCheckState(Qt::Unchecked);
45 }
46 }
47
48 void invertSelection() {
49 Qt::CheckState state;
50 for (int i = 0; i < count(); ++i) {
51 state = item(i)->checkState();
52 state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
53 item(i)->setCheckState(state);
54 }
55 }
56 };
57
58 #endif // __QCHECKEDLISTWIDGET__H__