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

Add ControlObjects for track table sorting #2118

Merged
merged 16 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ LibraryControl::LibraryControl(Library* pLibrary)
connect(m_pAutoDjAddBottom.get(), SIGNAL(valueChanged(double)),
this, SLOT(slotAutoDjAddBottom(double)));

// Sort controls
m_pSortColumn = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "sort_column"));
m_pSortColumn->setButtonMode(ControlPushButton::TOGGLE);
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
m_pSortOrder = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "sort_order"));
m_pSortOrder->setButtonMode(ControlPushButton::TOGGLE);

// Font sizes
m_pFontSizeKnob = std::make_unique<ControlObject>(
ConfigKey("[Library]", "font_size_knob"), false);
Expand Down
4 changes: 4 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class LibraryControl : public QObject {
std::unique_ptr<ControlObject> m_pAutoDjAddTop;
std::unique_ptr<ControlObject> m_pAutoDjAddBottom;

// Controls to sort the track view
std::unique_ptr<ControlPushButton> m_pSortColumn;
std::unique_ptr<ControlPushButton> m_pSortOrder;

// Font sizes
std::unique_ptr<ControlPushButton> m_pFontSizeIncrement;
std::unique_ptr<ControlPushButton> m_pFontSizeDecrement;
Expand Down
58 changes: 47 additions & 11 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::sortColumnChanged);
m_pSortOrder = new ControlProxy("[Library]", "sort_order", this);
m_pSortOrder->connectValueChanged(this, &WTrackTableView::sortOrderChanged);

connect(this, SIGNAL(scrollValueChanged(int)),
this, SLOT(slotScrollValueChanged(int)));
Expand Down Expand Up @@ -361,31 +365,36 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) {
if (m_sorting) {
// NOTE: Should be a UniqueConnection but that requires Qt 4.6
connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
this, SLOT(doSortByColumn(int)), Qt::AutoConnection);
this, SLOT(slotSortingChanged(int, Qt::SortOrder)), Qt::AutoConnection);

int sortColumn;
Qt::SortOrder sortOrder;

// Stupid hack that assumes column 0 is never visible, but this is a weak
// proxy for "there was a saved column sort order"
if (horizontalHeader()->sortIndicatorSection() > 0) {
// Sort by the saved sort section and order.
horizontalHeader()->setSortIndicator(horizontalHeader()->sortIndicatorSection(),
horizontalHeader()->sortIndicatorOrder());
// in Qt5, we need to call it manually, which triggers finally the select()
doSortByColumn(horizontalHeader()->sortIndicatorSection());
sortColumn = horizontalHeader()->sortIndicatorSection();
sortOrder = horizontalHeader()->sortIndicatorOrder();
} else {
// No saved order is present. Use the TrackModel's default sort order.
int sortColumn = trackModel->defaultSortColumn();
Qt::SortOrder sortOrder = trackModel->defaultSortOrder();
sortColumn = trackModel->defaultSortColumn();
sortOrder = trackModel->defaultSortOrder();

// If the TrackModel has an invalid or internal column as its default
// sort, find the first non-internal column and sort by that.
while (sortColumn < 0 || trackModel->isColumnInternal(sortColumn)) {
sortColumn++;
}
// This line sorts the TrackModel
horizontalHeader()->setSortIndicator(sortColumn, sortOrder);
// in Qt5, we need to call it manually, which triggers finally the select()
doSortByColumn(sortColumn);
}

// This line sorts the TrackModel
horizontalHeader()->setSortIndicator(sortColumn, sortOrder);
// in Qt5, we need to call it manually, which triggers finally the select()
doSortByColumn(sortColumn);

m_pSortColumn->set(sortColumn);
m_pSortOrder->set(sortOrder);
}

// Set up drag and drop behavior according to whether or not the track
Expand Down Expand Up @@ -1975,6 +1984,18 @@ void WTrackTableView::slotReloadCoverArt() {
}
}

void WTrackTableView::slotSortingChanged(int headerSection, Qt::SortOrder order) {
double sortOrder = (order == Qt::AscendingOrder) ? 0.0 : 1.0;
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
if (headerSection != (int)m_pSortColumn->get()) {
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
m_pSortColumn->set(headerSection);
sortColumnChanged(headerSection);
}
if (sortOrder != m_pSortOrder->get()) {
m_pSortOrder->set(sortOrder);
sortOrderChanged(sortOrder);
}
}

bool WTrackTableView::hasFocus() const {
return QWidget::hasFocus();
}
Expand All @@ -1994,3 +2015,18 @@ void WTrackTableView::keyNotationChanged()
QWidget::update();
}

void WTrackTableView::sortColumnChanged(double v)
{
int sortColumn = (int)v;
Qt::SortOrder sortOrder = m_pSortColumn->get() ? Qt::DescendingOrder : Qt::AscendingOrder;
horizontalHeader()->setSortIndicator(sortColumn, sortOrder);
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
doSortByColumn(sortColumn);
}

void WTrackTableView::sortOrderChanged(double v)
{
int sortColumn = (int)m_pSortColumn->get();
Qt::SortOrder sortOrder = v ? Qt::DescendingOrder : Qt::AscendingOrder;
horizontalHeader()->setSortIndicator(sortColumn, sortOrder);
doSortByColumn(sortColumn);
}
5 changes: 5 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ class WTrackTableView : public WLibraryTableView {

void slotTrackInfoClosed();
void slotTagFetcherClosed();
void slotSortingChanged(int headerSection, Qt::SortOrder order);
void keyNotationChanged();
void sortColumnChanged(double v);
void sortOrderChanged(double v);

private:

Expand Down Expand Up @@ -217,6 +220,8 @@ class WTrackTableView : public WLibraryTableView {
bool m_bCrateMenuLoaded;
ControlProxy* m_pCOTGuiTick;
ControlProxy* m_pKeyNotation;
ControlProxy* m_pSortColumn;
ControlProxy* m_pSortOrder;
};

#endif