Skip to content

Commit

Permalink
LibraryFeature: Add LibraryFeature::selectAndActivate()
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed May 3, 2024
1 parent b9002e6 commit 55d557f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,7 @@ void Library::slotSwitchToFeature(const QString& featureName) {
}
for (auto feature : m_features) {

Check warning on line 540 in src/library/library.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto feature' can be declared as 'auto *feature' [readability-qualified-auto]
if (feature->featureName() == featureName) {
// 'Select' the feature (i.e. update the sidebar selection).
// Selecting an index does not yet activate it (see below).
emit feature->featureSelect(feature, QModelIndex());

// 'Activate' the feature, i.e. update the library view
feature->activate();
feature->selectAndActivate();
return;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/library/libraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ LibraryFeature::LibraryFeature(
}
}

void LibraryFeature::selectAndActivate(const QModelIndex& index) {
if (index.isValid()) {
emit featureSelect(this, index);
activateChild(index);
} else {
// calling featureSelect with invalid index will select the root item
emit featureSelect(this, QModelIndex());
activate();
}
}

QStringList LibraryFeature::getPlaylistFiles(QFileDialog::FileMode mode) const {
QString lastPlaylistDirectory = m_pConfig->getValue(
ConfigKey("[Library]", "LastImportExportPlaylistDirectory"),
Expand Down
4 changes: 4 additions & 0 deletions src/library/libraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class LibraryFeature : public QObject {
const UserSettingsPointer m_pConfig;

public slots:
/// Pretend that the user has clicked on a tree item belonging
/// to this LibraryFeature by updating both the library view
/// and the sidebar selection.
void selectAndActivate(const QModelIndex& index = QModelIndex());
// called when you single click on the root item
virtual void activate() = 0;
// called when you single click on a child item, e.g., a concrete playlist or crate
Expand Down
3 changes: 1 addition & 2 deletions src/library/trackset/playlistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ void PlaylistFeature::slotPlaylistTableChanged(int playlistId) {
// Else (root item was selected or for some reason no index could be created)
// there's nothing to do: either no child was selected earlier, or the root
// was selected and will remain selected after the child model was rebuilt.
activateChild(newIndex);
emit featureSelect(this, newIndex);
selectAndActivate(newIndex);
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/library/trackset/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,8 @@ void SetlogFeature::slotPlaylistTableChanged(int playlistId) {
newIndex = m_pSidebarModel->index(selectedYearIndexRow - 1, 0);
}
}
if (newIndex.isValid()) {
emit featureSelect(this, newIndex);
activateChild(newIndex);
} else if (rootWasSelected) {
// calling featureSelect with invalid index will select the root item
emit featureSelect(this, newIndex);
activate(); // to reload the new current playlist
if (newIndex.isValid() || rootWasSelected) {
selectAndActivate(newIndex);
}
}

Expand Down

0 comments on commit 55d557f

Please sign in to comment.