forked from qt-creator/qt-creator
QmlDesigner: Add rows to a collection
Task-number: QDS-10619 Change-Id: I37a2b7ebdc3abd8f72a5fe3e7e5fd82e173cd9ea Reviewed-by: Miikka Heikkinen <miikka.heikkinen@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:
@@ -44,6 +44,25 @@ Item {
|
|||||||
enabled: root.model.selectedColumn > -1
|
enabled: root.model.selectedColumn > -1
|
||||||
onClicked: addColumnDialog.popUp(root.model.selectedColumn + 1)
|
onClicked: addColumnDialog.popUp(root.model.selectedColumn + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item { // spacer
|
||||||
|
width: 20
|
||||||
|
height: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton {
|
||||||
|
icon: StudioTheme.Constants.addrowbelow_medium
|
||||||
|
tooltip: qsTr("Insert record below")
|
||||||
|
enabled: root.model.selectedRow > -1
|
||||||
|
onClicked: root.model.insertRow(root.model.selectedRow + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton {
|
||||||
|
icon: StudioTheme.Constants.addrowabove_medium
|
||||||
|
tooltip: qsTr("Insert record above")
|
||||||
|
enabled: root.model.selectedRow > -1
|
||||||
|
onClicked: root.model.insertRow(root.model.selectedRow)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
|
|||||||
@@ -124,6 +124,20 @@ void CollectionDetails::insertElementAt(std::optional<QJsonObject> object, int r
|
|||||||
markChanged();
|
markChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollectionDetails::insertEmptyElements(int row, int count)
|
||||||
|
{
|
||||||
|
if (!isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (count < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
row = qBound(0, row, rows() - 1);
|
||||||
|
d->elements.insert(row, count, {});
|
||||||
|
|
||||||
|
markChanged();
|
||||||
|
}
|
||||||
|
|
||||||
bool CollectionDetails::setHeader(int column, const QString &value)
|
bool CollectionDetails::setHeader(int column, const QString &value)
|
||||||
{
|
{
|
||||||
if (!d->isValidColumnId(column))
|
if (!d->isValidColumnId(column))
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
bool removeColumns(int colIdx, int count = 1);
|
bool removeColumns(int colIdx, int count = 1);
|
||||||
|
|
||||||
void insertElementAt(std::optional<QJsonObject> object, int row = -1);
|
void insertElementAt(std::optional<QJsonObject> object, int row = -1);
|
||||||
|
void insertEmptyElements(int row = 0, int count = 1);
|
||||||
|
|
||||||
bool setHeader(int column, const QString &value);
|
bool setHeader(int column, const QString &value);
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,20 @@ bool SingleCollectionModel::setHeaderData(int section,
|
|||||||
return headerChanged;
|
return headerChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SingleCollectionModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
if (count < 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
row = qBound(0, row, rowCount());
|
||||||
|
beginInsertRows(parent, row, row + count);
|
||||||
|
m_currentCollection.insertEmptyElements(row, count);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
updateEmpty();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SingleCollectionModel::removeColumns(int column, int count, const QModelIndex &parent)
|
bool SingleCollectionModel::removeColumns(int column, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (column < 0 || column >= columnCount(parent) || count < 1)
|
if (column < 0 || column >= columnCount(parent) || count < 1)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
const QVariant &value,
|
const QVariant &value,
|
||||||
int role = Qt::EditRole) override;
|
int role = Qt::EditRole) override;
|
||||||
|
bool insertRows(int row, int count, const QModelIndex &parent = {}) override;
|
||||||
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
|
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|||||||
Reference in New Issue
Block a user