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

Fix empty library table after start #3935

Merged
merged 6 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 1 addition & 4 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ void BaseTrackTableModel::setHeaderProperties(
int defaultWidth) {
int section = fieldIndex(column);
if (section < 0) {
kLogger.debug()
<< "Skipping header properties for unsupported column"
<< column
<< title;
// Skipping header properties for unsupported column
return;
}
if (section >= m_columnHeaders.size()) {
Expand Down
44 changes: 21 additions & 23 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,21 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) {
return;
}

TrackModel* newModel = nullptr;

/* If the model has not changed
* there's no need to exchange the headers
* this will cause a small GUI freeze
*/
// If the model has not changed
// there's no need to exchange the headers
// this will cause a small GUI freeze
if (getTrackModel() == trackModel) {
// Re-sort the table even if the track model is the same. This triggers
// a select() if the table is dirty.
doSortByColumn(horizontalHeader()->sortIndicatorSection(),
horizontalHeader()->sortIndicatorOrder());
return;
} else {
newModel = trackModel;
saveVScrollBarPos(getTrackModel());
//saving current vertical bar position
//using address of track model as key
}

// saving current vertical bar position
// using address of track model as key
saveVScrollBarPos(getTrackModel());

setVisible(false);

// Save the previous track model's header state
Expand Down Expand Up @@ -262,28 +258,30 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) {
&WTrackTableView::slotSortingChanged,
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) {
TrackModel::SortColumnId sortColumn =
trackModel->sortColumnIdFromColumnIndex(
horizontalHeader()->sortIndicatorSection());
if (sortColumn != TrackModel::SortColumnId::Invalid) {
// Sort by the saved sort section and order.
sortColumn = horizontalHeader()->sortIndicatorSection();
sortOrder = horizontalHeader()->sortIndicatorOrder();
} else {
// No saved order is present. Use the TrackModel's default sort order.
sortColumn = trackModel->defaultSortColumn();
sortColumn = trackModel->sortColumnIdFromColumnIndex(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++;
// sort, find the first valid sort column and sort by that.
int sortColumnIndex = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

The idiomatic implementation would be a simple for loop with a break statement.

const int columnCount = model->columnCount(); // just to avoid an endless while loop
while (sortColumn == TrackModel::SortColumnId::Invalid &&
sortColumnIndex < columnCount) {
sortColumnIndex++;
sortColumn = trackModel->sortColumnIdFromColumnIndex(sortColumnIndex);
}
}

m_pSortColumn->set(static_cast<int>(trackModel->sortColumnIdFromColumnIndex(sortColumn)));
m_pSortColumn->set(static_cast<double>(sortColumn));
m_pSortOrder->set(sortOrder);
applySorting();
}
Expand Down Expand Up @@ -313,7 +311,7 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) {

setVisible(true);

restoreVScrollBarPos(newModel);
restoreVScrollBarPos(trackModel);
// restoring scrollBar position using model pointer as key
// scrollbar positions with respect to different models are backed by map
initTrackMenu();
Expand Down