Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquetc committed Apr 10, 2022
2 parents 3257368 + 4f413c7 commit 07d6b7d
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 57 deletions.
7 changes: 7 additions & 0 deletions NEWS.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions eu.skribisto.skribisto.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
</screenshot>
</screenshots>
<releases>
<release type="stable" version="1.9.39" date="2022-04-10T00:00:00Z">
<release type="stable" version="1.9.40" date="2022-04-11T00:00:00Z">
<description>
<ul>
<li>Fix missing tabulations</li>
<li>Fix First Steps Dialog transparency</li>
<li>Copy paste includes sub-items</li>
<li>Fix crash when drag drop in the empty space below the navigation list</li>
</ul>
</description>
</release>
Expand Down
87 changes: 65 additions & 22 deletions src/libskribisto-data/src/skrtreehub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QCollator>

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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -629,15 +630,17 @@ int SKRTreeHub::getLastAddedId()

// ----------------------------------------------------------------------------------------

SKRResult SKRTreeHub::addTreeItem(const QHash<QString, QVariant>& values, int projectId)
SKRResult SKRTreeHub::addTreeItem(const QHash<QString, QVariant>& values, int projectId, bool renumber)
{
PLMSqlQueries queries(projectId, m_tableName);

queries.beginTransaction();
int newId = -1;
SKRResult result = queries.add(values, newId);

IFOKDO(result, queries.renumberSortOrder());
if(renumber){
IFOKDO(result, queries.renumberSortOrder());
}
IFKO(result) {
queries.rollback();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -1487,7 +1490,7 @@ QList<int>SKRTreeHub::getAllSiblings(int projectId, int treeItemId, bool treeIte

// alone, so no siblings
if ((minSiblingIndex == treeItemSortedIdIndex) &&
(maxSiblingIndex == treeItemSortedIdIndex)) {
(maxSiblingIndex == treeItemSortedIdIndex)) {
return siblingsList;
}

Expand Down Expand Up @@ -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<int> resultTreeItemIdList;

// TODO: create duplicate
int newItemId = -2;
QHash<QString, QVariant> values;

int validSortOrder = getValidSortOrderAfterTree(projectId, treeItemId);

if(duplicateChildren && getAllChildren(projectId, treeItemId).count() > 0){
validSortOrder -= getAllChildren(projectId, treeItemId).count();
}

QHash<QString, QVariant> 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<int> childrenList = getAllChildren(projectId, treeItemId);
QList<int> childrenNotTrashed;
for(int childId: childrenList){
if(!getTrashed(projectId, childId)){
childrenNotTrashed.append(childId);
}
}
childrenList = childrenNotTrashed;

int sortOrderOffset = 1;
for(int childId: childrenList){

QHash<QString, QVariant> 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<QList<int> >(resultTreeItemIdList));
}
IFKO(result) {
emit errorSent(result);
Expand Down Expand Up @@ -1810,7 +1852,7 @@ void SKRTreeHub::copy(int projectId, QList<int>treeItemIds)

// ----------------------------------------------------------------------------------------

SKRResult SKRTreeHub::paste(int targetProjectId, int parentTreeItemId)
SKRResult SKRTreeHub::paste(int targetProjectId, int parentTreeItemId, bool copyChildren)
{
SKRResult result(this);
QList<int> treeItemIdList;
Expand Down Expand Up @@ -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<int> newTreeItemIdList = result.getData("treeItemIdList",
QVariant::fromValue<QList<int> >(QList<int>())).value<QList<int> >();
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
Expand Down
8 changes: 5 additions & 3 deletions src/libskribisto-data/src/skrtreehub.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class EXPORT SKRTreeHub : public QObject {
Q_INVOKABLE int getLastAddedId();

SKRResult addTreeItem(const QHash<QString, QVariant>& values,
int projectId);
int projectId, bool renumber= true);
Q_INVOKABLE SKRResult addTreeItemAbove(int projectId,
int targetId,
const QString& type);
Expand Down Expand Up @@ -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,
QList<int>treeItemIds);
Q_INVOKABLE void copy(int projectId,
QList<int>treeItemIds);
Q_INVOKABLE SKRResult paste(int targetProjectId,
int parentTreeItemId);
int parentTreeItemId,
bool copyChildren=true);

Q_INVOKABLE SKRResult addQuickNote(int projectId,
int receiverTreeItemId,
Expand Down
43 changes: 43 additions & 0 deletions src/libskribisto-data/tests/auto/treehubcase/tst_treehubcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ private Q_SLOTS:
void multipleCopyPaste();
void simpleCopyPasteInTheSameFolder();

//duplicate
void duplicate();
void duplicateWithChildren();

// move
void moveIntoFolder();
private:
Expand Down Expand Up @@ -728,6 +732,45 @@ void TreeHubCase::simpleCopyPasteInTheSameFolder() {
QCOMPARE(indent, 3);
}

void TreeHubCase::duplicate()
{
SKRResult result = skrdata->treeHub()->duplicateTreeItem(m_currentProjectId, 5, false);
QList<int> newIdList = result.getData("treeItemIdList",
QVariant::fromValue<QList<int> >(QList<int>())).value<QList<int> >();
QCOMPARE(newIdList.isEmpty(), false);
QList<int> 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<int> 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<int> newIdList = result.getData("treeItemIdList",
QVariant::fromValue<QList<int> >(QList<int>())).value<QList<int> >();

QList<int> 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<int> 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<int>() << 14 << 15 << 16);
SKRResult result = skrdata->treeHub()->paste(m_currentProjectId, 6);
Expand Down
20 changes: 17 additions & 3 deletions src/plugins/navigationProjectToolbox/NavigationListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}



Expand Down Expand Up @@ -2515,7 +2528,8 @@ Item {
var result = skrData.treeHub(
).paste(
menu.projectId,
menu.treeItemId)
menu.treeItemId,
true)

if (!result.success) {
console.debug(
Expand Down
Loading

0 comments on commit 07d6b7d

Please sign in to comment.