00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QITEMSELECTIONMODEL_H
00043 #define QITEMSELECTIONMODEL_H
00044
00045 #include <QtCore/qset.h>
00046 #include <QtCore/qvector.h>
00047 #include <QtCore/qlist.h>
00048 #include <QtCore/qabstractitemmodel.h>
00049
00050 QT_BEGIN_HEADER
00051
00052 QT_BEGIN_NAMESPACE
00053
00054 QT_MODULE(Gui)
00055
00056 #ifndef QT_NO_ITEMVIEWS
00057
00058 class Q_GUI_EXPORT QItemSelectionRange
00059 {
00060
00061 public:
00062 inline QItemSelectionRange() {}
00063 inline QItemSelectionRange(const QItemSelectionRange &other)
00064 : tl(other.tl), br(other.br) {}
00065 inline QItemSelectionRange(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00066 explicit inline QItemSelectionRange(const QModelIndex &index)
00067 { tl = index; br = tl; }
00068
00069 inline int top() const { return tl.row(); }
00070 inline int left() const { return tl.column(); }
00071 inline int bottom() const { return br.row(); }
00072 inline int right() const { return br.column(); }
00073 inline int width() const { return br.column() - tl.column() + 1; }
00074 inline int height() const { return br.row() - tl.row() + 1; }
00075
00076 inline QModelIndex topLeft() const { return QModelIndex(tl); }
00077 inline QModelIndex bottomRight() const { return QModelIndex(br); }
00078 inline QModelIndex parent() const { return tl.parent(); }
00079 inline const QAbstractItemModel *model() const { return tl.model(); }
00080
00081 inline bool contains(const QModelIndex &index) const
00082 {
00083 return (parent() == index.parent()
00084 && tl.row() <= index.row() && tl.column() <= index.column()
00085 && br.row() >= index.row() && br.column() >= index.column());
00086 }
00087
00088 inline bool contains(int row, int column, const QModelIndex &parentIndex) const
00089 {
00090 return (parent() == parentIndex
00091 && tl.row() <= row && tl.column() <= column
00092 && br.row() >= row && br.column() >= column);
00093 }
00094
00095 bool intersects(const QItemSelectionRange &other) const;
00096 QItemSelectionRange intersect(const QItemSelectionRange &other) const;
00097 inline QItemSelectionRange intersected(const QItemSelectionRange &other) const
00098 { return intersect(other); }
00099
00100 inline bool operator==(const QItemSelectionRange &other) const
00101 { return (tl == other.tl && br == other.br); }
00102 inline bool operator!=(const QItemSelectionRange &other) const
00103 { return !operator==(other); }
00104
00105 inline bool isValid() const
00106 {
00107 return (tl.isValid() && br.isValid() && tl.parent() == br.parent()
00108 && top() <= bottom() && left() <= right());
00109 }
00110
00111 bool isEmpty() const;
00112
00113 QModelIndexList indexes() const;
00114
00115 private:
00116 QPersistentModelIndex tl, br;
00117 };
00118 Q_DECLARE_TYPEINFO(QItemSelectionRange, Q_MOVABLE_TYPE);
00119
00120 inline QItemSelectionRange::QItemSelectionRange(const QModelIndex &atopLeft,
00121 const QModelIndex &abottomRight)
00122 { tl = atopLeft; br = abottomRight; }
00123
00124 class QItemSelection;
00125 class QItemSelectionModelPrivate;
00126
00127 class Q_GUI_EXPORT QItemSelectionModel : public QObject
00128 {
00129 Q_OBJECT
00130 Q_DECLARE_PRIVATE(QItemSelectionModel)
00131 Q_FLAGS(SelectionFlags)
00132
00133 public:
00134
00135 enum SelectionFlag {
00136 NoUpdate = 0x0000,
00137 Clear = 0x0001,
00138 Select = 0x0002,
00139 Deselect = 0x0004,
00140 Toggle = 0x0008,
00141 Current = 0x0010,
00142 Rows = 0x0020,
00143 Columns = 0x0040,
00144 SelectCurrent = Select | Current,
00145 ToggleCurrent = Toggle | Current,
00146 ClearAndSelect = Clear | Select
00147 };
00148
00149 Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
00150
00151 explicit QItemSelectionModel(QAbstractItemModel *model);
00152 explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent);
00153 virtual ~QItemSelectionModel();
00154
00155 QModelIndex currentIndex() const;
00156
00157 bool isSelected(const QModelIndex &index) const;
00158 bool isRowSelected(int row, const QModelIndex &parent) const;
00159 bool isColumnSelected(int column, const QModelIndex &parent) const;
00160
00161 bool rowIntersectsSelection(int row, const QModelIndex &parent) const;
00162 bool columnIntersectsSelection(int column, const QModelIndex &parent) const;
00163
00164 bool hasSelection() const;
00165
00166 QModelIndexList selectedIndexes() const;
00167 QModelIndexList selectedRows(int column = 0) const;
00168 QModelIndexList selectedColumns(int row = 0) const;
00169 const QItemSelection selection() const;
00170
00171 const QAbstractItemModel *model() const;
00172
00173 public Q_SLOTS:
00174 void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
00175 virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
00176 virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
00177 virtual void clear();
00178 virtual void reset();
00179
00180 void clearSelection();
00181
00182 Q_SIGNALS:
00183 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
00184 void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
00185 void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
00186 void currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous);
00187
00188 protected:
00189 QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model);
00190 void emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection);
00191
00192 private:
00193 Q_DISABLE_COPY(QItemSelectionModel)
00194 Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
00195 Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeRemoved(const QModelIndex&, int, int))
00196 Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeInserted(const QModelIndex&, int, int))
00197 Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeInserted(const QModelIndex&, int, int))
00198 Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged())
00199 Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
00200 };
00201
00202 Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags)
00203
00204
00205 inline uint qHash(const QItemSelectionRange &) { return 0; }
00206
00207 class Q_GUI_EXPORT QItemSelection : public QList<QItemSelectionRange>
00208 {
00209 public:
00210 QItemSelection() {}
00211 QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00212 void select(const QModelIndex &topLeft, const QModelIndex &bottomRight);
00213 bool contains(const QModelIndex &index) const;
00214 QModelIndexList indexes() const;
00215 void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command);
00216 static void split(const QItemSelectionRange &range,
00217 const QItemSelectionRange &other,
00218 QItemSelection *result);
00219 };
00220
00221 #ifndef QT_NO_DEBUG_STREAM
00222 Q_GUI_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &);
00223 #endif
00224
00225 #endif // QT_NO_ITEMVIEWS
00226
00227 QT_END_NAMESPACE
00228
00229 QT_END_HEADER
00230
00231 #endif // QITEMSELECTIONMODEL_H