-
Notifications
You must be signed in to change notification settings - Fork 42
Fuzzy text search, part 2: Add fuzzy search to learn page #197
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
Open
juli27
wants to merge
1
commit into
musescore:main
Choose a base branch
from
juli27:addFuzzySearchLearnPage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
framework/learn/qml/Muse/Learn/internal/playlistmodel.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-only | ||
| * MuseScore-CLA-applies | ||
| * | ||
| * MuseScore Studio | ||
| * Music Composition & Notation | ||
| * | ||
| * Copyright (C) 2026 MuseScore Limited and others | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "playlistmodel.h" | ||
|
|
||
| #include <QString> | ||
| #include <QStringList> | ||
|
|
||
| #include "global/log.h" | ||
|
|
||
| namespace muse::learn { | ||
| PlaylistModel::PlaylistModel(QObject* parent) | ||
| : QAbstractListModel(parent) | ||
| { | ||
| } | ||
|
|
||
| const Playlist& PlaylistModel::playlist() | ||
| { | ||
| return m_playlist; | ||
| } | ||
|
|
||
| void PlaylistModel::setPlaylist(const Playlist& playlist) | ||
| { | ||
| beginResetModel(); | ||
| m_playlist = playlist; | ||
| endResetModel(); | ||
| } | ||
|
|
||
| int PlaylistModel::rowCount(const QModelIndex& parent) const | ||
| { | ||
| if (parent.isValid()) { | ||
| return 0; | ||
| } | ||
|
|
||
| return m_playlist.size(); | ||
| } | ||
|
|
||
| QVariant PlaylistModel::data(const QModelIndex& index, int roleId) const | ||
| { | ||
| IF_ASSERT_FAILED(index.isValid() && index.row() < m_playlist.size()) { | ||
| return QVariant(); | ||
| } | ||
|
|
||
| const PlaylistItem& item = m_playlist[index.row()]; | ||
|
|
||
| switch (roleId) { | ||
| case RoleTitle: | ||
| return item.title; | ||
| case RoleAuthor: | ||
| return item.author; | ||
| case RoleDuration: { | ||
| // h:mm:ss for anything over an hour | ||
| // m:ss for anything under an hour | ||
| // 0:ss for anything under a minute | ||
| int seconds = item.durationSecs; | ||
| int minutes = seconds / 60; | ||
| seconds -= minutes * 60; | ||
| int hours = minutes / 60; | ||
| minutes -= hours * 60; | ||
|
|
||
| return ((hours > 0) | ||
| ? (QString::number(hours) + ":" + QString::number(minutes).rightJustified(2, '0')) | ||
| : QString::number(minutes) | ||
| ) + ":" | ||
| + QString::number(seconds).rightJustified(2, '0'); | ||
| } | ||
| case RoleUrl: | ||
| return item.url; | ||
| case RoleThumbnailUrl: | ||
| return item.thumbnailUrl; | ||
| case RoleSearchKey: { | ||
| QStringList searchKeyItems; | ||
| searchKeyItems << item.title | ||
| << item.author; | ||
|
|
||
| return searchKeyItems.join(u' '); | ||
| } | ||
|
|
||
| default: | ||
| UNREACHABLE; | ||
| break; | ||
| } | ||
|
|
||
| return QVariant(); | ||
| } | ||
|
|
||
| QHash<int, QByteArray> PlaylistModel::roleNames() const | ||
| { | ||
| return QHash<int, QByteArray> { | ||
| { RoleTitle, "title" }, | ||
| { RoleAuthor, "author" }, | ||
| { RoleDuration, "duration" }, | ||
| { RoleUrl, "url" }, | ||
| { RoleThumbnailUrl, "thumbnailUrl" }, | ||
| { RoleSearchKey, "searchKey" }, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-only | ||
| * MuseScore-CLA-applies | ||
| * | ||
| * MuseScore Studio | ||
| * Music Composition & Notation | ||
| * | ||
| * Copyright (C) 2026 MuseScore Limited and others | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QAbstractListModel> | ||
|
|
||
| #include "learn/learntypes.h" | ||
|
|
||
| namespace muse::learn { | ||
| class PlaylistModel final : public QAbstractListModel | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit PlaylistModel(QObject* parent = nullptr); | ||
|
|
||
| const Playlist& playlist(); | ||
| void setPlaylist(const Playlist&); | ||
|
|
||
| int rowCount(const QModelIndex& parent) const override; | ||
| QVariant data(const QModelIndex& index, int roleId) const override; | ||
| QHash<int, QByteArray> roleNames() const override; | ||
|
|
||
| private: | ||
| enum Roles { | ||
| RoleTitle = Qt::UserRole, | ||
| RoleAuthor, | ||
| RoleDuration, | ||
| RoleUrl, | ||
| RoleThumbnailUrl, | ||
| RoleSearchKey, | ||
| }; | ||
|
|
||
| Playlist m_playlist; | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.