[graphics/drawy] src/gui/customelements: Allow to export file

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 1f283f07a6802309246a8cc45287d2ec6a5b0217 by Laurent Montel.
Committed on 18/07/2026 at 21:08.
Pushed by mlaurent into branch 'master'.

Allow to export file

M  +7    -4    src/gui/customelements/customelementsmanager.cpp
M  +1    -1    src/gui/customelements/customelementsmanager.hpp

https://invent.kde.org/graphics/drawy/-/commit/1f283f07a6802309246a8cc45287d2ec6a5b0217

diff --git a/src/gui/customelements/customelementsmanager.cpp b/src/gui/customelements/customelementsmanager.cpp
index 5ac3497f..be6dde1f 100644
--- a/src/gui/customelements/customelementsmanager.cpp
+++ b/src/gui/customelements/customelementsmanager.cpp
@@ -54,7 +54,7 @@ void CustomElementsManager::loadCustomElements()
     }
 }
 
-void CustomElementsManager::saveCustomElements()
+void CustomElementsManager::saveCustomElements(const QString &fileName)
 {
     QJsonObject obj;
     obj["version"_L1] = QString::number(1);
@@ -63,7 +63,7 @@ void CustomElementsManager::saveCustomElements()
         elementsObj.append(element.save());
     }
     obj["librairies"_L1] = elementsObj;
-    const auto path = CustomElementsUtils::customElementsFilePath();
+    const auto path = fileName.isEmpty() ? CustomElementsUtils::customElementsFilePath() : fileName;
     QFile file(path);
     if (!file.open(QFile::WriteOnly)) {
         qCWarning(DRAWY_GUI_LOG) << "Impossible to open file: " << file.errorString();
@@ -78,8 +78,11 @@ void CustomElementsManager::saveCustomElements()
 
 void CustomElementsManager::exportToFile(const QString &fileName)
 {
-    Q_UNUSED(fileName);
-    // TODO
+    if (mCustomElements.isEmpty()) {
+        qCWarning(DRAWY_GUI_LOG) << "Custom Elements list is empty";
+        return;
+    }
+    saveCustomElements(fileName);
 }
 
 void CustomElementsManager::addItem(const std::shared_ptr<Item> &item)
diff --git a/src/gui/customelements/customelementsmanager.hpp b/src/gui/customelements/customelementsmanager.hpp
index 4c28fad4..ab0315d7 100644
--- a/src/gui/customelements/customelementsmanager.hpp
+++ b/src/gui/customelements/customelementsmanager.hpp
@@ -20,7 +20,7 @@ public:
     static CustomElementsManager *self();
 
     void loadCustomElements();
-    void saveCustomElements();
+    void saveCustomElements(const QString &fileName = {});
 
     [[nodiscard]] bool isEmpty() const;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.