diff options
-rw-r--r-- | Ladybird/ModelTranslator.cpp | 13 | ||||
-rw-r--r-- | Ladybird/ModelTranslator.h | 8 |
2 files changed, 15 insertions, 6 deletions
diff --git a/Ladybird/ModelTranslator.cpp b/Ladybird/ModelTranslator.cpp index aab80990c3..31d61954de 100644 --- a/Ladybird/ModelTranslator.cpp +++ b/Ladybird/ModelTranslator.cpp @@ -12,20 +12,19 @@ namespace Ladybird { -ModelTranslator::ModelTranslator(NonnullRefPtr<GUI::Model> model) - : m_model(move(model)) -{ -} - ModelTranslator::~ModelTranslator() = default; int ModelTranslator::columnCount(QModelIndex const& parent) const { + if (!m_model) + return 0; return m_model->column_count(to_gui(parent)); } int ModelTranslator::rowCount(QModelIndex const& parent) const { + if (!m_model) + return 0; return m_model->row_count(to_gui(parent)); } @@ -47,6 +46,7 @@ static QVariant convert_variant(GUI::Variant const& value) QVariant ModelTranslator::data(QModelIndex const& index, int role) const { + VERIFY(m_model); switch (role) { case Qt::DisplayRole: return convert_variant(m_model->data(to_gui(index), GUI::ModelRole::Display)); @@ -59,11 +59,13 @@ QVariant ModelTranslator::data(QModelIndex const& index, int role) const QModelIndex ModelTranslator::index(int row, int column, QModelIndex const& parent) const { + VERIFY(m_model); return to_qt(m_model->index(row, column, to_gui(parent))); } QModelIndex ModelTranslator::parent(QModelIndex const& index) const { + VERIFY(m_model); return to_qt(m_model->parent_index(to_gui(index))); } @@ -76,6 +78,7 @@ QModelIndex ModelTranslator::to_qt(GUI::ModelIndex const& index) const GUI::ModelIndex ModelTranslator::to_gui(QModelIndex const& index) const { + VERIFY(m_model); if (!index.isValid()) return {}; return m_model->unsafe_create_index(index.row(), index.column(), index.internalPointer()); diff --git a/Ladybird/ModelTranslator.h b/Ladybird/ModelTranslator.h index 6890b1e2d0..a276636a1b 100644 --- a/Ladybird/ModelTranslator.h +++ b/Ladybird/ModelTranslator.h @@ -14,9 +14,15 @@ namespace Ladybird { class ModelTranslator final : public QAbstractItemModel { Q_OBJECT public: - explicit ModelTranslator(NonnullRefPtr<GUI::Model>); virtual ~ModelTranslator() override; + void set_underlying_model(RefPtr<GUI::Model> model) + { + beginResetModel(); + m_model = model; + endResetModel(); + } + virtual int columnCount(QModelIndex const& parent) const override; virtual int rowCount(QModelIndex const& parent) const override; virtual QVariant data(QModelIndex const&, int role) const override; |