[graphics/drawy] src: Add customelementslistview
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit dea0fff3f79bbfebbad44e02b7af2dd7474a41e0 by Laurent Montel.
Committed on 27/07/2026 at 11:15.
Pushed by mlaurent into branch 'master'.
Add customelementslistview
M +3 -1 src/gui/customelements/customelementsmodel.cpp
M +1 -0 src/gui/customelements/customelementsmodel.hpp
M +2 -2 src/gui/customelements/customelementsutils.cpp
M +2 -0 src/widgets/CMakeLists.txt
M +1 -0 src/widgets/autotests/CMakeLists.txt
A +21 -0 src/widgets/autotests/customelementslistviewtest.cpp [License: GPL(v3.0+)]
A +19 -0 src/widgets/autotests/customelementslistviewtest.hpp [License: GPL(v3.0+)]
A +15 -0 src/widgets/customelementswidget/customelementslistview.cpp [License: GPL(v3.0+)]
A +16 -0 src/widgets/customelementswidget/customelementslistview.hpp [License: GPL(v3.0+)]
M +2 -1 src/widgets/customelementswidget/customelementswidget.cpp
M +2 -2 src/widgets/customelementswidget/customelementswidget.hpp
M +4 -3 src/widgets/keybindings/actionmanager.cpp
https://invent.kde.org/graphics/drawy/-/commit/dea0fff3f79bbfebbad44e02b7af2dd7474a41e0
diff --git a/src/gui/customelements/customelementsmodel.cpp b/src/gui/customelements/customelementsmodel.cpp
index 6373da88..ef2b044c 100644
--- a/src/gui/customelements/customelementsmodel.cpp
+++ b/src/gui/customelements/customelementsmodel.cpp
@@ -21,7 +21,7 @@ int CustomElementsModel::rowCount(const QModelIndex &parent) const
return mCustomElements.count();
}
-QVariant CustomElementsModel::data([[maybe_unused]] const QModelIndex &index, [[maybe_unused]] int role) const
+QVariant CustomElementsModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= mCustomElements.count()) {
return {};
@@ -30,6 +30,8 @@ QVariant CustomElementsModel::data([[maybe_unused]] const QModelIndex &index, [[
switch (role) {
case TimeStamp:
return customElement.timeStamp();
+ case Icon:
+ return {};
}
return {};
}
diff --git a/src/gui/customelements/customelementsmodel.hpp b/src/gui/customelements/customelementsmodel.hpp
index a5dc041d..92a684a5 100644
--- a/src/gui/customelements/customelementsmodel.hpp
+++ b/src/gui/customelements/customelementsmodel.hpp
@@ -16,6 +16,7 @@ class LIBDRAWYGUI_EXPORT CustomElementsModel : public QAbstractListModel
public:
enum CustomElementRoles {
TimeStamp = Qt::UserRole + 1,
+ Icon,
};
Q_ENUM(CustomElementRoles)
diff --git a/src/gui/customelements/customelementsutils.cpp b/src/gui/customelements/customelementsutils.cpp
index f6588463..fff03c7c 100644
--- a/src/gui/customelements/customelementsutils.cpp
+++ b/src/gui/customelements/customelementsutils.cpp
@@ -9,7 +9,7 @@
using namespace Qt::Literals::StringLiterals;
QString CustomElementsUtils::customElementsFilePath()
{
- const QString customElementsPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/custom-elements/"_s;
+ const QString customElementsPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QDir().mkpath(customElementsPath);
- return customElementsPath;
+ return customElementsPath + u"/custom-elements"_s;
}
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index 1626bbcf..9c13a5ec 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -254,6 +254,8 @@ target_sources(
common/renderitems.hpp
customelementswidget/customelementswidget.hpp
customelementswidget/customelementswidget.cpp
+ customelementswidget/customelementslistview.hpp
+ customelementswidget/customelementslistview.cpp
)
if(USE_DBUS)
diff --git a/src/widgets/autotests/CMakeLists.txt b/src/widgets/autotests/CMakeLists.txt
index 0fe04a0b..404982bf 100644
--- a/src/widgets/autotests/CMakeLists.txt
+++ b/src/widgets/autotests/CMakeLists.txt
@@ -78,3 +78,4 @@ set_tests_properties(
add_drawy_unittest(cornerrectangletypewidgettest.cpp)
add_drawy_unittest(customelementswidgettest.cpp)
+add_drawy_unittest(customelementslistviewtest.cpp)
diff --git a/src/widgets/autotests/customelementslistviewtest.cpp b/src/widgets/autotests/customelementslistviewtest.cpp
new file mode 100644
index 00000000..18290e8e
--- /dev/null
+++ b/src/widgets/autotests/customelementslistviewtest.cpp
@@ -0,0 +1,21 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "customelementslistviewtest.hpp"
+#include "customelementswidget/customelementslistview.hpp"
+#include <QTest>
+using namespace Qt::Literals::StringLiterals;
+QTEST_MAIN(CustomElementsListViewTest)
+CustomElementsListViewTest::CustomElementsListViewTest(QObject *parent)
+ : QObject{parent}
+{
+}
+
+void CustomElementsListViewTest::shouldHaveDefaultValues()
+{
+ const CustomElementsListView w(nullptr);
+ // TODO add check
+ Q_UNUSED(w)
+}
diff --git a/src/widgets/autotests/customelementslistviewtest.hpp b/src/widgets/autotests/customelementslistviewtest.hpp
new file mode 100644
index 00000000..8338f4d0
--- /dev/null
+++ b/src/widgets/autotests/customelementslistviewtest.hpp
@@ -0,0 +1,19 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#pragma once
+
+#include <QObject>
+
+class CustomElementsListViewTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit CustomElementsListViewTest(QObject *parent = nullptr);
+ ~CustomElementsListViewTest() override = default;
+
+private Q_SLOTS:
+ void shouldHaveDefaultValues();
+};
diff --git a/src/widgets/customelementswidget/customelementslistview.cpp b/src/widgets/customelementswidget/customelementslistview.cpp
new file mode 100644
index 00000000..48d1c28b
--- /dev/null
+++ b/src/widgets/customelementswidget/customelementslistview.cpp
@@ -0,0 +1,15 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "customelementslistview.hpp"
+
+CustomElementsListView::CustomElementsListView(QWidget *parent)
+ : QListView(parent)
+{
+}
+
+CustomElementsListView::~CustomElementsListView() = default;
+
+#include "moc_customelementslistview.cpp"
diff --git a/src/widgets/customelementswidget/customelementslistview.hpp b/src/widgets/customelementswidget/customelementslistview.hpp
new file mode 100644
index 00000000..3d36b733
--- /dev/null
+++ b/src/widgets/customelementswidget/customelementslistview.hpp
@@ -0,0 +1,16 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Laurent Montel <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#pragma once
+
+#include "libdrawywidgets_private_export.h"
+#include <QListView>
+class LIBDRAWYWIDGETS_TESTS_EXPORT CustomElementsListView : public QListView
+{
+ Q_OBJECT
+public:
+ explicit CustomElementsListView(QWidget *parent = nullptr);
+ ~CustomElementsListView() override;
+};
diff --git a/src/widgets/customelementswidget/customelementswidget.cpp b/src/widgets/customelementswidget/customelementswidget.cpp
index db0c7a15..1076361d 100644
--- a/src/widgets/customelementswidget/customelementswidget.cpp
+++ b/src/widgets/customelementswidget/customelementswidget.cpp
@@ -6,12 +6,13 @@
#include "customelementswidget.hpp"
#include "customelements/customelementsmanager.hpp"
#include "customelements/customelementsmodel.hpp"
+#include "customelementswidget/customelementslistview.hpp"
#include <QListView>
#include <QVBoxLayout>
using namespace Qt::Literals::StringLiterals;
CustomElementsWidget::CustomElementsWidget(CustomElementsManager *manager, QWidget *parent)
: QWidget{parent}
- , mListView(new QListView(this))
+ , mListView(new CustomElementsListView(this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(u"mainLayout"_s);
diff --git a/src/widgets/customelementswidget/customelementswidget.hpp b/src/widgets/customelementswidget/customelementswidget.hpp
index 8c181a90..c2004dd9 100644
--- a/src/widgets/customelementswidget/customelementswidget.hpp
+++ b/src/widgets/customelementswidget/customelementswidget.hpp
@@ -6,7 +6,7 @@
#pragma once
#include "libdrawywidgets_private_export.h"
#include <QWidget>
-class QListView;
+class CustomElementsListView;
class CustomElementsManager;
class LIBDRAWYWIDGETS_TESTS_EXPORT CustomElementsWidget : public QWidget
{
@@ -16,5 +16,5 @@ public:
~CustomElementsWidget() override;
private:
- QListView *const mListView;
+ CustomElementsListView *const mListView;
};
diff --git a/src/widgets/keybindings/actionmanager.cpp b/src/widgets/keybindings/actionmanager.cpp
index 2b82aa6c..1b6c8f02 100644
--- a/src/widgets/keybindings/actionmanager.cpp
+++ b/src/widgets/keybindings/actionmanager.cpp
@@ -30,6 +30,7 @@
#include "command/ungroupcommand.hpp"
#include "command/zordercommand.hpp"
#include "common/constants.hpp"
+#include "customelements/customelementsmanager.hpp"
#include "dialog/configuresettingsdialog.hpp"
#include "event/event.hpp"
#include "jobs/serializejob.hpp"
@@ -815,10 +816,10 @@ void ActionManager::slotUpdateZorderAndGroupButtons()
void ActionManager::slotAddCustomElement()
{
const QList<std::shared_ptr<Item>> items = dynamic_cast<SelectionTool &>(m_context->uiContext()->toolBar()->curTool()).getItemsUnderCursor(m_context);
- if (items.size() == 1 && items.at(0)->locked()) {
- // TODO
+ if (items.size() == 1) {
+ auto manager = m_context->uiContext()->customElementsManager();
+ manager->addItem(items.constFirst());
}
- // TODO
}
#include "moc_actionmanager.cpp"