forked from qt-creator/qt-creator
QmlDesigner: Fix save indicator behavior on selection change
Task-number: QDS-12499 Change-Id: If91aab8d133a9269d9fc381ea0a130d3953aa69d Reviewed-by: Ali Kianian <ali.kianian@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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<CollectionReference, CollectionDetails> m_openedCollections;
|
||||
CollectionDetails m_currentCollection;
|
||||
bool m_isEmpty = true;
|
||||
bool m_hasUnsavedChanges = false;
|
||||
int m_selectedColumn = -1;
|
||||
int m_selectedRow = -1;
|
||||
|
||||
|
Reference in New Issue
Block a user