diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index 389058f11..67ce4a02f 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -512,6 +512,10 @@ int QetGraphicsTableItem::displayNRowOffset() const */ int QetGraphicsTableItem::displayedRowCount() const { + if (!m_model) { + return 0; + } + //Calcule the number of rows to display. auto row_count = m_model->rowCount(); @@ -524,12 +528,12 @@ int QetGraphicsTableItem::displayedRowCount() const return row_count; } -QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const +QPointer QetGraphicsTableItem::previousTable() const { return m_previous_table; } -QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const +QPointer QetGraphicsTableItem::nextTable() const { return m_next_table; } @@ -1091,15 +1095,15 @@ void QetGraphicsTableItem::previousTableDisplayRowChanged() */ void QetGraphicsTableItem::removeUselessNextTable(bool recursive) { - if (!m_next_table) { - return; - } - - if (recursive) { - m_next_table->removeUselessNextTable(); - } - if (m_next_table->displayedRowCount() <= 0) { - delete m_next_table; - m_next_table = nullptr; + if (m_next_table) + { + if (recursive) { + m_next_table->removeUselessNextTable(); + } + if (m_next_table->displayedRowCount() <= 0) + { + m_next_table.data()->deleteLater(); + m_next_table.clear(); + } } } diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h index 25ccf5d04..67a5cfe39 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h @@ -80,8 +80,8 @@ class QetGraphicsTableItem : public QetGraphicsItem QString tableName() const; int displayNRowOffset() const; int displayedRowCount() const; - QetGraphicsTableItem *previousTable() const; - QetGraphicsTableItem *nextTable() const; + QPointer previousTable() const; + QPointer nextTable() const; void setToMinimumHeight(); void initLink(); QUuid uuid() const {return m_uuid;} @@ -141,9 +141,8 @@ class QetGraphicsTableItem : public QetGraphicsItem QetGraphicsHandlerItem m_handler_item; QetGraphicsHeaderItem *m_header_item = nullptr; - QetGraphicsTableItem - *m_previous_table = nullptr, - *m_next_table = nullptr; + QPointer m_previous_table, + m_next_table; QString m_name; QUuid