Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix toggle lock button #2860

Merged
merged 1 commit into from
May 16, 2023
Merged

Conversation

panleone
Copy link

@panleone panleone commented May 7, 2023

This PR solves issue #2159

The Lock functionality has been extended to tree mode view

(See the picture)
2023-05-07-201812_1366x768_scrot

@panleone panleone self-assigned this May 7, 2023
@panleone panleone added this to the 6.0.0 milestone May 7, 2023
Liquid369
Liquid369 previously approved these changes May 9, 2023
Copy link
Member

@Liquid369 Liquid369 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 6840431
Nice fix good idea to solve some stuff listed in issues

@Fuzzbawls
Copy link
Collaborator

Wasn't quite happy with the idea of forcibly flipping UTXO lock states when switching from list view to tree view after the Toggle lock state button was used (this is functionality I use quite often with large wallets to quickly lock everything up and then unlock a select few UTXOs from a specific address), so went on a bit of a dive to see if there was a way to instead just make the Toggle lock state button work in tree view.

Here is a patch based on top of this PR's commit to do just that! Could possibly be further optimized, but feel free to use it/test it/change it as you see fit.

Video: https://github.com/PIVX-Project/PIVX/assets/7393257/10530ba9-4e01-4dc4-bd72-7b9fe63a6d1e

Patch:

Index: src/qt/coincontroldialog.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp
--- a/src/qt/coincontroldialog.cpp	(revision 6840431f9aa3e099b17bbbadd540252507b1daf6)
+++ b/src/qt/coincontroldialog.cpp	(date 1683715642755)
@@ -228,27 +228,39 @@
     updateLabels();
 }
 
-void CoinControlDialog::toggleCoinLock()
+void CoinControlDialog::toggleItemLock(QTreeWidgetItem* item)
 {
-    QTreeWidgetItem* item;
-    for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
-        item = ui->treeWidget->topLevelItem(i);
-
-        COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
-        if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) {
-            model->unlockCoin(outpt);
-            item->setDisabled(false);
-            // restore cold-stake snowflake icon for P2CS which were previously locked
-            if (item->data(COLUMN_CHECKBOX, Qt::UserRole) == QString("Delegated"))
-                item->setIcon(COLUMN_CHECKBOX, QIcon("://ic-check-cold-staking-off"));
-            else
-                item->setIcon(COLUMN_CHECKBOX, QIcon());
-        } else {
-            model->lockCoin(outpt);
-            item->setDisabled(true);
-            item->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed"));
-        }
-        updateLabelLocked();
+    COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
+    if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) {
+        model->unlockCoin(outpt);
+        item->setDisabled(false);
+        // restore cold-stake snowflake icon for P2CS which were previously locked
+        if (item->data(COLUMN_CHECKBOX, Qt::UserRole) == QString("Delegated"))
+            item->setIcon(COLUMN_CHECKBOX, QIcon("://ic-check-cold-staking-off"));
+        else
+            item->setIcon(COLUMN_CHECKBOX, QIcon());
+    } else {
+        model->lockCoin(outpt);
+        item->setDisabled(true);
+        item->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed"));
+    }
+    updateLabelLocked();
+}
+
+void CoinControlDialog::toggleCoinLock()
+{
+    QTreeWidgetItem* item;
+    bool treemode = ui->treeWidget->rootIsDecorated();
+    for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
+        item = ui->treeWidget->topLevelItem(i);
+        if (treemode) {
+            auto subItems = item->takeChildren();
+            for (auto j : subItems) {
+                toggleItemLock(j);
+            }
+        } else {
+            toggleItemLock(item);
+        }
     }
 }
 
@@ -261,19 +273,10 @@
     }
 
     // Works in list-mode only
-    if (ui->radioListMode->isChecked()) {
-        ui->treeWidget->setEnabled(false);
-        toggleCoinLock();
-        ui->treeWidget->setEnabled(true);
-        updateLabels();
-    } else {
-        ui->pushButtonToggleLock->setChecked(false);
-        QMessageBox msgBox;
-        msgBox.setObjectName("lockMessageBox");
-        msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
-        msgBox.setText(tr("Please switch to \"List mode\" to use this function."));
-        msgBox.exec();
-    }
+    ui->treeWidget->setEnabled(false);
+    toggleCoinLock();
+    ui->treeWidget->setEnabled(true);
+    updateView();
 }
 
 // context menu
@@ -441,13 +444,8 @@
 // toggle tree mode
 void CoinControlDialog::radioTreeMode(bool checked)
 {
-    if (checked && model) {
-        if (ui->pushButtonToggleLock->isChecked() && fSelectTransparent) {
-            ui->pushButtonToggleLock->setChecked(false);
-            toggleCoinLock();
-        }
+    if (checked && model)
         updateView();
-    }
 }
 
 // toggle list mode
Index: src/qt/coincontroldialog.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h
--- a/src/qt/coincontroldialog.h	(revision 6840431f9aa3e099b17bbbadd540252507b1daf6)
+++ b/src/qt/coincontroldialog.h	(date 1683714494344)
@@ -93,6 +93,7 @@
     void updatePushButtonSelectAll(bool checked);
     void sortView(int, Qt::SortOrder);
     void inform(const QString& text);
+    void toggleItemLock(QTreeWidgetItem* item);
     void toggleCoinLock();
 
     // Load a row with coin's data

@panleone
Copy link
Author

patch applied and rebased! Having the functionality available also on tree mode is surely a better solution

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f0f58b9

there is a leftover stale comment about only working in list mode (my fault, didn't remove it from my diff patch), but that is of little concern right now. would rather merge as-is and eventually do a cleanup later.

Copy link
Member

@Liquid369 Liquid369 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f0f58b9

@Fuzzbawls Fuzzbawls merged commit 62d7459 into PIVX-Project:master May 16, 2023
@Fuzzbawls Fuzzbawls modified the milestones: 6.0.0, 5.6.0 Feb 6, 2024
@Fuzzbawls Fuzzbawls added Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes and removed Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes labels Feb 15, 2024
@panleone panleone deleted the toggle_lock_fix branch March 23, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants