Appending and removing items are done via GeneralSortFilterModel instead of TableModel directly.

This commit is contained in:
2026-01-12 10:07:59 +01:00
parent a6512f2c67
commit d78fc734c1
2 changed files with 15 additions and 2 deletions

View File

@ -3,12 +3,22 @@
GeneralSortFilterModel::GeneralSortFilterModel(std::shared_ptr<TableModel> sourceModel)
: QSortFilterProxyModel{sourceModel.get()}
, m_sourceModel(sourceModel) {
, m_tableModel(sourceModel) {
setSourceModel(sourceModel.get());
m_collator.setNumericMode(true);
}
void GeneralSortFilterModel::appendItems(const QByteArray& jsonDoc) {
m_tableModel->appendItems(jsonDoc);
}
bool GeneralSortFilterModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) {
const QModelIndex proxyIndex = index(firstRow, 0, parentIndex);
const QModelIndex sourceIndex = mapToSource(proxyIndex);
return m_tableModel->removeRows(sourceIndex.row(), nRows, sourceIndex.parent());
}
bool GeneralSortFilterModel::lessThan(const QModelIndex& source_left,
const QModelIndex& source_right) const {
if (source_left.column() != source_right.column()) {

View File

@ -11,12 +11,15 @@ class GeneralSortFilterModel : public QSortFilterProxyModel {
public:
explicit GeneralSortFilterModel(std::shared_ptr<TableModel> sourceModel = nullptr);
public slots:
void appendItems(const QByteArray& jsonDoc);
bool removeRows(int firstRow, int nRows, const QModelIndex& parentIndex = QModelIndex()) override;
/// QSortFilterProxyModel interface
protected:
bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const override;
private:
std::shared_ptr<TableModel> m_sourceModel;
std::shared_ptr<TableModel> m_tableModel;
QCollator m_collator; /// for sorting
};