diff options
author | mread <qt-info@nokia.com> | 2009-08-05 08:37:51 (GMT) |
---|---|---|
committer | mread <qt-info@nokia.com> | 2009-08-05 08:37:51 (GMT) |
commit | 867bcdcce78acca9fde2ffc57e6a304cd2e25517 (patch) | |
tree | ae41a5deeec81ab83c294441917409c124ae362c /src | |
parent | 58839dd435e558a02ea7882e9133e5be0fa9c687 (diff) | |
download | Qt-867bcdcce78acca9fde2ffc57e6a304cd2e25517.zip Qt-867bcdcce78acca9fde2ffc57e6a304cd2e25517.tar.gz Qt-867bcdcce78acca9fde2ffc57e6a304cd2e25517.tar.bz2 |
memory leak fix in standardItemModel found during combo box testing
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/itemviews/qstandarditemmodel.cpp | 20 | ||||
-rw-r--r-- | src/gui/itemviews/qstandarditemmodel_p.h | 4 |
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; }; |