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