From bb43bd2dee625da1dbf54ec5e6fc19d0d7b768ae Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 4 Nov 2023 16:30:18 -0400 Subject: [PATCH] Ladybird: Remove the now-unused ModelTranslator --- Ladybird/CMakeLists.txt | 3 +- Ladybird/Qt/ModelTranslator.cpp | 85 --------------------------------- Ladybird/Qt/ModelTranslator.h | 44 ----------------- 3 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 Ladybird/Qt/ModelTranslator.cpp delete mode 100644 Ladybird/Qt/ModelTranslator.h diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index eb56a4ff83c..ace38fde099 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -120,7 +120,6 @@ if (ENABLE_QT) Qt/EventLoopImplementationQtEventTarget.cpp Qt/InspectorWidget.cpp Qt/LocationEdit.cpp - Qt/ModelTranslator.cpp Qt/Settings.cpp Qt/SettingsDialog.cpp Qt/Tab.cpp @@ -178,7 +177,7 @@ target_sources(ladybird PUBLIC FILE_SET ladybird TYPE HEADERS BASE_DIRS ${SERENITY_SOURCE_DIR} FILES ${LADYBIRD_HEADERS} ) -target_link_libraries(ladybird PRIVATE LibCore LibFileSystem LibGfx LibGUI LibImageDecoderClient LibIPC LibJS LibMain LibWeb LibWebView LibProtocol) +target_link_libraries(ladybird PRIVATE LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibJS LibMain LibWeb LibWebView LibProtocol) target_include_directories(ladybird PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/) diff --git a/Ladybird/Qt/ModelTranslator.cpp b/Ladybird/Qt/ModelTranslator.cpp deleted file mode 100644 index 293e8cd1d52..00000000000 --- a/Ladybird/Qt/ModelTranslator.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "ModelTranslator.h" -#include "StringUtils.h" -#include - -namespace Ladybird { - -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)); -} - -static QVariant convert_variant(GUI::Variant const& value) -{ - if (value.is_string()) - return qstring_from_ak_deprecated_string(value.as_string()); - if (value.is_icon()) { - auto const& gui_icon = value.as_icon(); - auto bitmap = gui_icon.bitmap_for_size(16); - VERIFY(bitmap); - auto qt_image = QImage(bitmap->scanline_u8(0), 16, 16, QImage::Format_ARGB32); - QIcon qt_icon; - qt_icon.addPixmap(QPixmap::fromImage(qt_image.convertToFormat(QImage::Format::Format_ARGB32_Premultiplied))); - return qt_icon; - } - return {}; -} - -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)); - case Qt::DecorationRole: - return convert_variant(m_model->data(to_gui(index), GUI::ModelRole::Icon)); - default: - return {}; - } -} - -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))); -} - -QModelIndex ModelTranslator::to_qt(GUI::ModelIndex const& index) const -{ - if (!index.is_valid()) - return {}; - return createIndex(index.row(), index.column(), index.internal_data()); -} - -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/Qt/ModelTranslator.h b/Ladybird/Qt/ModelTranslator.h deleted file mode 100644 index 40f7c4cde0c..00000000000 --- a/Ladybird/Qt/ModelTranslator.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace Ladybird { - -class ModelTranslator final : public QAbstractItemModel { - Q_OBJECT -public: - virtual ~ModelTranslator() override; - - void set_underlying_model(RefPtr model) - { - beginResetModel(); - m_model = model; - endResetModel(); - } - - RefPtr underlying_model() - { - return m_model; - } - - 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; - virtual QModelIndex index(int row, int column, QModelIndex const& parent) const override; - virtual QModelIndex parent(QModelIndex const& index) const override; - - QModelIndex to_qt(GUI::ModelIndex const&) const; - GUI::ModelIndex to_gui(QModelIndex const&) const; - -private: - RefPtr m_model; -}; - -}