| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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 |
|
|---|
| 64 | QT_BEGIN_NAMESPACE
|
|---|
| 65 |
|
|---|
| 66 | class QListModelLessThan
|
|---|
| 67 | {
|
|---|
| 68 | public:
|
|---|
| 69 | inline bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
|
|---|
| 70 | { return *i1 < *i2; }
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | class QListModelGreaterThan
|
|---|
| 74 | {
|
|---|
| 75 | public:
|
|---|
| 76 | inline bool operator()(QListWidgetItem *i1, QListWidgetItem *i2) const
|
|---|
| 77 | { return *i2 < *i1; }
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | class Q_AUTOTEST_EXPORT QListModel : public QAbstractListModel
|
|---|
| 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,
|
|---|
| 113 | const QPair<QListWidgetItem*,int> &right);
|
|---|
| 114 | static bool itemGreaterThan(const QPair<QListWidgetItem*,int> &left,
|
|---|
| 115 | const QPair<QListWidgetItem*,int> &right);
|
|---|
| 116 | static QList<QListWidgetItem*>::iterator sortedInsertionIterator(
|
|---|
| 117 | const QList<QListWidgetItem*>::iterator &begin,
|
|---|
| 118 | const QList<QListWidgetItem*>::iterator &end,
|
|---|
| 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:
|
|---|
| 134 | QList<QListWidgetItem*> items;
|
|---|
| 135 |
|
|---|
| 136 | // A cache must be mutable if get-functions should have const modifiers
|
|---|
| 137 | mutable QModelIndexList cachedIndexes;
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | class QListWidgetPrivate : public QListViewPrivate
|
|---|
| 143 | {
|
|---|
| 144 | Q_DECLARE_PUBLIC(QListWidget)
|
|---|
| 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 ¤t, const QModelIndex &previous);
|
|---|
| 156 | void _q_sort();
|
|---|
| 157 | void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
|---|
| 158 | Qt::SortOrder sortOrder;
|
|---|
| 159 | bool sortingEnabled;
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | class QListWidgetItemPrivate
|
|---|
| 163 | {
|
|---|
| 164 | public:
|
|---|
| 165 | QListWidgetItemPrivate(QListWidgetItem *item) : q(item), theid(-1) {}
|
|---|
| 166 | QListWidgetItem *q;
|
|---|
| 167 | QVector<QWidgetItemData> values;
|
|---|
| 168 | int theid;
|
|---|
| 169 | };
|
|---|
| 170 |
|
|---|
| 171 | QT_END_NAMESPACE
|
|---|
| 172 |
|
|---|
| 173 | #endif // QT_NO_LISTWIDGET
|
|---|
| 174 |
|
|---|
| 175 | #endif // QLISTWIDGET_P_H
|
|---|