diff --git a/share/qtcreator/qmldesigner/collectionEditorQmlSource/CollectionDetailsToolbar.qml b/share/qtcreator/qmldesigner/collectionEditorQmlSource/CollectionDetailsToolbar.qml index 852341b9d5d..e7997f7eae6 100644 --- a/share/qtcreator/qmldesigner/collectionEditorQmlSource/CollectionDetailsToolbar.qml +++ b/share/qtcreator/qmldesigner/collectionEditorQmlSource/CollectionDetailsToolbar.qml @@ -17,7 +17,6 @@ Rectangle { required property var model required property var backend property int selectedRow: -1 - property bool hasUnsavedChanges: false implicitHeight: StudioTheme.Values.toolbarHeight color: StudioTheme.Values.themeToolbarBackground @@ -35,14 +34,6 @@ Rectangle { fileDialog.reject() } - Connections { - target: root.model - - function onDataChanged() { - hasUnsavedChanges = true - } - } - RowLayout { id: container @@ -131,8 +122,8 @@ Rectangle { buttonIcon: StudioTheme.Constants.save_medium tooltip: qsTr("Save changes") - enabled: root.model.collectionName !== "" && root.hasUnsavedChanges - onClicked: hasUnsavedChanges = !root.model.saveDataStoreCollections() + enabled: root.model.collectionName !== "" && root.model.hasUnsavedChanges + onClicked: root.model.saveDataStoreCollections() Rectangle { width: StudioTheme.Values.smallStatusIndicatorDiameter @@ -140,7 +131,7 @@ Rectangle { radius: StudioTheme.Values.smallStatusIndicatorDiameter / 2 anchors.right: parent.right anchors.top: parent.top - visible: hasUnsavedChanges + visible: root.model.hasUnsavedChanges color: StudioTheme.Values.themeIconColorSelected } } diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp index 1643dfc23e2..d2917ec3022 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp @@ -93,6 +93,7 @@ bool CollectionDetailsModel::setData(const QModelIndex &index, const QVariant &v if (prevWarning != m_currentCollection.cellWarningCheck(index.row(), index.column())) roles << DataTypeWarningRole; + setHasUnsavedChanges(true); emit dataChanged(index, index, roles); } @@ -131,6 +132,7 @@ bool CollectionDetailsModel::insertRows(int row, int count, [[maybe_unused]] con beginInsertRows({}, row, row + count - 1); m_currentCollection.insertEmptyRows(row, count); endInsertRows(); + setHasUnsavedChanges(true); return true; } @@ -247,6 +249,7 @@ bool CollectionDetailsModel::addColumn(int column, const QString &name, const QS {}, CollectionDataTypeModel::dataTypeFromString(propertyType)); endInsertColumns(); + setHasUnsavedChanges(true); return m_currentCollection.containsPropertyName(name); } @@ -302,6 +305,7 @@ bool CollectionDetailsModel::setPropertyType(int column, const QString &newValue {Qt::DisplayRole, Qt::EditRole, DataTypeRole, DataTypeWarningRole, ColumnDataTypeRole}); } + setHasUnsavedChanges(true); return changed; } @@ -434,6 +438,7 @@ bool CollectionDetailsModel::saveDataStoreCollections() if (reference != currentReference) closeCollectionIfSaved(reference); } + setHasUnsavedChanges(false); return true; } } @@ -611,4 +616,12 @@ QString CollectionDetailsModel::warningToString(DataTypeWarning::Warning warning return DataTypeWarning::getDataTypeWarningString(warning); } +void CollectionDetailsModel::setHasUnsavedChanges(bool val) +{ + if (m_hasUnsavedChanges == val) + return; + m_hasUnsavedChanges = val; + emit hasUnsavedChangesChanged(); +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.h b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.h index 24a040cce6c..8844ff4a3ef 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.h +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.h @@ -20,6 +20,7 @@ class CollectionDetailsModel : public QAbstractTableModel Q_PROPERTY(int selectedColumn READ selectedColumn WRITE selectColumn NOTIFY selectedColumnChanged) Q_PROPERTY(int selectedRow READ selectedRow WRITE selectRow NOTIFY selectedRowChanged) Q_PROPERTY(bool isEmpty MEMBER m_isEmpty NOTIFY isEmptyChanged) + Q_PROPERTY(bool hasUnsavedChanges MEMBER m_hasUnsavedChanges WRITE setHasUnsavedChanges NOTIFY hasUnsavedChangesChanged) public: enum DataRoles { SelectedRole = Qt::UserRole + 1, DataTypeRole, ColumnDataTypeRole, DataTypeWarningRole }; @@ -70,12 +71,14 @@ public: const CollectionDetails upToDateConstCollection(const CollectionReference &reference) const; bool collectionHasColumn(const CollectionReference &reference, const QString &columnName) const; QString getFirstColumnName(const CollectionReference &reference) const; + void setHasUnsavedChanges(bool val); signals: void collectionNameChanged(const QString &collectionName); void selectedColumnChanged(int); void selectedRowChanged(int); void isEmptyChanged(bool); + void hasUnsavedChangesChanged(); void warning(const QString &title, const QString &body); private slots: @@ -93,6 +96,7 @@ private: QHash m_openedCollections; CollectionDetails m_currentCollection; bool m_isEmpty = true; + bool m_hasUnsavedChanges = false; int m_selectedColumn = -1; int m_selectedRow = -1;