Added QAbstractItemModelTester to main and proxy model. And fixing errors in functions flags(...), rowCount(...) and columnCount(...).
This commit is contained in:
@ -11,6 +11,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
|
|
||||||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core LinguistTools)
|
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core LinguistTools)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core LinguistTools Gui)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core LinguistTools Gui)
|
||||||
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)
|
||||||
|
|
||||||
configure_file(CoreConfig.h.in CoreConfig.h)
|
configure_file(CoreConfig.h.in CoreConfig.h)
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ add_library(${TARGET_APP} STATIC
|
|||||||
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
|
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
target_link_libraries(GenericCore PRIVATE Qt${QT_VERSION_MAJOR}::Test)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui)
|
target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "genericcore.h"
|
#include "genericcore.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemModelTester>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -135,7 +136,19 @@ void GenericCore::setupModels() {
|
|||||||
m_mainModel = make_shared<TableModel>(m_modelUndoStack, this);
|
m_mainModel = make_shared<TableModel>(m_modelUndoStack, this);
|
||||||
m_sortFilterModel = make_shared<GeneralSortFilterModel>(m_mainModel);
|
m_sortFilterModel = make_shared<GeneralSortFilterModel>(m_mainModel);
|
||||||
|
|
||||||
// TODO add QAbstractItemModelTester
|
/// QAbstractItemModelTester
|
||||||
|
#ifdef QT_DEBUG
|
||||||
|
m_mainModelTester = make_unique<QAbstractItemModelTester>(
|
||||||
|
m_mainModel.get(), QAbstractItemModelTester::FailureReportingMode::Fatal);
|
||||||
|
m_proxyModelTester = make_unique<QAbstractItemModelTester>(
|
||||||
|
m_sortFilterModel.get(), QAbstractItemModelTester::FailureReportingMode::Fatal);
|
||||||
|
#else
|
||||||
|
m_mainModelTester = make_unique<QAbstractItemModelTester>(
|
||||||
|
m_mainModel.get(), QAbstractItemModelTester::FailureReportingMode::Warning);
|
||||||
|
m_modelTester = make_unique<QAbstractItemModelTester>(
|
||||||
|
m_sortFilterModel.get(), QAbstractItemModelTester::FailureReportingMode::Warning);
|
||||||
|
#endif
|
||||||
|
|
||||||
initModelData();
|
initModelData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
|
class QAbstractItemModelTester;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
class TableModel;
|
class TableModel;
|
||||||
@ -38,6 +39,8 @@ class GenericCore : public QObject {
|
|||||||
QUndoStack* m_modelUndoStack;
|
QUndoStack* m_modelUndoStack;
|
||||||
std::shared_ptr<TableModel> m_mainModel;
|
std::shared_ptr<TableModel> m_mainModel;
|
||||||
std::shared_ptr<GeneralSortFilterModel> m_sortFilterModel;
|
std::shared_ptr<GeneralSortFilterModel> m_sortFilterModel;
|
||||||
|
std::unique_ptr<QAbstractItemModelTester> m_mainModelTester;
|
||||||
|
std::unique_ptr<QAbstractItemModelTester> m_proxyModelTester;
|
||||||
|
|
||||||
void setupModels();
|
void setupModels();
|
||||||
void initModelData();
|
void initModelData();
|
||||||
|
|||||||
@ -39,18 +39,25 @@ TableModel::TableModel(QUndoStack* undoStack, QObject* parent)
|
|||||||
, m_undoStack(undoStack) {}
|
, m_undoStack(undoStack) {}
|
||||||
|
|
||||||
Qt::ItemFlags TableModel::flags(const QModelIndex& index) const {
|
Qt::ItemFlags TableModel::flags(const QModelIndex& index) const {
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return QAbstractTableModel::flags(index);
|
||||||
|
}
|
||||||
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
|
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> TableModel::roleNames() const { return ROLE_NAMES; }
|
QHash<int, QByteArray> TableModel::roleNames() const { return ROLE_NAMES; }
|
||||||
|
|
||||||
int TableModel::rowCount(const QModelIndex& parent) const {
|
int TableModel::rowCount(const QModelIndex& parent) const {
|
||||||
Q_UNUSED(parent);
|
if (parent.isValid()) {
|
||||||
|
return 0; // no children
|
||||||
|
}
|
||||||
return m_items.size();
|
return m_items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TableModel::columnCount(const QModelIndex& parent) const {
|
int TableModel::columnCount(const QModelIndex& parent) const {
|
||||||
Q_UNUSED(parent);
|
if (parent.isValid()) {
|
||||||
|
return 0; // no children
|
||||||
|
}
|
||||||
return ROLE_NAMES.size();
|
return ROLE_NAMES.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user