summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qabstractitemmodel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.h')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.h127
1 files changed, 58 insertions, 69 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h
index 32d88e9d96..c4f705e858 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.h
+++ b/src/corelib/itemmodels/qabstractitemmodel.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -49,24 +49,24 @@ class Q_CORE_EXPORT QModelIndex
{
friend class QAbstractItemModel;
public:
- Q_DECL_CONSTEXPR inline QModelIndex() : r(-1), c(-1), i(0), m(0) {}
+ Q_DECL_CONSTEXPR inline QModelIndex() Q_DECL_NOTHROW : r(-1), c(-1), i(0), m(0) {}
// compiler-generated copy/move ctors/assignment operators are fine!
- Q_DECL_CONSTEXPR inline int row() const { return r; }
- Q_DECL_CONSTEXPR inline int column() const { return c; }
- Q_DECL_CONSTEXPR inline quintptr internalId() const { return i; }
- inline void *internalPointer() const { return reinterpret_cast<void*>(i); }
+ Q_DECL_CONSTEXPR inline int row() const Q_DECL_NOTHROW { return r; }
+ Q_DECL_CONSTEXPR inline int column() const Q_DECL_NOTHROW { return c; }
+ Q_DECL_CONSTEXPR inline quintptr internalId() const Q_DECL_NOTHROW { return i; }
+ inline void *internalPointer() const Q_DECL_NOTHROW { return reinterpret_cast<void*>(i); }
inline QModelIndex parent() const;
inline QModelIndex sibling(int row, int column) const;
inline QModelIndex child(int row, int column) const;
inline QVariant data(int role = Qt::DisplayRole) const;
inline Qt::ItemFlags flags() const;
- Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const { return m; }
- Q_DECL_CONSTEXPR inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); }
- Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const Q_DECL_NOTHROW { return m; }
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW { return (r >= 0) && (c >= 0) && (m != 0); }
+ Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const Q_DECL_NOTHROW
{ return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); }
- Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const Q_DECL_NOTHROW
{ return !(*this == other); }
- Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const Q_DECL_NOTHROW
{
return r < other.r
|| (r == other.r && (c < other.c
@@ -74,9 +74,9 @@ public:
|| (i == other.i && m < other.m )))));
}
private:
- inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel)
+ inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) Q_DECL_NOTHROW
: r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
- Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel)
+ Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_NOTHROW
: r(arow), c(acolumn), i(id), m(amodel) {}
int r, c;
quintptr i;
@@ -91,7 +91,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
class QPersistentModelIndexData;
// qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4)
-uint qHash(const QPersistentModelIndex &index, uint seed = 0);
+uint qHash(const QPersistentModelIndex &index, uint seed = 0) Q_DECL_NOTHROW;
class Q_CORE_EXPORT QPersistentModelIndex
{
@@ -106,11 +106,12 @@ public:
{ return !operator==(other); }
QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QPersistentModelIndex(QPersistentModelIndex &&other) : d(other.d) { other.d = 0; }
- inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other)
+ inline QPersistentModelIndex(QPersistentModelIndex &&other) Q_DECL_NOTHROW
+ : d(other.d) { other.d = Q_NULLPTR; }
+ inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QPersistentModelIndex &other) { qSwap(d, other.d); }
+ inline void swap(QPersistentModelIndex &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
bool operator==(const QModelIndex &other) const;
bool operator!=(const QModelIndex &other) const;
QPersistentModelIndex &operator=(const QModelIndex &other);
@@ -128,14 +129,14 @@ public:
bool isValid() const;
private:
QPersistentModelIndexData *d;
- friend uint qHash(const QPersistentModelIndex &, uint seed);
+ friend uint qHash(const QPersistentModelIndex &, uint seed) Q_DECL_NOTHROW;
#ifndef QT_NO_DEBUG_STREAM
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
#endif
};
Q_DECLARE_SHARED(QPersistentModelIndex)
-inline uint qHash(const QPersistentModelIndex &index, uint seed)
+inline uint qHash(const QPersistentModelIndex &index, uint seed) Q_DECL_NOTHROW
{ return qHash(index.d, seed); }
@@ -154,7 +155,6 @@ template <class Key, class T> class QMap;
class Q_CORE_EXPORT QAbstractItemModel : public QObject
{
Q_OBJECT
- Q_ENUMS(LayoutChangeHint)
friend class QPersistentModelIndexData;
friend class QAbstractItemViewPrivate;
@@ -164,20 +164,20 @@ public:
explicit QAbstractItemModel(QObject *parent = 0);
virtual ~QAbstractItemModel();
- bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
- virtual QModelIndex index(int row, int column,
+ Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ Q_INVOKABLE virtual QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const = 0;
- virtual QModelIndex parent(const QModelIndex &child) const = 0;
+ Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0;
- virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
- virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
+ Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
+ Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
+ Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
+ Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
- virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
+ Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- virtual QVariant headerData(int section, Qt::Orientation orientation,
+ Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
int role = Qt::EditRole);
@@ -217,24 +217,20 @@ public:
inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn,
const QModelIndex &destinationParent, int destinationChild);
- virtual void fetchMore(const QModelIndex &parent);
- virtual bool canFetchMore(const QModelIndex &parent) const;
- virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent);
+ Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const;
+ Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
virtual QModelIndex buddy(const QModelIndex &index) const;
- virtual QModelIndexList match(const QModelIndex &start, int role,
- const QVariant &value, int hits = 1,
- Qt::MatchFlags flags =
- Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
+ Q_INVOKABLE virtual QModelIndexList match(const QModelIndex &start, int role,
+ const QVariant &value, int hits = 1,
+ Qt::MatchFlags flags =
+ Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
virtual QSize span(const QModelIndex &index) const;
virtual QHash<int,QByteArray> roleNames() const;
-#ifdef Q_NO_USING_KEYWORD
- inline QObject *parent() const { return QObject::parent(); }
-#else
using QObject::parent;
-#endif
enum LayoutChangeHint
{
@@ -242,6 +238,7 @@ public:
VerticalSortHint,
HorizontalSortHint
};
+ Q_ENUM(LayoutChangeHint)
Q_SIGNALS:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
@@ -419,27 +416,22 @@ public:
explicit QAbstractTableModel(QObject *parent = 0);
~QAbstractTableModel();
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent);
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
-#ifdef Q_NO_USING_KEYWORD
-#ifndef Q_QDOC
- inline QObject *parent() const { return QAbstractItemModel::parent(); }
-#endif
-#else
using QObject::parent;
-#endif
protected:
QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent);
private:
Q_DISABLE_COPY(QAbstractTableModel)
- QModelIndex parent(const QModelIndex &child) const;
- bool hasChildren(const QModelIndex &parent) const;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent) const Q_DECL_OVERRIDE;
};
class Q_CORE_EXPORT QAbstractListModel : public QAbstractItemModel
@@ -450,28 +442,23 @@ public:
explicit QAbstractListModel(QObject *parent = 0);
~QAbstractListModel();
- QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent);
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
-#ifdef Q_NO_USING_KEYWORD
-#ifndef Q_QDOC
- inline QObject *parent() const { return QAbstractItemModel::parent(); }
-#endif
-#else
using QObject::parent;
-#endif
protected:
QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent);
private:
Q_DISABLE_COPY(QAbstractListModel)
- QModelIndex parent(const QModelIndex &child) const;
- int columnCount(const QModelIndex &parent) const;
- bool hasChildren(const QModelIndex &parent) const;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent) const Q_DECL_OVERRIDE;
};
// inline implementations
@@ -491,9 +478,11 @@ inline QVariant QModelIndex::data(int arole) const
inline Qt::ItemFlags QModelIndex::flags() const
{ return m ? m->flags(*this) : Qt::ItemFlags(0); }
-inline uint qHash(const QModelIndex &index)
+inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW
{ return uint((index.row() << 4) + index.column() + index.internalId()); }
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QModelIndexList)
+
#endif // QABSTRACTITEMMODEL_H