forked from qt-creator/qt-creator
QmlDesigner: Select the property type while adding a column
Task-number: QDS-11004 Change-Id: Ie2b8cb715efc2d530b2ce8dec2d7111b7fc318cc Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Qt.labs.platform as PlatformWidgets
|
||||
import HelperWidgets 2.0 as HelperWidgets
|
||||
import StudioControls 1.0 as StudioControls
|
||||
@@ -43,7 +44,7 @@ Item {
|
||||
IconButton {
|
||||
icon: StudioTheme.Constants.addcolumnleft_medium
|
||||
tooltip: qsTr("Add property left %1").arg(leftSideToolbar.topPadding)
|
||||
enabled: root.model.selectedColumn > 0
|
||||
enabled: root.model.selectedColumn > -1
|
||||
onClicked: addColumnDialog.popUp(root.model.selectedColumn - 1)
|
||||
}
|
||||
|
||||
@@ -189,12 +190,15 @@ Item {
|
||||
function popUp(index)
|
||||
{
|
||||
addColumnDialog.clickedIndex = index
|
||||
columnName.text = ""
|
||||
addedPropertyType.currentIndex = addedPropertyType.find("String")
|
||||
|
||||
addColumnDialog.open()
|
||||
}
|
||||
|
||||
function addColumnName() {
|
||||
if (addColumnDialog.nameIsValid) {
|
||||
root.model.addColumn(addColumnDialog.clickedIndex, columnName.text)
|
||||
root.model.addColumn(addColumnDialog.clickedIndex, columnName.text, addedPropertyType.currentText)
|
||||
addColumnDialog.accept()
|
||||
} else {
|
||||
addColumnDialog.reject()
|
||||
@@ -204,8 +208,10 @@ Item {
|
||||
contentItem: Column {
|
||||
spacing: 2
|
||||
|
||||
Row {
|
||||
spacing: 10
|
||||
GridLayout {
|
||||
rowSpacing: 10
|
||||
columnSpacing: 10
|
||||
columns: 2
|
||||
|
||||
Text {
|
||||
text: qsTr("Column name:")
|
||||
@@ -228,12 +234,25 @@ Item {
|
||||
&& !root.model.isPropertyAvailable(columnName.text))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("The collection already contains \"%1\"!").arg(columnName.text)
|
||||
visible: columnName.text !== "" && !addColumnDialog.nameIsValid
|
||||
color: "red"
|
||||
color: StudioTheme.Values.themeRedLight
|
||||
Layout.columnSpan: 2
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("Type:")
|
||||
color: StudioTheme.Values.themeTextColor
|
||||
}
|
||||
|
||||
StudioControls.ComboBox {
|
||||
id: addedPropertyType
|
||||
|
||||
model: root.model.typesList()
|
||||
actionIndicatorVisible: false
|
||||
}
|
||||
}
|
||||
|
||||
Item { // spacer
|
||||
|
@@ -94,6 +94,7 @@ StudioControls.Dialog {
|
||||
readonly property bool changed: propertyType.initialType !== propertyType.currentText
|
||||
|
||||
model: root.model.typesList()
|
||||
actionIndicatorVisible: false
|
||||
|
||||
onInitialTypeChanged: {
|
||||
let propertyIndex = propertyType.find(initialType)
|
||||
|
@@ -45,7 +45,7 @@ public:
|
||||
static DataType typeFromString(const QString &dataType)
|
||||
{
|
||||
static const QHash<QString, DataType> stringTypeHash = stringToTypeHash();
|
||||
return stringTypeHash.value(dataType);
|
||||
return stringTypeHash.value(dataType, DataType::Unknown);
|
||||
}
|
||||
|
||||
static QStringList typesStringList()
|
||||
@@ -263,7 +263,7 @@ bool CollectionDetailsModel::isPropertyAvailable(const QString &name)
|
||||
return m_currentCollection.containsPropertyName(name);
|
||||
}
|
||||
|
||||
bool CollectionDetailsModel::addColumn(int column, const QString &name)
|
||||
bool CollectionDetailsModel::addColumn(int column, const QString &name, const QString &propertyType)
|
||||
{
|
||||
if (m_currentCollection.containsPropertyName(name))
|
||||
return false;
|
||||
@@ -272,7 +272,10 @@ bool CollectionDetailsModel::addColumn(int column, const QString &name)
|
||||
column = columnCount();
|
||||
|
||||
beginInsertColumns({}, column, column);
|
||||
m_currentCollection.insertColumn(name, column);
|
||||
m_currentCollection.insertColumn(name,
|
||||
column,
|
||||
{},
|
||||
CollectionDataTypeHelper::typeFromString(propertyType));
|
||||
endInsertColumns();
|
||||
return m_currentCollection.containsPropertyName(name);
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public:
|
||||
Q_INVOKABLE QString propertyType(int column) const;
|
||||
|
||||
Q_INVOKABLE bool isPropertyAvailable(const QString &name);
|
||||
Q_INVOKABLE bool addColumn(int column, const QString &name);
|
||||
Q_INVOKABLE bool addColumn(int column, const QString &name, const QString &propertyType = {});
|
||||
Q_INVOKABLE bool selectColumn(int section);
|
||||
Q_INVOKABLE bool renameColumn(int section, const QString &newValue);
|
||||
Q_INVOKABLE bool setPropertyType(int column, const QString &newValue, bool force = false);
|
||||
|
Reference in New Issue
Block a user