Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "diagnosticspathsmodel.h"
23 :
24 : #include "log.h"
25 :
26 : using namespace muse::diagnostics;
27 :
28 0 : DiagnosticsPathsModel::DiagnosticsPathsModel(QObject* parent)
29 0 : : QAbstractListModel(parent), Contextable(muse::iocCtxForQmlObject(this))
30 : {
31 0 : }
32 :
33 0 : void DiagnosticsPathsModel::load()
34 : {
35 0 : const std::vector<IDiagnosticsPathsRegister::Item>& items = pathsRegister()->items();
36 :
37 0 : beginResetModel();
38 :
39 0 : QString dump;
40 0 : for (const IDiagnosticsPathsRegister::Item& item : items) {
41 0 : QVariantMap it;
42 0 : it["name"] = QString::fromStdString(item.name);
43 0 : it["path"] = item.path.toQString();
44 :
45 0 : dump += QString::fromStdString(item.name) + " " + item.path.toQString() + "\n";
46 :
47 0 : m_items << it;
48 0 : }
49 :
50 0 : endResetModel();
51 :
52 0 : LOGI() << dump;
53 0 : }
54 :
55 0 : void DiagnosticsPathsModel::openPath(const QString& path)
56 : {
57 0 : platformInteractive()->openUrl(QUrl::fromUserInput(path));
58 0 : }
59 :
60 0 : QVariant DiagnosticsPathsModel::data(const QModelIndex& index, int role) const
61 : {
62 0 : if (!index.isValid()) {
63 0 : return QVariant();
64 : }
65 :
66 0 : switch (role) {
67 0 : case rItemData: return m_items.at(index.row());
68 : }
69 :
70 0 : return QVariant();
71 : }
72 :
73 0 : int DiagnosticsPathsModel::rowCount(const QModelIndex&) const
74 : {
75 0 : return m_items.count();
76 : }
77 :
78 0 : QHash<int, QByteArray> DiagnosticsPathsModel::roleNames() const
79 : {
80 0 : return { { rItemData, "itemData" } };
81 0 : }
|