summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-07-07 20:19:41 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-07-08 19:19:32 +0200
commitd6a724a9b2e8bab1ee35e637887b8968ee66bc26 (patch)
treeaa530ac6ec530b28ec3fd95c2b1d6f10f04482bc /src
parent8a78830b0d7020c83f7f739165ab865f04440a74 (diff)
QCalendarWidget: code tidies for the internal model
The table model inside a QCalendarWidget was violating a few QAIM principles: * returning illegal values from row/columnCount by not checking the parent index * not keeping invariants on row/column manipulation. Pick-to: 5.15 Change-Id: I2c51e59ea2d89e73884bad20f3c06fbb808a26c5 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp51
1 files changed, 20 insertions, 31 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 830216ef72..be3d275375 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -860,38 +860,23 @@ class QCalendarModel : public QAbstractTableModel
public:
QCalendarModel(QObject *parent = nullptr);
- int rowCount(const QModelIndex &) const override
- { return RowCount + m_firstRow; }
- int columnCount(const QModelIndex &) const override
- { return ColumnCount + m_firstColumn; }
- QVariant data(const QModelIndex &index, int role) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
-
- bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
- {
- beginInsertRows(parent, row, row + count - 1);
- endInsertRows();
- return true;
- }
- bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override
+ int rowCount(const QModelIndex &parent) const override
{
- beginInsertColumns(parent, column, column + count - 1);
- endInsertColumns();
- return true;
- }
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
- {
- beginRemoveRows(parent, row, row + count - 1);
- endRemoveRows();
- return true;
+ if (parent.isValid())
+ return 0;
+ return RowCount + m_firstRow;
}
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override
+
+ int columnCount(const QModelIndex &parent) const override
{
- beginRemoveColumns(parent, column, column + count - 1);
- endRemoveColumns();
- return true;
+ if (parent.isValid())
+ return 0;
+ return ColumnCount + m_firstColumn;
}
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+
void showMonth(int year, int month);
void setDate(QDate d);
@@ -1303,11 +1288,13 @@ void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeader
int oldFormat = m_horizontalHeaderFormat;
m_horizontalHeaderFormat = format;
if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
+ beginInsertRows(QModelIndex(), 0, 0);
m_firstRow = 1;
- insertRow(0);
+ endInsertRows();
} else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) {
+ beginRemoveRows(QModelIndex(), 0, 0);
m_firstRow = 0;
- removeRow(0);
+ endRemoveRows();
}
internalUpdate();
}
@@ -1338,11 +1325,13 @@ void QCalendarModel::setWeekNumbersShown(bool show)
m_weekNumbersShown = show;
if (show) {
+ beginInsertColumns(QModelIndex(), 0, 0);
m_firstColumn = 1;
- insertColumn(0);
+ endInsertColumns();
} else {
+ beginRemoveColumns(QModelIndex(), 0, 0);
m_firstColumn = 0;
- removeColumn(0);
+ endRemoveColumns();
}
internalUpdate();
}