summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemviews/qstandarditemmodel.cpp20
-rw-r--r--src/gui/itemviews/qstandarditemmodel_p.h4
2 files changed, 11 insertions, 13 deletions
diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp
index b960fae..25acbc4 100644
--- a/src/gui/itemviews/qstandarditemmodel.cpp
+++ b/src/gui/itemviews/qstandarditemmodel.cpp
@@ -329,7 +329,6 @@ QStandardItemModelPrivate::QStandardItemModelPrivate()
*/
QStandardItemModelPrivate::~QStandardItemModelPrivate()
{
- delete root;
delete itemPrototype;
qDeleteAll(columnHeaderItems);
qDeleteAll(rowHeaderItems);
@@ -554,7 +553,7 @@ void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent,
int row, int count)
{
Q_Q(QStandardItemModel);
- if (parent == root)
+ if (parent == root.data())
rowHeaderItems.insert(row, count, 0);
q->endInsertRows();
}
@@ -566,7 +565,7 @@ void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent,
int column, int count)
{
Q_Q(QStandardItemModel);
- if (parent == root)
+ if (parent == root.data())
columnHeaderItems.insert(column, count, 0);
q->endInsertColumns();
}
@@ -578,7 +577,7 @@ void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent,
int row, int count)
{
Q_Q(QStandardItemModel);
- if (parent == root) {
+ if (parent == root.data()) {
for (int i = row; i < row + count; ++i) {
QStandardItem *oldItem = rowHeaderItems.at(i);
if (oldItem)
@@ -597,7 +596,7 @@ void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent,
int column, int count)
{
Q_Q(QStandardItemModel);
- if (parent == root) {
+ if (parent == root.data()) {
for (int i = column; i < column + count; ++i) {
QStandardItem *oldItem = columnHeaderItems.at(i);
if (oldItem)
@@ -788,7 +787,7 @@ QStandardItem::~QStandardItem()
QStandardItem *QStandardItem::parent() const
{
Q_D(const QStandardItem);
- if (!d->model || (d->model->d_func()->root != d->parent))
+ if (!d->model || (d->model->d_func()->root.data() != d->parent))
return d->parent;
return 0;
}
@@ -2083,8 +2082,7 @@ QStandardItemModel::~QStandardItemModel()
void QStandardItemModel::clear()
{
Q_D(QStandardItemModel);
- delete d->root;
- d->root = new QStandardItem;
+ d->root.reset(new QStandardItem);
d->root->d_func()->setModel(this);
qDeleteAll(d->columnHeaderItems);
d->columnHeaderItems.clear();
@@ -2231,7 +2229,7 @@ QStandardItem *QStandardItemModel::item(int row, int column) const
QStandardItem *QStandardItemModel::invisibleRootItem() const
{
Q_D(const QStandardItemModel);
- return d->root;
+ return d->root.data();
}
/*!
@@ -2733,7 +2731,7 @@ QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex &pa
bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent)
{
Q_D(QStandardItemModel);
- QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root;
+ QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
if (item == 0)
return false;
return item->d_func()->insertColumns(column, count, QList<QStandardItem*>());
@@ -2745,7 +2743,7 @@ bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex
bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent)
{
Q_D(QStandardItemModel);
- QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root;
+ QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
if (item == 0)
return false;
return item->d_func()->insertRows(row, count, QList<QStandardItem*>());
diff --git a/src/gui/itemviews/qstandarditemmodel_p.h b/src/gui/itemviews/qstandarditemmodel_p.h
index b2b16d1..8be8e9e 100644
--- a/src/gui/itemviews/qstandarditemmodel_p.h
+++ b/src/gui/itemviews/qstandarditemmodel_p.h
@@ -152,7 +152,7 @@ public:
inline QStandardItem *itemFromIndex(const QModelIndex &index) const {
Q_Q(const QStandardItemModel);
if (!index.isValid())
- return root;
+ return root.data();
if (index.model() != q)
return 0;
QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());
@@ -177,7 +177,7 @@ public:
QVector<QStandardItem*> columnHeaderItems;
QVector<QStandardItem*> rowHeaderItems;
- QStandardItem *root;
+ QScopedPointer<QStandardItem> root;
const QStandardItem *itemPrototype;
int sortRole;
};