Skip to content

Conversation

promag
Copy link
Contributor

@promag promag commented Feb 3, 2020

This PR moves the RecentRequestsTableModel instancing to where it's needed which in turn breaks the circular dependency between WalletModel and RecentRequestsTableModel.

@fanquake fanquake added the GUI label Feb 3, 2020
@hebasto
Copy link
Member

hebasto commented Feb 3, 2020

Concept ACK.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 3, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@@ -70,15 +70,17 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)

if(_model && _model->getOptionsModel())
{
_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
assert(m_recent_requests_table_model == nullptr);
m_recent_requests_table_model = new RecentRequestsTableModel(_model);
Copy link
Contributor

Choose a reason for hiding this comment

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

No delete necessary in this case? I tend to prefer it occur even if not strictly necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete on setModel(nullptr)?

Copy link
Member

Choose a reason for hiding this comment

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

No delete necessary in this case?

m_recent_requests_table_model is a QObject with a parent. This ensures that it will be deleted during its parent deletion, no?

Copy link
Contributor Author

@promag promag Feb 4, 2020

Choose a reason for hiding this comment

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

Yes. Only thing "wrong" is that when WalletModel is destroyed we will have a dangling
m_recent_requests_table_model. But AFAICT this shouldn't be a concern because that happens when the wallet is being unloaded and everything is being destroyed.

Anyway, I'm thinking we could move away from these setModel(WalletModel*) and pass it on the constructor, but it's going to take a while to get there.

Copy link
Member

Choose a reason for hiding this comment

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

Only thing "wrong" is that when WalletModel is destroyed we will have a dangling
m_recent_requests_table_model.

Sounds not good...

But AFAICT this shouldn't be a concern because that happens when the wallet is being unloaded and everything is being destroyed.

Agree.

Anyway, I'm thinking we could move away from these setModel(WalletModel*) and pass it on the constructor, but it's going to take a while to get there.

Maybe discuss this on IRC meeting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe discuss this on IRC meeting?

Not sure worth it, a draft PR with the whole change might be better.

Copy link
Member

@laanwj laanwj Feb 10, 2020

Choose a reason for hiding this comment

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

This will create a new RecentRequestsTableModel every time setModel is called. I do not think this is expected behavior. setModel should set a model not create one.

Maybe pass it in from the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called once, see the assertion above.

There is no use case for switching models, that's why I think we can slowly refactor to get the dependencies on the constructor rather than having these setters, which add unnecessary state management.

@promag promag force-pushed the 2020-02-recentrequeststablemodel branch from 677a80d to b211a50 Compare February 4, 2020 07:59
@promag
Copy link
Contributor Author

promag commented Feb 4, 2020

Rebased.

@promag promag force-pushed the 2020-02-recentrequeststablemodel branch from b211a50 to e0cf0e2 Compare February 4, 2020 09:54
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK e0cf0e2, tested on Linux Mint 19.3.
No user-faced changes in behavior are observed. Local tests, including test_bitcoin-qt, have passed.

@promag promag force-pushed the 2020-02-recentrequeststablemodel branch from e0cf0e2 to bbb33d6 Compare February 4, 2020 13:54
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

re-ACK bbb33d6, the only change since e0cf0e2 is explicit type instead of auto.

@@ -44,6 +45,8 @@ class ReceiveCoinsDialog : public QDialog

void setModel(WalletModel *model);

RecentRequestsTableModel* recentRequestsTableModel() const { return m_recent_requests_table_model; }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: seems like returning a const pointer would be more correct, given that this is a const method

Perhaps negligible as this is only used in the test, it has no other impact:

diff --git a/src/qt/receivecoinsdialog.h b/src/qt/receivecoinsdialog.h
index e400129f7..5dc340aed 100644
--- a/src/qt/receivecoinsdialog.h
+++ b/src/qt/receivecoinsdialog.h
@@ -45,7 +45,7 @@ public:
 
     void setModel(WalletModel *model);
 
-    RecentRequestsTableModel* recentRequestsTableModel() const { return m_recent_requests_table_model; }
+    const RecentRequestsTableModel* recentRequestsTableModel() const { return m_recent_requests_table_model; }
 
 public Q_SLOTS:
     void clear();
diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp
index c15b1c0d6..276df75f4 100644
--- a/src/qt/test/wallettests.cpp
+++ b/src/qt/test/wallettests.cpp
@@ -212,7 +212,7 @@ void TestGUI(interfaces::Node& node)
     // Check Request Payment button
     ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());
     receiveCoinsDialog.setModel(&walletModel);
-    RecentRequestsTableModel* requestTableModel = receiveCoinsDialog.recentRequestsTableModel();
+    const RecentRequestsTableModel* requestTableModel = receiveCoinsDialog.recentRequestsTableModel();
     assert(requestTableModel);
 
     // Label input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: seems like returning a const pointer would be more correct, given that this is a const method

More correct why? Those are orthogonal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, not in every case, but in many cases it would be incongruent if an instance was const and its member was not - for example, if I have a const counter object, but I exposed the current count in an externally modifiable way, then that would be incongruent IMO.

In this case, it's not necessary to expose members in a non-const way from a const method, so I would bias toward the more restrictive presentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative is a method that returns a bool rather than the member itself, since that is all that is needed to satisfy the test.

@jonasschnelli
Copy link
Contributor

Tested ACK bbb33d6

@laanwj
Copy link
Member

laanwj commented Feb 10, 2020

code-review ACK bbb33d6
(see comment)
#18064 (comment)

@promag
Copy link
Contributor Author

promag commented Feb 16, 2020

@laanwj not sure if you saw my reply above.

@laanwj
Copy link
Member

laanwj commented Feb 25, 2020

I still dislike setModel actually creating the model, or conceptually, a dialog creating its own model (for that matter). But if everyone else is ok with it's fine…

@promag
Copy link
Contributor Author

promag commented Feb 26, 2020

@laanwj I'll try to push the whole change where setModel is removed.

@promag
Copy link
Contributor Author

promag commented Apr 13, 2020

Closing in favor of #18618.

@promag promag closed this Apr 13, 2020
@promag promag deleted the 2020-02-recentrequeststablemodel branch April 13, 2020 09:32
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants