]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
AccountSwitcherDialog: don't select #0 account on opening
authortobtoht <tob@featherwallet.org>
Wed, 18 Dec 2024 17:35:19 +0000 (18:35 +0100)
committertobtoht <tob@featherwallet.org>
Wed, 18 Dec 2024 17:35:19 +0000 (18:35 +0100)
src/dialog/AccountSwitcherDialog.cpp
src/dialog/AccountSwitcherDialog.h

index c907c21d10524a2eb6f0c91124501529df3857fc..09889f7d2098e25a53f3aa70b57c42f76556fe73 100644 (file)
@@ -39,7 +39,7 @@ AccountSwitcherDialog::AccountSwitcherDialog(Wallet *wallet, QWidget *parent)
     ui->accounts->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
     ui->accounts->header()->setSectionResizeMode(SubaddressAccountModel::Label, QHeaderView::Stretch);
 
-    connect(ui->accounts->selectionModel(), &QItemSelectionModel::currentChanged, this, &AccountSwitcherDialog::switchAccount);
+    connect(ui->accounts, &QTreeView::clicked, this, &AccountSwitcherDialog::switchAccount);
     connect(ui->accounts, &QTreeView::customContextMenuRequested, this, &AccountSwitcherDialog::showContextMenu);
 
     connect(ui->btn_newAccount, &QPushButton::clicked, [this]{
@@ -47,11 +47,14 @@ AccountSwitcherDialog::AccountSwitcherDialog(Wallet *wallet, QWidget *parent)
        m_wallet->subaddressAccount()->refresh();
     });
 
-    connect(m_wallet, &Wallet::currentSubaddressAccountChanged, this, &AccountSwitcherDialog::updateSelection);
     connect(m_wallet->subaddressAccount(), &SubaddressAccount::refreshFinished, this, &AccountSwitcherDialog::updateSelection);
+}
+
+void AccountSwitcherDialog::showEvent(QShowEvent *event) {
+    QDialog::showEvent(event);
 
     this->update();
-    this->updateSelection();
+    m_wallet->switchSubaddressAccount(m_wallet->currentSubaddressAccount());
 }
 
 void AccountSwitcherDialog::update() {
@@ -59,13 +62,8 @@ void AccountSwitcherDialog::update() {
     m_wallet->subaddressAccount()->refresh();
 }
 
-void AccountSwitcherDialog::switchAccount() {
-    auto row = this->currentEntry();
-    if (!row) {
-        return;
-    }
-
-    m_wallet->switchSubaddressAccount(row->getRow());
+void AccountSwitcherDialog::switchAccount(const QModelIndex &index) {
+    m_wallet->switchSubaddressAccount(m_proxyModel->mapToSource(index).row());
 }
 
 void AccountSwitcherDialog::copyLabel() {
@@ -93,11 +91,13 @@ void AccountSwitcherDialog::editLabel() {
 }
 
 void AccountSwitcherDialog::updateSelection() {
-    QModelIndex index = m_model->index(m_wallet->currentSubaddressAccount(), 0);
+    QModelIndex index = m_proxyModel->index(m_wallet->currentSubaddressAccount(), 0);
     if (!index.isValid()) {
         return;
     }
-    ui->accounts->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+
+    ui->accounts->setCurrentIndex(index);
+    ui->accounts->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
 }
 
 void AccountSwitcherDialog::showContextMenu(const QPoint &point) {
index eef7b1a64c2d6e3cc73a6a95f774467d8952d0a1..d25b004ed29b956704923dbad4356a8148583cc7 100644 (file)
@@ -22,12 +22,15 @@ public:
 
     void update();
 
+protected:
+    void showEvent(QShowEvent *event) override;
+
 private slots:
     void showContextMenu(const QPoint& point);
     void updateSelection();
 
 private:
-    void switchAccount();
+    void switchAccount(const QModelIndex &index);
     void copyLabel();
     void copyBalance();
     void editLabel();