1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtGui module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
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.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
1742
1739
Q_D(QStandardItem);
1743
1740
if ((row < 0) || (row >= rowCount()))
1744
1741
return QList<QStandardItem*>();
1743
d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
1745
1744
QList<QStandardItem*> items;
1746
int index = d->childIndex(row, 0);
1747
for (int column = 0; column < d->columnCount(); ++column) {
1748
QStandardItem *ch = d->children.at(index);
1750
ch->d_func()->setParentAndModel(0, 0);
1751
d->children.replace(index, 0);
1745
int index = d->childIndex(row, 0); // Will return -1 if there are no columns
1747
int col_count = d->columnCount();
1748
for (int column = 0; column < col_count; ++column) {
1749
QStandardItem *ch = d->children.at(index + column);
1751
ch->d_func()->setParentAndModel(0, 0);
1754
d->children.remove(index, col_count);
1758
d->model->d_func()->rowsRemoved(this, row, 1);
1769
1771
Q_D(QStandardItem);
1770
1772
if ((column < 0) || (column >= columnCount()))
1771
1773
return QList<QStandardItem*>();
1775
d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
1772
1776
QList<QStandardItem*> items;
1773
int index = d->childIndex(0, column);
1774
for (int row = 0; row < d->rowCount(); ++row) {
1778
for (int row = d->rowCount() - 1; row >= 0; --row) {
1779
int index = d->childIndex(row, column);
1775
1780
QStandardItem *ch = d->children.at(index);
1777
1782
ch->d_func()->setParentAndModel(0, 0);
1778
d->children.replace(index, 0);
1781
index += d->columnCount();
1783
d->children.remove(index);
1783
removeColumn(column);
1788
d->model->d_func()->columnsRemoved(this, column, 1);
1801
1806
const int role = model() ? model()->sortRole() : Qt::DisplayRole;
1802
1807
const QVariant l = data(role), r = other.data(role);
1803
1808
// this code is copied from QSortFilterProxyModel::lessThan()
1809
switch (l.userType()) {
1805
1810
case QVariant::Invalid:
1806
1811
return (r.type() == QVariant::Invalid);
1807
1812
case QVariant::Int:
1812
1817
return l.toLongLong() < r.toLongLong();
1813
1818
case QVariant::ULongLong:
1814
1819
return l.toULongLong() < r.toULongLong();
1820
case QMetaType::Float:
1821
return l.toFloat() < r.toFloat();
1815
1822
case QVariant::Double:
1816
1823
return l.toDouble() < r.toDouble();
1817
1824
case QVariant::Char:
2079
2086
void QStandardItemModel::clear()
2081
2088
Q_D(QStandardItemModel);
2083
d->root = new QStandardItem;
2089
d->root.reset(new QStandardItem);
2084
2090
d->root->d_func()->setModel(this);
2085
2091
qDeleteAll(d->columnHeaderItems);
2086
2092
d->columnHeaderItems.clear();
2729
2735
bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent)
2731
2737
Q_D(QStandardItemModel);
2732
QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root;
2738
QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
2735
2741
return item->d_func()->insertColumns(column, count, QList<QStandardItem*>());
2741
2747
bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent)
2743
2749
Q_D(QStandardItemModel);
2744
QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root;
2750
QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
2747
2753
return item->d_func()->insertRows(row, count, QList<QStandardItem*>());
2907
2913
QStack<QStandardItem*> stack;
2908
2914
itemsSet.reserve(indexes.count());
2909
2915
stack.reserve(indexes.count());
2910
foreach (const QModelIndex &index, indexes) {
2911
QStandardItem *item = itemFromIndex(index);
2916
for (int i = 0; i < indexes.count(); ++i) {
2917
QStandardItem *item = itemFromIndex(indexes.at(i));
2912
2918
itemsSet << item;
2913
2919
stack.push(item);
2965
2971
Used by QStandardItemModel::dropMimeData
2966
2972
stream out an item and his children
2968
static void decodeDataRecursive(QDataStream &stream, QStandardItem *item)
2974
void QStandardItemModelPrivate::decodeDataRecursive(QDataStream &stream, QStandardItem *item)
2970
2976
int colCount, childCount;
2971
2977
stream >> *item;
2977
2983
while(childPos > 0) {
2979
QStandardItem *child = new QStandardItem;
2985
QStandardItem *child = createItem();
2980
2986
decodeDataRecursive(stream, child);
2981
2987
item->setChild( childPos / colCount, childPos % colCount, child);
2989
2995
bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
2990
2996
int row, int column, const QModelIndex &parent)
2998
Q_D(QStandardItemModel);
2992
2999
// check if the action is supported
2993
3000
if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
3021
3028
while (!stream.atEnd()) {
3023
QStandardItem *item = new QStandardItem;
3030
QStandardItem *item = d->createItem();
3024
3031
stream >> r >> c;
3025
decodeDataRecursive(stream, item);
3032
d->decodeDataRecursive(stream, item);
3027
3034
rows.append(r);
3028
3035
columns.append(c);