From 01df15fafab7002a1d02dbf7f364c1f7369242f7 Mon Sep 17 00:00:00 2001 From: Cyril Jacquet Date: Sun, 10 Apr 2022 20:47:27 +0200 Subject: [PATCH 1/4] fix crash when drag drop below items --- .../NavigationListView.qml | 17 +++++- src/translations/skribisto_en_US.ts | 52 +++++++++---------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/plugins/navigationProjectToolbox/NavigationListView.qml b/src/plugins/navigationProjectToolbox/NavigationListView.qml index 8a9dc4776..69dd50530 100644 --- a/src/plugins/navigationProjectToolbox/NavigationListView.qml +++ b/src/plugins/navigationProjectToolbox/NavigationListView.qml @@ -229,15 +229,28 @@ Item { onExited: { } - onDropped: { + onDropped: function(drop){ if (drop.proposedAction === Qt.MoveAction) { listView.interactive = true priv.dragging = false - skrData.treeHub().moveTreeItemAsChildOf(drag.source.projectId, drag.source.treeItemId, projectId, parentId) + console.log("onDropped", drag.source.projectId, drag.source.treeItemId, projectId, parentId) + focusZoneMoveTreeItemAsChildOfTimer.sourceProjectId = drag.source.projectId + focusZoneMoveTreeItemAsChildOfTimer.sourceTreeItemId = drag.source.treeItemId + focusZoneMoveTreeItemAsChildOfTimer.start() + //skrData.treeHub().moveTreeItemAsChildOf(drag.source.projectId, drag.source.treeItemId, projectId, parentId) } } + Timer{ + id: focusZoneMoveTreeItemAsChildOfTimer + property int sourceProjectId: -1 + property int sourceTreeItemId: -1 + interval: 1000 + onTriggered: { + skrData.treeHub().moveTreeItemAsChildOf(sourceProjectId, sourceTreeItemId, projectId, parentId) + } + } diff --git a/src/translations/skribisto_en_US.ts b/src/translations/skribisto_en_US.ts index 58b520266..2c6cefae6 100644 --- a/src/translations/skribisto_en_US.ts +++ b/src/translations/skribisto_en_US.ts @@ -1305,132 +1305,132 @@ - + Navigation list - + is a folder - + label: - + has child - + navigation item - + See sub-items - + This project is a backup - + Enter label - + Enter title - + Item menu - + Open - + Open in another view - + Open in a new window - + Set as active project - + Rename - + Set label - + Cut - + Copy - + Paste - + Add before - + Add after - + Add a sub-item - + Move up - + Move down - + Send to trash - + Close this project From 84d4eaa5b87be5839a156143a581bd3a0ac8c82a Mon Sep 17 00:00:00 2001 From: Cyril Jacquet Date: Mon, 11 Apr 2022 00:58:55 +0200 Subject: [PATCH 2/4] copy paste includes sub-items --- src/libskribisto-data/src/skrtreehub.cpp | 87 ++++++++++++++----- src/libskribisto-data/src/skrtreehub.h | 8 +- .../auto/treehubcase/tst_treehubcase.cpp | 43 +++++++++ .../NavigationListView.qml | 3 +- src/translations/skribisto_en_US.ts | 14 +-- 5 files changed, 122 insertions(+), 33 deletions(-) diff --git a/src/libskribisto-data/src/skrtreehub.cpp b/src/libskribisto-data/src/skrtreehub.cpp index 473ae38e2..ae13bdaae 100755 --- a/src/libskribisto-data/src/skrtreehub.cpp +++ b/src/libskribisto-data/src/skrtreehub.cpp @@ -27,7 +27,7 @@ #include SKRTreeHub::SKRTreeHub(QObject *parent) : QObject(parent), m_tableName("tbl_tree"), m_last_added_id(-1), m_cutCopy( - CutCopy()) + CutCopy()) { connect(this, &SKRTreeHub::errorSent, this, &SKRTreeHub::setError, Qt::DirectConnection); @@ -131,6 +131,7 @@ QString SKRTreeHub::getTitle(int projectId, int treeItemId) const SKRResult SKRTreeHub::setInternalTitle(int projectId, int treeItemId, const QString& internalTitle) { + SKRResult result = set(projectId, treeItemId, "t_internal_title", internalTitle); IFOK(result) { @@ -629,7 +630,7 @@ int SKRTreeHub::getLastAddedId() // ---------------------------------------------------------------------------------------- -SKRResult SKRTreeHub::addTreeItem(const QHash& values, int projectId) +SKRResult SKRTreeHub::addTreeItem(const QHash& values, int projectId, bool renumber) { PLMSqlQueries queries(projectId, m_tableName); @@ -637,7 +638,9 @@ SKRResult SKRTreeHub::addTreeItem(const QHash& values, int pr int newId = -1; SKRResult result = queries.add(values, newId); - IFOKDO(result, queries.renumberSortOrder()); + if(renumber){ + IFOKDO(result, queries.renumberSortOrder()); + } IFKO(result) { queries.rollback(); } @@ -871,7 +874,7 @@ SKRResult SKRTreeHub::moveTreeItem(int sourceProjectId, int sourceTreeItemId, in IFOKDO(result, queries.renumberSortOrder()) - IFKO(result) { + IFKO(result) { queries.rollback(); emit errorSent(result); } @@ -927,7 +930,7 @@ SKRResult SKRTreeHub::moveTreeItemUp(int projectId, int treeItemId) if (this->getIndent(projectId, possibleTargetTreeItemId) == - this->getIndent(projectId, treeItemId)) { + this->getIndent(projectId, treeItemId)) { targetTreeItemId = possibleTargetTreeItemId; break; } @@ -948,7 +951,7 @@ SKRResult SKRTreeHub::moveTreeItemUp(int projectId, int treeItemId) IFOKDO(result, this->moveTreeItem(projectId, treeItemId, targetTreeItemId)) - IFKO(result) { + IFKO(result) { emit errorSent(result); } return result; @@ -991,7 +994,7 @@ SKRResult SKRTreeHub::moveTreeItemDown(int projectId, int treeItemId) if (this->getIndent(projectId, possibleTargetTreeItemId) == - this->getIndent(projectId, treeItemId)) { + this->getIndent(projectId, treeItemId)) { targetTreeItemId = possibleTargetTreeItemId; break; } @@ -1012,7 +1015,7 @@ SKRResult SKRTreeHub::moveTreeItemDown(int projectId, int treeItemId) IFOKDO(result, this->moveTreeItem(projectId, treeItemId, targetTreeItemId, true)) - IFKO(result) { + IFKO(result) { emit errorSent(result); } return result; @@ -1487,7 +1490,7 @@ QListSKRTreeHub::getAllSiblings(int projectId, int treeItemId, bool treeIte // alone, so no siblings if ((minSiblingIndex == treeItemSortedIdIndex) && - (maxSiblingIndex == treeItemSortedIdIndex)) { + (maxSiblingIndex == treeItemSortedIdIndex)) { return siblingsList; } @@ -1740,27 +1743,66 @@ int SKRTreeHub::getPreviousTreeItemIdOfTheSameType(int projectId, int treeItemId // ---------------------------------------------------------------------------------------- -SKRResult SKRTreeHub::duplicateTreeItem(int projectId, int treeItemId) +SKRResult SKRTreeHub::duplicateTreeItem(int projectId, int treeItemId, bool duplicateChildren, bool renumber) { SKRResult result(this); + QList resultTreeItemIdList; - // TODO: create duplicate - int newItemId = -2; + QHash values; + int validSortOrder = getValidSortOrderAfterTree(projectId, treeItemId); + + if(duplicateChildren && getAllChildren(projectId, treeItemId).count() > 0){ + validSortOrder -= getAllChildren(projectId, treeItemId).count(); + } - QHash values; values.insert("t_title", getTitle(projectId, treeItemId)); values.insert("l_indent", getIndent(projectId, treeItemId)); - values.insert("l_sort_order", getSortOrder(projectId, treeItemId) + 1); + values.insert("l_sort_order", validSortOrder); values.insert("t_type", getType(projectId, treeItemId)); values.insert("m_primary_content", getPrimaryContent(projectId, treeItemId)); values.insert("m_secondary_content", getSecondaryContent(projectId, treeItemId)); - result = this->addTreeItem(values, projectId); + result = this->addTreeItem(values, projectId, false); + + int newTreeItemId = result.getData("treeItemId", -2).toInt(); + resultTreeItemIdList << newTreeItemId; + if(duplicateChildren){ + QList childrenList = getAllChildren(projectId, treeItemId); + QList childrenNotTrashed; + for(int childId: childrenList){ + if(!getTrashed(projectId, childId)){ + childrenNotTrashed.append(childId); + } + } + childrenList = childrenNotTrashed; + + int sortOrderOffset = 1; + for(int childId: childrenList){ + + QHash childValues; + + childValues.insert("t_title", getTitle(projectId, childId)); + childValues.insert("l_indent", getIndent(projectId, childId)); + childValues.insert("l_sort_order", validSortOrder + sortOrderOffset); + childValues.insert("t_type", getType(projectId, childId)); + childValues.insert("m_primary_content", getPrimaryContent(projectId, childId)); + childValues.insert("m_secondary_content", getSecondaryContent(projectId, childId)); + result = this->addTreeItem(childValues, projectId, false); + + resultTreeItemIdList << result.getData("treeItemId", -2).toInt(); + + sortOrderOffset += 1; + + } + } + if(renumber){ + IFOKDO(result, renumberSortOrders(projectId)) + } IFOK(result) { - result.addData("treeItemId", result.getData("treeItemId", -2)); + result.addData("treeItemIdList", QVariant::fromValue >(resultTreeItemIdList)); } IFKO(result) { emit errorSent(result); @@ -1810,7 +1852,7 @@ void SKRTreeHub::copy(int projectId, QListtreeItemIds) // ---------------------------------------------------------------------------------------- -SKRResult SKRTreeHub::paste(int targetProjectId, int parentTreeItemId) +SKRResult SKRTreeHub::paste(int targetProjectId, int parentTreeItemId, bool copyChildren) { SKRResult result(this); QList treeItemIdList; @@ -1841,14 +1883,15 @@ SKRResult SKRTreeHub::paste(int targetProjectId, int parentTreeItemId) else if (m_cutCopy.type == CutCopy::Type::Copy) { for (int treeItemId : qAsConst(m_cutCopy.treeItemIds)) { if (targetProjectId == sourceProjectId) { - result = this->duplicateTreeItem(sourceProjectId, treeItemId); - int newTreeItemId = result.getData("treeItemId", -2).toInt(); - treeItemIdList << newTreeItemId; + result = this->duplicateTreeItem(sourceProjectId, treeItemId, copyChildren, false); + QList newTreeItemIdList = result.getData("treeItemIdList", + QVariant::fromValue >(QList())).value >(); + treeItemIdList << newTreeItemIdList.first(); IFOKDO(result, - this->moveTreeItemAsChildOf(sourceProjectId, newTreeItemId, targetProjectId, + this->moveTreeItemAsChildOf(sourceProjectId, newTreeItemIdList.first(), targetProjectId, parentTreeItemId, false)) - result = this->renumberSortOrders(targetProjectId); + result = this->renumberSortOrders(targetProjectId); } // TODO: case if projects are different diff --git a/src/libskribisto-data/src/skrtreehub.h b/src/libskribisto-data/src/skrtreehub.h index 179c403dd..7e4a9baf4 100755 --- a/src/libskribisto-data/src/skrtreehub.h +++ b/src/libskribisto-data/src/skrtreehub.h @@ -178,7 +178,7 @@ class EXPORT SKRTreeHub : public QObject { Q_INVOKABLE int getLastAddedId(); SKRResult addTreeItem(const QHash& values, - int projectId); + int projectId, bool renumber= true); Q_INVOKABLE SKRResult addTreeItemAbove(int projectId, int targetId, const QString& type); @@ -252,13 +252,15 @@ class EXPORT SKRTreeHub : public QObject { int treeItemId); Q_INVOKABLE SKRResult duplicateTreeItem(int projectId, - int treeItemId); + int treeItemId, + bool duplicateChildren=true, bool renumber=true); Q_INVOKABLE void cut(int projectId, QListtreeItemIds); Q_INVOKABLE void copy(int projectId, QListtreeItemIds); Q_INVOKABLE SKRResult paste(int targetProjectId, - int parentTreeItemId); + int parentTreeItemId, + bool copyChildren=true); Q_INVOKABLE SKRResult addQuickNote(int projectId, int receiverTreeItemId, diff --git a/src/libskribisto-data/tests/auto/treehubcase/tst_treehubcase.cpp b/src/libskribisto-data/tests/auto/treehubcase/tst_treehubcase.cpp index df75934ad..4b60a0c70 100755 --- a/src/libskribisto-data/tests/auto/treehubcase/tst_treehubcase.cpp +++ b/src/libskribisto-data/tests/auto/treehubcase/tst_treehubcase.cpp @@ -82,6 +82,10 @@ private Q_SLOTS: void multipleCopyPaste(); void simpleCopyPasteInTheSameFolder(); + //duplicate + void duplicate(); + void duplicateWithChildren(); + // move void moveIntoFolder(); private: @@ -728,6 +732,45 @@ void TreeHubCase::simpleCopyPasteInTheSameFolder() { QCOMPARE(indent, 3); } +void TreeHubCase::duplicate() +{ + SKRResult result = skrdata->treeHub()->duplicateTreeItem(m_currentProjectId, 5, false); + QList newIdList = result.getData("treeItemIdList", + QVariant::fromValue >(QList())).value >(); + QCOMPARE(newIdList.isEmpty(), false); + QList ids = skrdata->treeHub()->getAllIds(m_currentProjectId); + + // original: + // 0 << 2 << 4 << 5 << 13 << 14 << 15 << 16 << 6 << 17 << 18 << 19 << 20 << + // 7 << 8 << 9 << 10 << 11 << 12 << 1 << 3 << 21 << 22 << 23 + QList wantedIds; + wantedIds << 0 << 2 << 4 << 5 << 13 << 14 << 15 << 16 << newIdList.first() << 6 << 17 << 18 << 19 << 20 << 7 << 8 << + 9 << 10 << 11 << 12 << 1 << 3 << 21 << 22 << 23; + + QCOMPARE(ids, wantedIds); +} + +void TreeHubCase::duplicateWithChildren() +{ + SKRResult result = skrdata->treeHub()->duplicateTreeItem(m_currentProjectId, 5, true); + QList newIdList = result.getData("treeItemIdList", + QVariant::fromValue >(QList())).value >(); + + QList ids = skrdata->treeHub()->getAllIds(m_currentProjectId); + + // original: + // 0 << 2 << 4 << 5 << 13 << 14 << 15 << 16 << 6 << 17 << 18 << 19 << 20 << + // 7 << 8 << 9 << 10 << 11 << 12 << 1 << 3 << 21 << 22 << 23 + QList wantedIds; + qDebug() << "newIdList" << newIdList; + qDebug() << "ids" << ids; + wantedIds << 0 << 2 << 4 << 5 << 13 << 14 << 15 << 16 << newIdList << 6 << 17 << 18 << 19 << 20 << 7 << 8 << + 9 << 10 << 11 << 12 << 1 << 3 << 21 << 22 << 23; + + QCOMPARE(ids, wantedIds); + +} + void TreeHubCase::multipleCopyPaste() { skrdata->treeHub()->copy(m_currentProjectId, QList() << 14 << 15 << 16); SKRResult result = skrdata->treeHub()->paste(m_currentProjectId, 6); diff --git a/src/plugins/navigationProjectToolbox/NavigationListView.qml b/src/plugins/navigationProjectToolbox/NavigationListView.qml index 69dd50530..a349ca2bb 100644 --- a/src/plugins/navigationProjectToolbox/NavigationListView.qml +++ b/src/plugins/navigationProjectToolbox/NavigationListView.qml @@ -2528,7 +2528,8 @@ Item { var result = skrData.treeHub( ).paste( menu.projectId, - menu.treeItemId) + menu.treeItemId, + true) if (!result.success) { console.debug( diff --git a/src/translations/skribisto_en_US.ts b/src/translations/skribisto_en_US.ts index 2c6cefae6..1804b3e9d 100644 --- a/src/translations/skribisto_en_US.ts +++ b/src/translations/skribisto_en_US.ts @@ -1400,37 +1400,37 @@ - + Add before - + Add after - + Add a sub-item - + Move up - + Move down - + Send to trash - + Close this project From 69a3ff12d828aefbef71775336929036f5e87d36 Mon Sep 17 00:00:00 2001 From: Cyril Jacquet Date: Mon, 11 Apr 2022 01:00:42 +0200 Subject: [PATCH 3/4] update NEWS.yml --- NEWS.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.yml b/NEWS.yml index 960923f25..9a920dd98 100644 --- a/NEWS.yml +++ b/NEWS.yml @@ -1,3 +1,10 @@ +Version: 1.9.40 +Date: 2022-04-11 +Type: stable +Description: +- "Copy paste includes sub-items" +- "Fix crash when drag drop in the empty space below the navigation list" +--- Version: 1.9.39 Date: 2022-04-10 Type: stable From 4f413c79f03a41c1de1e5758306644c0c84e35cb Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 10 Apr 2022 23:01:02 +0000 Subject: [PATCH 4/4] releases in AppData generated --- eu.skribisto.skribisto.appdata.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eu.skribisto.skribisto.appdata.xml b/eu.skribisto.skribisto.appdata.xml index b7722b8ee..f113330a1 100644 --- a/eu.skribisto.skribisto.appdata.xml +++ b/eu.skribisto.skribisto.appdata.xml @@ -28,11 +28,11 @@ - +
    -
  • Fix missing tabulations
  • -
  • Fix First Steps Dialog transparency
  • +
  • Copy paste includes sub-items
  • +
  • Fix crash when drag drop in the empty space below the navigation list