From 7fc1c5abed475212c76195f0d2fddb6c7d08be4a Mon Sep 17 00:00:00 2001 From: Roman Pudashkin Date: Wed, 25 Nov 2020 10:21:25 +0200 Subject: [PATCH] fixed updating state of the instruments panel controls when there is no opened notation --- .../Instruments/InstrumentsPanel.qml | 9 ++-- .../internal/InstrumentsControlPanel.qml | 5 +- .../view/instrumentpaneltreemodel.cpp | 10 ++++ .../view/instrumentpaneltreemodel.h | 52 +++++++++---------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/mu4/instruments/qml/MuseScore/Instruments/InstrumentsPanel.qml b/mu4/instruments/qml/MuseScore/Instruments/InstrumentsPanel.qml index f9548894c0..ee1b51dfd7 100644 --- a/mu4/instruments/qml/MuseScore/Instruments/InstrumentsPanel.qml +++ b/mu4/instruments/qml/MuseScore/Instruments/InstrumentsPanel.qml @@ -28,9 +28,11 @@ Item { InstrumentsControlPanel { Layout.fillWidth: true + Layout.alignment: Qt.AlignTop isMovingUpAvailable: instrumentTreeModel.isMovingUpAvailable isMovingDownAvailable: instrumentTreeModel.isMovingDownAvailable + isAddingAvailable: instrumentTreeModel.isAddingAvailable isRemovingAvailable: instrumentTreeModel.isRemovingAvailable onAddRequested: { @@ -51,14 +53,14 @@ Item { } StyledTextLabel { - Layout.topMargin: 12 Layout.fillWidth: true Layout.fillHeight: true + Layout.topMargin: 12 Layout.leftMargin: 20 Layout.rightMargin: 20 text: qsTrc("instruments", "There are no instruments in your score. To choose some, press Add, or use the shortcut ā€˜iā€™") - visible: instrumentsTreeView.isEmpty + visible: instrumentTreeModel.isEmpty && instrumentTreeModel.isAddingAvailable verticalAlignment: Qt.AlignTop wrapMode: Text.WordWrap @@ -70,8 +72,7 @@ Item { Layout.fillWidth: true Layout.fillHeight: true - property alias isEmpty: instrumentTreeModel.isEmpty - visible: !isEmpty + visible: !instrumentTreeModel.isEmpty model: InstrumentPanelTreeModel { id: instrumentTreeModel diff --git a/mu4/instruments/qml/MuseScore/Instruments/internal/InstrumentsControlPanel.qml b/mu4/instruments/qml/MuseScore/Instruments/internal/InstrumentsControlPanel.qml index 9ee5751c2d..b379f96150 100644 --- a/mu4/instruments/qml/MuseScore/Instruments/internal/InstrumentsControlPanel.qml +++ b/mu4/instruments/qml/MuseScore/Instruments/internal/InstrumentsControlPanel.qml @@ -9,8 +9,8 @@ RowLayout { property bool isMovingUpAvailable: false property bool isMovingDownAvailable: false - property bool isRearrangementAvailable: false property bool isRemovingAvailable: false + property bool isAddingAvailable: value signal addRequested() signal moveUpRequested() @@ -21,8 +21,11 @@ RowLayout { FlatButton { Layout.fillWidth: true + text: qsTrc("instruments", "Add") + enabled: root.isAddingAvailable + onClicked: { root.addRequested() } diff --git a/mu4/instruments/view/instrumentpaneltreemodel.cpp b/mu4/instruments/view/instrumentpaneltreemodel.cpp index 83dffc39ac..0e60c93578 100644 --- a/mu4/instruments/view/instrumentpaneltreemodel.cpp +++ b/mu4/instruments/view/instrumentpaneltreemodel.cpp @@ -70,10 +70,12 @@ InstrumentPanelTreeModel::~InstrumentPanelTreeModel() void InstrumentPanelTreeModel::clear() { beginResetModel(); + m_selectionModel->clear(); deleteItems(); endResetModel(); emit isEmptyChanged(); + emit isAddingAvailableChanged(false); } void InstrumentPanelTreeModel::deleteItems() @@ -120,6 +122,9 @@ void InstrumentPanelTreeModel::load() }); endResetModel(); + + emit isEmptyChanged(); + emit isAddingAvailableChanged(true); } IDList InstrumentPanelTreeModel::currentNotationPartIdList() const @@ -401,6 +406,11 @@ bool InstrumentPanelTreeModel::isRemovingAvailable() const return m_isRemovingAvailable; } +bool InstrumentPanelTreeModel::isAddingAvailable() const +{ + return m_notationParts != nullptr; +} + bool InstrumentPanelTreeModel::isEmpty() const { return m_rootItem ? m_rootItem->isEmpty() : true; diff --git a/mu4/instruments/view/instrumentpaneltreemodel.h b/mu4/instruments/view/instrumentpaneltreemodel.h index 956bd7bc1d..09589e8972 100644 --- a/mu4/instruments/view/instrumentpaneltreemodel.h +++ b/mu4/instruments/view/instrumentpaneltreemodel.h @@ -45,34 +45,16 @@ class InstrumentPanelTreeModel : public QAbstractItemModel, public async::Asynca INJECT(instruments, framework::IInteractive, interactive) Q_PROPERTY(QItemSelectionModel * selectionModel READ selectionModel NOTIFY selectionChanged) - Q_PROPERTY(bool isMovingUpAvailable READ isMovingUpAvailable WRITE setIsMovingUpAvailable NOTIFY isMovingUpAvailableChanged) - Q_PROPERTY(bool isMovingDownAvailable READ isMovingDownAvailable WRITE setIsMovingDownAvailable NOTIFY isMovingDownAvailableChanged) - Q_PROPERTY(bool isRemovingAvailable READ isRemovingAvailable WRITE setIsRemovingAvailable NOTIFY isRemovingAvailableChanged) + Q_PROPERTY(bool isMovingUpAvailable READ isMovingUpAvailable NOTIFY isMovingUpAvailableChanged) + Q_PROPERTY(bool isMovingDownAvailable READ isMovingDownAvailable NOTIFY isMovingDownAvailableChanged) + Q_PROPERTY(bool isRemovingAvailable READ isRemovingAvailable NOTIFY isRemovingAvailableChanged) + Q_PROPERTY(bool isAddingAvailable READ isAddingAvailable NOTIFY isAddingAvailableChanged) Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY isEmptyChanged) public: - enum RoleNames { - ItemRole = Qt::UserRole + 1 - }; - explicit InstrumentPanelTreeModel(QObject* parent = nullptr); ~InstrumentPanelTreeModel() override; - Q_INVOKABLE void load(); - Q_INVOKABLE void selectRow(const QModelIndex& rowIndex, const bool isMultipleSelectionModeOn); - Q_INVOKABLE void addInstruments(); - Q_INVOKABLE void moveSelectedRowsUp(); - Q_INVOKABLE void moveSelectedRowsDown(); - Q_INVOKABLE void removeSelectedRows(); - - bool isMovingUpAvailable() const; - bool isMovingDownAvailable() const; - bool isRemovingAvailable() const; - bool isEmpty() const; - - Q_INVOKABLE bool moveRows(const QModelIndex& sourceParent, int sourceRow, int count, const QModelIndex& destinationParent, - int destinationChild) override; - QModelIndex index(int row, int column, const QModelIndex& parent) const override; QModelIndex parent(const QModelIndex& child) const override; int rowCount(const QModelIndex& parent) const override; @@ -81,16 +63,26 @@ public: QHash roleNames() const override; QItemSelectionModel* selectionModel() const; + bool isMovingUpAvailable() const; + bool isMovingDownAvailable() const; + bool isRemovingAvailable() const; + bool isAddingAvailable() const; + bool isEmpty() const; -public slots: - void setIsMovingUpAvailable(bool isMovingUpAvailable); - void setIsMovingDownAvailable(bool isMovingDownAvailable); - void setIsRemovingAvailable(bool isRemovingAvailable); + Q_INVOKABLE void load(); + Q_INVOKABLE void selectRow(const QModelIndex& rowIndex, const bool isMultipleSelectionModeOn); + Q_INVOKABLE void addInstruments(); + Q_INVOKABLE void moveSelectedRowsUp(); + Q_INVOKABLE void moveSelectedRowsDown(); + Q_INVOKABLE void removeSelectedRows(); + Q_INVOKABLE bool moveRows(const QModelIndex& sourceParent, int sourceRow, int count, const QModelIndex& destinationParent, + int destinationChild) override; signals: void selectionChanged(); void isMovingUpAvailableChanged(bool isMovingUpAvailable); void isMovingDownAvailableChanged(bool isMovingDownAvailable); + void isAddingAvailableChanged(bool isAddingAvailable); void isRemovingAvailableChanged(bool isRemovingAvailable); void isEmptyChanged(); @@ -101,9 +93,17 @@ private slots: void updateRemovingAvailability(); private: + enum RoleNames { + ItemRole = Qt::UserRole + 1 + }; + void clear(); void deleteItems(); + void setIsMovingUpAvailable(bool isMovingUpAvailable); + void setIsMovingDownAvailable(bool isMovingDownAvailable); + void setIsRemovingAvailable(bool isRemovingAvailable); + bool removeRows(int row, int count, const QModelIndex& parent) override; notation::IDList currentNotationPartIdList() const;