-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add ControlObjects for track table sorting #2118
Add ControlObjects for track table sorting #2118
Conversation
This fixes Launchpad Bug #1828882 ("Add mapping controls for library sort", https://bugs.launchpad.net/mixxx/+bug/1828882).
Splendid! The 202 will benefit from this as well. |
That'd be nice, but since the column numbers are taken from the underlying track model, not derived from the column order in the table widget, the column indices should be static unless the track model source code changes. |
What happens if the columns are rearranged? I suppose then the column index in the control doesn't match the primary sort column and the internal state becomes inconsistent. How do we handle this case? |
@uklotzde Rearraging columns via drag&drop on the column headers does not influence the column indices, since the indices refer to the columns in the underlying track model, NOT the columns in the |
The reduction in both code size and runtime dependencies by your latest commit is nice, even more than what I expected :) |
src/widget/wtracktableview.cpp
Outdated
@@ -127,6 +127,10 @@ WTrackTableView::WTrackTableView(QWidget * parent, | |||
m_pKeyNotation = new ControlProxy("[Library]", "key_notation", this); | |||
m_pKeyNotation->connectValueChanged(this, &WTrackTableView::keyNotationChanged); | |||
|
|||
m_pSortColumn = new ControlProxy("[Library]", "sort_column", this); | |||
m_pSortColumn->connectValueChanged(this, &WTrackTableView::applySorting); |
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.
How will this Control be used? Is there an issue we sort twice when changing the column?
Currently the sort order is saved per column. This is probably broken now.
Can we read back the sort order after changing the sort column and change the "sort_order" CO accordingly?
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.
When changing the sort column by clicking on the column headers, the table should only be sorted once.
When the CO is used in a controller mapping, it depends. Here's an example how I'd use it on the DJ-505:
if (sortColumn === engine.getValue("[Library]", "sort_column")) {
script.toggleControl("[Library]", "sort_order");
} else {
engine.setValue("[Library]", "sort_column", sortColumn);
engine.setValue("[Library]", "sort_order", 0);
}
The code would trigger two sorts if the sort_order
is descending when the sort_column
changes, because the JS code sets sort_order
to 0
if the column changes.
I could avoid this by setting the sort_order
to 0
on sort_column
changes unconditionally in the C++ code. However, there might be legitimate usecases for keeping the order even when the column changes, so I'd rather not do that and keep the current behaviour.
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.
Ah OK, so you have a push button for each column exactly like the table header bar in the GUI.
Right?
Than I think the new controls should behave like this without a need of script magic.
How about this:
- Setting "sort_column" to a new value sorts the new coloumn with the stored value.
- the current sort order is reflected in "sort_order"
- Setting the same value to "sort_column" again toggles the sorting. The same happens if you click again on the header in the GUI.
Your script will then melt down to just:
engine.setValue("[Library]", "sort_column", sortColumn);
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.
Ah OK, so you have a push button for each column exactly like the table header bar in the GUI.
Right?
Correct.
Than I think the new controls should behave like this without a need of script magic.
How about this:
- Setting "sort_column" to a new value sorts the new coloumn with the stored value.
- the current sort order is reflected in "sort_order"
- Setting the same value to "sort_column" again toggles the sorting. The same happens if you click again on the header in the GUI.
If you assign a new value to sort_column
, should sort_order
get reset to 0 or keep its current value?
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.
The idea was to model the exact behavior of the header bar and update the "sort_order" from the c++ domain after changing the "sort_column".
Originally I had the impression that the sort order is saved per column, but I have just tested again and it turns out that this is not true.
I noticed something odd when using diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp
index 4fd1acfc3..188d98efe 100644
--- a/src/widget/wtracktableview.cpp
+++ b/src/widget/wtracktableview.cpp
@@ -128,9 +128,9 @@ WTrackTableView::WTrackTableView(QWidget * parent,
m_pKeyNotation->connectValueChanged(this, &WTrackTableView::keyNotationChanged);
m_pSortColumn = new ControlProxy("[Library]", "sort_column", this);
- m_pSortColumn->connectValueChanged(this, &WTrackTableView::applySorting);
+ m_pSortColumn->connectValueChanged(this, &WTrackTableView::slotSortColumnChanged);
m_pSortOrder = new ControlProxy("[Library]", "sort_order", this);
- m_pSortOrder->connectValueChanged(this, &WTrackTableView::applySorting);
+ m_pSortOrder->connectValueChanged(this, &WTrackTableView::slotSortOrderChanged);
connect(this, SIGNAL(scrollValueChanged(int)),
this, SLOT(slotScrollValueChanged(int)));
@@ -1781,6 +1781,7 @@ void WTrackTableView::doSortByColumn(int headerSection) {
}
void WTrackTableView::applySorting() {
+ qDebug() << "applySorting";
int sortColumn = static_cast<int>(m_pSortColumn->get());
Qt::SortOrder sortOrder = m_pSortOrder->get() ? Qt::DescendingOrder : Qt::AscendingOrder;
@@ -1992,15 +1993,17 @@ void WTrackTableView::slotReloadCoverArt() {
}
void WTrackTableView::slotSortingChanged(int headerSection, Qt::SortOrder order) {
-
+ qDebug() << "slotSortingChanged" << headerSection << order;
double sortOrder = static_cast<double>(order);
bool sortingChanged = false;
if (headerSection != static_cast<int>(m_pSortColumn->get())) {
+ qDebug() << "setSortColumn" << headerSection;
m_pSortColumn->set(headerSection);
sortingChanged = true;
}
if (sortOrder != m_pSortOrder->get()) {
+ qDebug() << "setSortOrder" << order;
m_pSortOrder->set(sortOrder);
sortingChanged = true;
}
@@ -2028,3 +2031,13 @@ void WTrackTableView::keyNotationChanged()
{
QWidget::update();
}
+
+void WTrackTableView::slotSortColumnChanged(double v)
+{
+ qDebug() << "slotSortColumnChanged" << v;
+}
+
+void WTrackTableView::slotSortOrderChanged(double v)
+{
+ qDebug() << "slotSortOrderChanged" << v;
+}
diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h
index 8eaef53c4..ffb993199 100644
--- a/src/widget/wtracktableview.h
+++ b/src/widget/wtracktableview.h
@@ -95,6 +95,8 @@ class WTrackTableView : public WLibraryTableView {
void slotTrackInfoClosed();
void slotTagFetcherClosed();
void slotSortingChanged(int headerSection, Qt::SortOrder order);
+ void slotSortColumnChanged(double v);
+ void slotSortOrderChanged(double v);
void keyNotationChanged();
private:
I don't get why this happens. Any ideas? |
Looks like slots being fired is caused by |
Normally yes. On which OS and IDE are you? |
@daschuer I'm using Linux x86_64 with X11. My IDE is vim. I'll try to debug this tomorrow, when I have some spare time. |
@daschuer Looks like there are multiple instances |
There's another problem with this implementation: Apparently there are different track models for the different Is there a way to have string controls so that we can use column names? Or should I implement an additional abstraction layer that maps column indices to some model-independent numbering scheme? |
This sounds reasonable anyway, even without the issue. It would allow us to change implementation details without breaking mappings. This bit might be interesting: mixxx/src/library/basesqltablemodel.cpp Line 67 in ae392c9
|
8f94fae
to
cfca2a9
Compare
Ok, I added a translation layer to the individual
Feedback is appreciated ;-) |
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.
Looks good, need to test is though.
Do you have worrys about this?
No, but I didn't test all tables (e.g. Recordings), so I'd like someone else to test this. |
We have a weird mixture between snake_case and PascalCase control objects. The [Library] section mainly uses PascalCase. Should we adopt this convention here? |
We also have the mixture inside sections, e.g. When looking at the wiki, it looks like the majority uses |
We should not touch old COs though. There is only a minor benefit compared to the hassle to maintain two versions for backwards compatibility. |
I also agree that |
Done.
True. That why I'd propose a backwards-incompatible change that can be added in case some future major release breaks backwards-compatibility anyway. |
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.
I have did some tests and left some comments.
40725b0
to
ca3e6a8
Compare
can you fix the CodeFactor complains as well? |
I have just tested this branch and it works perfect. |
@daschuer The CodeFactor complaints have been fixed.
I'll use the
The double SQL select occurs only when both I'm not sure how negative values for the descending order would change this behaviour. |
Ok. Thank you for you patience and making this really good. |
This is supposed to resolve Launchpad Bug #1828882 ("Add mapping controls for library
sort").
It adds two controls to the
[Library]
group:sort_column
sort_order
I do not have any experience with the Mixxx codebase or Qt, so I'm relatively sure that my code absolutely abysmal. Feedback would be appreciated.