-
Notifications
You must be signed in to change notification settings - Fork 37.7k
gui: Drop WalletModel dependency to RecentRequestsTableModel #18064
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
Conversation
Concept ACK. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete on setModel(nullptr)
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
677a80d
to
b211a50
Compare
Rebased. |
b211a50
to
e0cf0e2
Compare
There was a problem hiding this 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.
e0cf0e2
to
bbb33d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -44,6 +45,8 @@ class ReceiveCoinsDialog : public QDialog | |||
|
|||
void setModel(WalletModel *model); | |||
|
|||
RecentRequestsTableModel* recentRequestsTableModel() const { return m_recent_requests_table_model; } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Tested ACK bbb33d6 |
|
@laanwj not sure if you saw my reply above. |
I still dislike |
@laanwj I'll try to push the whole change where |
Closing in favor of #18618. |
This PR moves the
RecentRequestsTableModel
instancing to where it's needed which in turn breaks the circular dependency betweenWalletModel
andRecentRequestsTableModel
.