]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Remove KStandardItem and KStandardItemModel
authorKai Uwe Broulik <kde@privat.broulik.de>
Thu, 16 Dec 2021 18:37:39 +0000 (19:37 +0100)
committerKai Uwe Broulik <kde@privat.broulik.de>
Tue, 11 Jan 2022 12:43:44 +0000 (13:43 +0100)
They were used by the custom places panel and are now unused.

src/CMakeLists.txt
src/kitemviews/kstandarditem.cpp [deleted file]
src/kitemviews/kstandarditem.h [deleted file]
src/kitemviews/kstandarditemmodel.cpp [deleted file]
src/kitemviews/kstandarditemmodel.h [deleted file]
src/tests/CMakeLists.txt
src/tests/kstandarditemmodeltest.cpp [deleted file]

index a3a15aaf3beb8c976dc77930a399b8a60729975f..016edb8d3c2e3eb03581e8477d7d5163178d1e03 100644 (file)
@@ -74,11 +74,9 @@ target_sources(dolphinprivate PRIVATE
     kitemviews/kitemlistwidget.cpp
     kitemviews/kitemmodelbase.cpp
     kitemviews/kitemset.cpp
     kitemviews/kitemlistwidget.cpp
     kitemviews/kitemmodelbase.cpp
     kitemviews/kitemset.cpp
-    kitemviews/kstandarditem.cpp
     kitemviews/kstandarditemlistgroupheader.cpp
     kitemviews/kstandarditemlistwidget.cpp
     kitemviews/kstandarditemlistview.cpp
     kitemviews/kstandarditemlistgroupheader.cpp
     kitemviews/kstandarditemlistwidget.cpp
     kitemviews/kstandarditemlistview.cpp
-    kitemviews/kstandarditemmodel.cpp
     kitemviews/private/kdirectorycontentscounter.cpp
     kitemviews/private/kdirectorycontentscounterworker.cpp
     kitemviews/private/kfileitemclipboard.cpp
     kitemviews/private/kdirectorycontentscounter.cpp
     kitemviews/private/kdirectorycontentscounterworker.cpp
     kitemviews/private/kfileitemclipboard.cpp
diff --git a/src/kitemviews/kstandarditem.cpp b/src/kitemviews/kstandarditem.cpp
deleted file mode 100644 (file)
index fcaa50b..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#include "kstandarditem.h"
-#include "kstandarditemmodel.h"
-
-KStandardItem::KStandardItem(KStandardItem* parent) :
-    QObject(parent),
-    m_model(nullptr),
-    m_data()
-{
-}
-
-KStandardItem::KStandardItem(const QString& text, KStandardItem* parent) :
-    QObject(parent),
-    m_model(nullptr),
-    m_data()
-{
-    setText(text);
-}
-
-KStandardItem::KStandardItem(const QString& icon, const QString& text, KStandardItem* parent) :
-    QObject(parent),
-    m_model(nullptr),
-    m_data()
-{
-    setIcon(icon);
-    setText(text);
-}
-
-KStandardItem::~KStandardItem()
-{
-}
-
-void KStandardItem::setText(const QString& text)
-{
-    setDataValue("text", text);
-}
-
-QString KStandardItem::text() const
-{
-    return m_data["text"].toString();
-}
-
-void KStandardItem::setIcon(const QString& icon)
-{
-    setDataValue("iconName", icon);
-}
-
-QString KStandardItem::icon() const
-{
-    return m_data["iconName"].toString();
-}
-
-void KStandardItem::setIconOverlays(const QStringList& overlays)
-{
-    setDataValue("iconOverlays", overlays);
-}
-
-QStringList KStandardItem::iconOverlays() const
-{
-    return m_data["iconOverlays"].toStringList();
-}
-
-void KStandardItem::setGroup(const QString& group)
-{
-    setDataValue("group", group);
-}
-
-QString KStandardItem::group() const
-{
-    return m_data["group"].toString();
-}
-
-void KStandardItem::setDataValue(const QByteArray& role, const QVariant& value)
-{
-    const QVariant previous = m_data.value(role);
-    if (previous == value) {
-        return;
-    }
-
-    m_data.insert(role, value);
-    onDataValueChanged(role, value, previous);
-
-    if (m_model) {
-        const int index = m_model->index(this);
-        QSet<QByteArray> changedRoles;
-        changedRoles.insert(role);
-        m_model->onItemChanged(index, changedRoles);
-        Q_EMIT m_model->itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
-    }
-}
-
-QVariant KStandardItem::dataValue(const QByteArray& role) const
-{
-    return m_data[role];
-}
-
-void KStandardItem::setData(const QHash<QByteArray, QVariant>& values)
-{
-    const QHash<QByteArray, QVariant> previous = m_data;
-    m_data = values;
-    onDataChanged(values, previous);
-}
-
-QHash<QByteArray, QVariant> KStandardItem::data() const
-{
-    return m_data;
-}
-
-void KStandardItem::onDataValueChanged(const QByteArray& role,
-                                       const QVariant& current,
-                                       const QVariant& previous)
-{
-    Q_UNUSED(role)
-    Q_UNUSED(current)
-    Q_UNUSED(previous)
-}
-
-void KStandardItem::onDataChanged(const QHash<QByteArray, QVariant>& current,
-                                  const QHash<QByteArray, QVariant>& previous)
-{
-    Q_UNUSED(current)
-    Q_UNUSED(previous)
-}
-
diff --git a/src/kitemviews/kstandarditem.h b/src/kitemviews/kstandarditem.h
deleted file mode 100644 (file)
index fb64b33..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#ifndef KSTANDARDITEM_H
-#define KSTANDARDITEM_H
-
-#include "dolphin_export.h"
-
-#include <QByteArray>
-#include <QHash>
-#include <QObject>
-#include <QSet>
-#include <QVariant>
-
-class KStandardItemModel;
-
-/**
- * @brief Represents and item of KStandardItemModel.
- *
- * Provides setter- and getter-methods for the most commonly
- * used roles. It is possible to assign values for custom
- * roles by using setDataValue().
- */
-class DOLPHIN_EXPORT KStandardItem : public QObject
-{
-    Q_OBJECT
-public:
-    explicit KStandardItem(KStandardItem* parent = nullptr);
-    explicit KStandardItem(const QString& text, KStandardItem* parent = nullptr);
-    KStandardItem(const QString& icon, const QString& text, KStandardItem* parent = nullptr);
-    ~KStandardItem() override;
-
-    /**
-     * Sets the text for the "text"-role.
-     */
-    void setText(const QString& text);
-    QString text() const;
-
-    /**
-     * Sets the icon for the "iconName"-role.
-     */
-    void setIcon(const QString& icon);
-    QString icon() const;
-
-    void setIconOverlays(const QStringList& overlays);
-    QStringList iconOverlays() const;
-
-    /**
-     * Sets the group for the "group"-role.
-     */
-    void setGroup(const QString& group);
-    QString group() const;
-
-    void setDataValue(const QByteArray& role, const QVariant& value);
-    QVariant dataValue(const QByteArray& role) const;
-
-    void setData(const QHash<QByteArray, QVariant>& values);
-    QHash<QByteArray, QVariant> data() const;
-
-protected:
-    virtual void onDataValueChanged(const QByteArray& role,
-                                    const QVariant& current,
-                                    const QVariant& previous);
-
-    virtual void onDataChanged(const QHash<QByteArray, QVariant>& current,
-                               const QHash<QByteArray, QVariant>& previous);
-
-private:
-    KStandardItemModel* m_model;
-
-    QHash<QByteArray, QVariant> m_data;
-
-    friend class KStandardItemModel;
-};
-
-#endif
-
-
diff --git a/src/kitemviews/kstandarditemmodel.cpp b/src/kitemviews/kstandarditemmodel.cpp
deleted file mode 100644 (file)
index 128841c..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#include "kstandarditemmodel.h"
-
-#include "kstandarditem.h"
-
-KStandardItemModel::KStandardItemModel(QObject* parent) :
-    KItemModelBase(parent),
-    m_items(),
-    m_indexesForItems()
-{
-}
-
-KStandardItemModel::~KStandardItemModel()
-{
-    qDeleteAll(m_items);
-    m_items.clear();
-    m_indexesForItems.clear();
-}
-
-void KStandardItemModel::insertItem(int index, KStandardItem* item)
-{
-    if (index < 0 || index > count() || !item) {
-        delete item;
-        return;
-    }
-
-    if (!m_indexesForItems.contains(item)) {
-        item->m_model = this;
-        m_items.insert(index, item);
-        m_indexesForItems.insert(item, index);
-
-        // Inserting an item requires to update the indexes
-        // afterwards from m_indexesForItems.
-        for (int i = index + 1; i < m_items.count(); ++i) {
-            m_indexesForItems.insert(m_items[i], i);
-        }
-
-        // TODO: no hierarchical items are handled yet
-
-        onItemInserted(index);
-        Q_EMIT itemsInserted(KItemRangeList() << KItemRange(index, 1));
-    }
-}
-
-void KStandardItemModel::changeItem(int index, KStandardItem* item)
-{
-    if (index < 0 || index >= count() || !item) {
-        delete item;
-        return;
-    }
-
-    item->m_model = this;
-
-    QSet<QByteArray> changedRoles;
-
-    KStandardItem* oldItem = m_items[index];
-    const QHash<QByteArray, QVariant> oldData = oldItem->data();
-    const QHash<QByteArray, QVariant> newData = item->data();
-
-    // Determine which roles have been changed
-    QHashIterator<QByteArray, QVariant> it(oldData);
-    while (it.hasNext()) {
-        it.next();
-        const QByteArray role = it.key();
-        const QVariant oldValue = it.value();
-        if (newData.contains(role) && newData.value(role) != oldValue) {
-            changedRoles.insert(role);
-        }
-    }
-
-    m_indexesForItems.remove(oldItem);
-    delete oldItem;
-    oldItem = nullptr;
-
-    m_items[index] = item;
-    m_indexesForItems.insert(item, index);
-
-    onItemChanged(index, changedRoles);
-    Q_EMIT itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
-}
-
-void KStandardItemModel::removeItem(int index)
-{
-    if (index >= 0 && index < count()) {
-        KStandardItem* item = m_items[index];
-        m_indexesForItems.remove(item);
-        m_items.removeAt(index);
-
-        // Removing an item requires to update the indexes
-        // afterwards from m_indexesForItems.
-        for (int i = index; i < m_items.count(); ++i) {
-            m_indexesForItems.insert(m_items[i], i);
-        }
-
-        onItemRemoved(index, item);
-
-        item->deleteLater();
-        item = nullptr;
-
-        Q_EMIT itemsRemoved(KItemRangeList() << KItemRange(index, 1));
-
-        // TODO: no hierarchical items are handled yet
-    }
-}
-
-void KStandardItemModel::clear()
-{
-    int size = m_items.size();
-    m_items.clear();
-    m_indexesForItems.clear();
-
-    Q_EMIT itemsRemoved(KItemRangeList() << KItemRange(0, size));
-}
-
-KStandardItem* KStandardItemModel::item(int index) const
-{
-    if (index < 0 || index >= m_items.count()) {
-        return nullptr;
-    }
-    return m_items[index];
-}
-
-int KStandardItemModel::index(const KStandardItem* item) const
-{
-    return m_indexesForItems.value(item, -1);
-}
-
-void KStandardItemModel::appendItem(KStandardItem *item)
-{
-    insertItem(m_items.count(), item);
-}
-
-int KStandardItemModel::count() const
-{
-    return m_items.count();
-}
-
-QHash<QByteArray, QVariant> KStandardItemModel::data(int index) const
-{
-    if (index >= 0 && index < count()) {
-        const KStandardItem* item = m_items[index];
-        if (item) {
-            return item->data();
-        }
-    }
-    return QHash<QByteArray, QVariant>();
-}
-
-bool KStandardItemModel::setData(int index, const QHash<QByteArray, QVariant>& values)
-{
-    Q_UNUSED(values)
-    if (index < 0 || index >= count()) {
-        return false;
-    }
-
-    return true;
-}
-
-QMimeData* KStandardItemModel::createMimeData(const KItemSet& indexes) const
-{
-    Q_UNUSED(indexes)
-    return nullptr;
-}
-
-int KStandardItemModel::indexForKeyboardSearch(const QString& text, int startFromIndex) const
-{
-    Q_UNUSED(text)
-    Q_UNUSED(startFromIndex)
-    return -1;
-}
-
-bool KStandardItemModel::supportsDropping(int index) const
-{
-    Q_UNUSED(index)
-    return false;
-}
-
-QString KStandardItemModel::roleDescription(const QByteArray& role) const
-{
-    Q_UNUSED(role)
-    return QString();
-}
-
-QList<QPair<int, QVariant> > KStandardItemModel::groups() const
-{
-    QList<QPair<int, QVariant> > groups;
-
-    const QByteArray role = sortRole().isEmpty() ? "group" : sortRole();
-    bool isFirstGroupValue = true;
-    QString groupValue;
-    const int maxIndex = count() - 1;
-    for (int i = 0; i <= maxIndex; ++i) {
-        const QString newGroupValue = m_items.at(i)->dataValue(role).toString();
-        if (newGroupValue != groupValue || isFirstGroupValue) {
-            groupValue = newGroupValue;
-            groups.append(QPair<int, QVariant>(i, newGroupValue));
-            isFirstGroupValue = false;
-        }
-    }
-
-    return groups;
-}
-
-void KStandardItemModel::onItemInserted(int index)
-{
-    Q_UNUSED(index)
-}
-
-void KStandardItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRoles)
-{
-    Q_UNUSED(index)
-    Q_UNUSED(changedRoles)
-}
-
-void KStandardItemModel::onItemRemoved(int index, KStandardItem* removedItem)
-{
-    Q_UNUSED(index)
-    Q_UNUSED(removedItem)
-}
-
diff --git a/src/kitemviews/kstandarditemmodel.h b/src/kitemviews/kstandarditemmodel.h
deleted file mode 100644 (file)
index d92ec5d..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#ifndef KSTANDARDITEMMODEL_H
-#define KSTANDARDITEMMODEL_H
-
-#include "dolphin_export.h"
-#include "kitemviews/kitemmodelbase.h"
-
-#include <QHash>
-#include <QList>
-
-class KStandardItem;
-
-/**
- * @brief Model counterpart for KStandardItemListView.
- *
- * Allows to add items to the model in an easy way by the
- * class KStandardItem.
- *
- * @see KStandardItem
- */
-class DOLPHIN_EXPORT KStandardItemModel : public KItemModelBase
-{
-    Q_OBJECT
-
-public:
-    explicit KStandardItemModel(QObject* parent = nullptr);
-    ~KStandardItemModel() override;
-
-    /**
-     * Inserts the item \a item at the index \a index. If the index
-     * is equal to the number of items of the model, the item
-     * gets appended as last element. KStandardItemModel takes
-     * the ownership of the item. If the index is invalid, the item
-     * gets deleted.
-     */
-    void insertItem(int index, KStandardItem* item);
-
-    /**
-     * Changes the item on the index \a index to \a item.
-     * KStandardItemModel takes the ownership of the item. The
-     * old item gets deleted. If the index is invalid, the item
-     * gets deleted.
-     */
-    void changeItem(int index, KStandardItem* item);
-
-    void removeItem(int index);
-    KStandardItem* item(int index) const;
-    int index(const KStandardItem* item) const;
-
-    /**
-     * Convenience method for insertItem(count(), item).
-     */
-    void appendItem(KStandardItem* item);
-
-    int count() const override;
-    QHash<QByteArray, QVariant> data(int index) const override;
-    bool setData(int index, const QHash<QByteArray, QVariant>& values) override;
-    QMimeData* createMimeData(const KItemSet& indexes) const override;
-    int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const override;
-    bool supportsDropping(int index) const override;
-    QString roleDescription(const QByteArray& role) const override;
-    QList<QPair<int, QVariant> > groups() const override;
-
-    virtual void clear();
-protected:
-    /**
-     * Is invoked after an item has been inserted and before the signal
-     * itemsInserted() gets emitted.
-     */
-    virtual void onItemInserted(int index);
-
-    /**
-     * Is invoked after an item or one of its roles has been changed and
-     * before the signal itemsChanged() gets emitted.
-     */
-    virtual void onItemChanged(int index, const QSet<QByteArray>& changedRoles);
-
-    /**
-     * Is invoked after an item has been removed and before the signal
-     * itemsRemoved() gets emitted. The item \a removedItem has already
-     * been removed from the model and will get deleted after the
-     * execution of onItemRemoved().
-     */
-    virtual void onItemRemoved(int index, KStandardItem* removedItem);
-
-private:
-    QList<KStandardItem*> m_items;
-    QHash<const KStandardItem*, int> m_indexesForItems;
-
-    friend class KStandardItem;
-    friend class KStandardItemModelTest;  // For unit testing
-};
-
-#endif
-
-
index 95ba0186185208cb3236330e1e3a871842755c36..909bc9edf607800f69380d9effd76364d59bac2a 100644 (file)
@@ -51,11 +51,6 @@ if (KF5Baloo_FOUND)
     LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test)
 endif()
 
     LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test)
 endif()
 
-# KStandardItemModelTest
-ecm_add_test(kstandarditemmodeltest.cpp
-TEST_NAME kstandarditemmodeltest
-LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test)
-
 # ViewPropertiesTest
 ecm_add_test(viewpropertiestest.cpp testdir.cpp
 TEST_NAME viewpropertiestest
 # ViewPropertiesTest
 ecm_add_test(viewpropertiestest.cpp testdir.cpp
 TEST_NAME viewpropertiestest
diff --git a/src/tests/kstandarditemmodeltest.cpp b/src/tests/kstandarditemmodeltest.cpp
deleted file mode 100644 (file)
index 943a852..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
- * SPDX-FileCopyrightText: 2011 Frank Reininghaus <frank78ac@googlemail.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#include "dolphindebug.h"
-
-#include "kitemviews/kstandarditem.h"
-#include "kitemviews/kstandarditemmodel.h"
-
-#include <QStandardPaths>
-#include <QTest>
-
-class KStandardItemModelTest : public QObject
-{
-    Q_OBJECT
-
-private Q_SLOTS:
-    void initTestCase();
-    void init();
-    void cleanup();
-
-    void testNewItems();
-    void testRemoveItems();
-
-private:
-    bool isModelConsistent() const;
-
-private:
-    KStandardItemModel* m_model;
-};
-
-void KStandardItemModelTest::initTestCase()
-{
-    QStandardPaths::setTestModeEnabled(true);
-}
-
-void KStandardItemModelTest::init()
-{
-    m_model = new KStandardItemModel();
-}
-
-void KStandardItemModelTest::cleanup()
-{
-    delete m_model;
-    m_model = nullptr;
-}
-
-void KStandardItemModelTest::testNewItems()
-{
-    m_model->insertItem(0, new KStandardItem("item 1"));
-    m_model->insertItem(0, new KStandardItem("item 2"));
-    m_model->insertItem(2, new KStandardItem("item 3"));
-    m_model->appendItem(new KStandardItem("item 4"));
-    m_model->insertItem(-1, new KStandardItem("invalid 1"));
-    m_model->insertItem(5, new KStandardItem("invalid 2"));
-    QCOMPARE(m_model->count(), 4);
-    QCOMPARE(m_model->item(0)->text(), QString("item 2"));
-    QCOMPARE(m_model->item(1)->text(), QString("item 1"));
-    QCOMPARE(m_model->item(2)->text(), QString("item 3"));
-    QCOMPARE(m_model->item(3)->text(), QString("item 4"));
-
-    QVERIFY(isModelConsistent());
-}
-
-void KStandardItemModelTest::testRemoveItems()
-{
-    for (int i = 1; i <= 10; ++i) {
-        m_model->appendItem(new KStandardItem("item " + QString::number(i)));
-    }
-
-    m_model->removeItem(0);
-    m_model->removeItem(3);
-    m_model->removeItem(5);
-    m_model->removeItem(-1);
-    QCOMPARE(m_model->count(), 7);
-    QCOMPARE(m_model->item(0)->text(), QString("item 2"));
-    QCOMPARE(m_model->item(1)->text(), QString("item 3"));
-    QCOMPARE(m_model->item(2)->text(), QString("item 4"));
-    QCOMPARE(m_model->item(3)->text(), QString("item 6"));
-    QCOMPARE(m_model->item(4)->text(), QString("item 7"));
-    QCOMPARE(m_model->item(5)->text(), QString("item 9"));
-    QCOMPARE(m_model->item(6)->text(), QString("item 10"));
-}
-
-bool KStandardItemModelTest::isModelConsistent() const
-{
-    if (m_model->m_items.count() != m_model->m_indexesForItems.count()) {
-        return false;
-    }
-
-    for (int i = 0; i < m_model->count(); ++i) {
-        const KStandardItem* item = m_model->item(i);
-        if (!item) {
-            qCWarning(DolphinDebug) << "Item" << i << "is null";
-            return false;
-        }
-
-        const int itemIndex = m_model->index(item);
-        if (itemIndex != i) {
-            qCWarning(DolphinDebug) << "Item" << i << "has a wrong index:" << itemIndex;
-            return false;
-        }
-    }
-
-    return true;
-}
-
-QTEST_GUILESS_MAIN(KStandardItemModelTest)
-
-#include "kstandarditemmodeltest.moc"