Qt 4.8
qlistwidget_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QLISTWIDGET_P_H
43 #define QLISTWIDGET_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. This header file may change
50 // from version to version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include <QtCore/qabstractitemmodel.h>
56 #include <QtGui/qabstractitemview.h>
57 #include <QtGui/qlistwidget.h>
58 #include <qitemdelegate.h>
59 #include <private/qlistview_p.h>
60 #include <private/qwidgetitemdata_p.h>
61 
62 #ifndef QT_NO_LISTWIDGET
63 
65 
67 {
68 public:
69  inline bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
70  { return *i1 < *i2; }
71 };
72 
74 {
75 public:
76  inline bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
77  { return *i2 < *i1; }
78 };
79 
81 {
82  Q_OBJECT
83 public:
84  QListModel(QListWidget *parent);
85  ~QListModel();
86 
87  void clear();
88  QListWidgetItem *at(int row) const;
89  void insert(int row, QListWidgetItem *item);
90  void insert(int row, const QStringList &items);
91  void remove(QListWidgetItem *item);
92  QListWidgetItem *take(int row);
93  void move(int srcRow, int dstRow);
94 
95  int rowCount(const QModelIndex &parent = QModelIndex()) const;
96 
97  QModelIndex index(QListWidgetItem *item) const;
98  QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
99 
100  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
101  bool setData(const QModelIndex &index, const QVariant &value, int role);
102 
103  QMap<int, QVariant> itemData(const QModelIndex &index) const;
104 
105  bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
106  bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
107 
108  Qt::ItemFlags flags(const QModelIndex &index) const;
109 
110  void sort(int column, Qt::SortOrder order);
111  void ensureSorted(int column, Qt::SortOrder order, int start, int end);
112  static bool itemLessThan(const QPair<QListWidgetItem*,int> &left,
114  static bool itemGreaterThan(const QPair<QListWidgetItem*,int> &left,
115  const QPair<QListWidgetItem*,int> &right);
116  static QList<QListWidgetItem*>::iterator sortedInsertionIterator(
119  Qt::SortOrder order, QListWidgetItem *item);
120 
121  void itemChanged(QListWidgetItem *item);
122 
123  // dnd
124  QStringList mimeTypes() const;
125  QMimeData *mimeData(const QModelIndexList &indexes) const;
126 #ifndef QT_NO_DRAGANDDROP
127  bool dropMimeData(const QMimeData *data, Qt::DropAction action,
128  int row, int column, const QModelIndex &parent);
129  Qt::DropActions supportedDropActions() const;
130 #endif
131 
132  QMimeData *internalMimeData() const;
133 private:
135 
136  // A cache must be mutable if get-functions should have const modifiers
138 };
139 
140 
141 
143 {
145 public:
146  QListWidgetPrivate() : QListViewPrivate(), sortOrder(Qt::AscendingOrder), sortingEnabled(false) {}
147  inline QListModel *listModel() const { return qobject_cast<QListModel*>(model); }
148  void setup();
149  void _q_emitItemPressed(const QModelIndex &index);
150  void _q_emitItemClicked(const QModelIndex &index);
151  void _q_emitItemDoubleClicked(const QModelIndex &index);
152  void _q_emitItemActivated(const QModelIndex &index);
153  void _q_emitItemEntered(const QModelIndex &index);
154  void _q_emitItemChanged(const QModelIndex &index);
155  void _q_emitCurrentItemChanged(const QModelIndex &current, const QModelIndex &previous);
156  void _q_sort();
157  void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
160 };
161 
163 {
164 public:
165  QListWidgetItemPrivate(QListWidgetItem *item) : q(item), theid(-1) {}
168  int theid;
169 };
170 
172 
173 #endif // QT_NO_LISTWIDGET
174 
175 #endif // QLISTWIDGET_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define at(className, varName)
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QListWidget class provides an item-based list widget.
Definition: qlistwidget.h:202
The QAbstractListModel class provides an abstract model that can be subclassed to create one-dimensio...
Qt::SortOrder sortOrder
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void sort(T *array, int count, LessThan lessThan)
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
QList< QListWidgetItem * > items
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
Definition: qlistwidget_p.h:69
static const char * data(const QByteArray &arr)
QVector< QWidgetItemData > values
DropAction
Definition: qnamespace.h:1597
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
#define Q_OBJECT
Definition: qobjectdefs.h:157
QModelIndexList cachedIndexes
The QListWidgetItem class provides an item for use with the QListWidget item view class...
Definition: qlistwidget.h:63
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
QListModel * listModel() const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QListWidgetItem * q
bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
Definition: qlistwidget_p.h:76
The QModelIndex class is used to locate data in a data model.
Definition: qnamespace.h:54
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
quint16 index
QListWidgetItemPrivate(QListWidgetItem *item)
static const KeyPair *const end
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static void setup()
Definition: qtextcodec.cpp:718