forked from qt-creator/qt-creator
QmlDesigner: Model should have at least one cell
* If all of the columns are deleted, all of the objects will be deleted and a single column, with one empty row will be created. * A bug is fixed for the cases that we have invalid selected column. Task-number: QDS-11649 Fixes: QDS-11678 Change-Id: I8bdbd0176ad76dd761e98b5030cdc77379a8642b Reviewed-by: Shrief Gabr <shrief.gabr@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -219,11 +219,16 @@ bool CollectionDetailsModel::removeColumns(int column, int count, const QModelIn
|
||||
bool columnsRemoved = m_currentCollection.removeColumns(column, count);
|
||||
endRemoveColumns();
|
||||
|
||||
if (!columnCount(parent))
|
||||
removeRows(0, rowCount(parent), parent);
|
||||
|
||||
int nextColumn = column - 1;
|
||||
if (nextColumn < 0 && columnCount(parent) > 0)
|
||||
nextColumn = 0;
|
||||
|
||||
selectColumn(nextColumn);
|
||||
|
||||
ensureSingleCell();
|
||||
return columnsRemoved;
|
||||
}
|
||||
|
||||
@@ -237,6 +242,7 @@ bool CollectionDetailsModel::removeRows(int row, int count, const QModelIndex &p
|
||||
bool rowsRemoved = m_currentCollection.removeElements(row, count);
|
||||
endRemoveRows();
|
||||
|
||||
ensureSingleCell();
|
||||
return rowsRemoved;
|
||||
}
|
||||
|
||||
@@ -317,8 +323,8 @@ bool CollectionDetailsModel::selectColumn(int section)
|
||||
|
||||
const int columns = columnCount();
|
||||
|
||||
if (m_selectedColumn >= columns)
|
||||
return false;
|
||||
if (section >= columns)
|
||||
section = columns - 1;
|
||||
|
||||
selectRow(-1);
|
||||
|
||||
@@ -415,6 +421,7 @@ void CollectionDetailsModel::loadCollection(const ModelNode &sourceNode, const Q
|
||||
deselectAll();
|
||||
beginResetModel();
|
||||
switchToCollection(newReference);
|
||||
ensureSingleCell();
|
||||
endResetModel();
|
||||
}
|
||||
} else {
|
||||
@@ -583,6 +590,7 @@ void CollectionDetailsModel::loadJsonCollection(const QString &source, const QSt
|
||||
SourceFormat sourceFormat = jsonFileIsOk ? SourceFormat::Json : SourceFormat::Unknown;
|
||||
beginResetModel();
|
||||
m_currentCollection.resetDetails(getJsonHeaders(collectionNodes), elements, sourceFormat);
|
||||
ensureSingleCell();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
@@ -635,9 +643,24 @@ void CollectionDetailsModel::loadCsvCollection(const QString &source,
|
||||
SourceFormat sourceFormat = csvFileIsOk ? SourceFormat::Csv : SourceFormat::Unknown;
|
||||
beginResetModel();
|
||||
m_currentCollection.resetDetails(headers, elements, sourceFormat);
|
||||
ensureSingleCell();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void CollectionDetailsModel::ensureSingleCell()
|
||||
{
|
||||
if (!m_currentCollection.isValid())
|
||||
return;
|
||||
|
||||
if (!columnCount())
|
||||
addColumn(0, "Column 1", "String");
|
||||
|
||||
if (!rowCount())
|
||||
insertRow(0);
|
||||
|
||||
updateEmpty();
|
||||
}
|
||||
|
||||
QVariant CollectionDetailsModel::variantFromString(const QString &value)
|
||||
{
|
||||
constexpr QStringView typesPattern{u"(?<boolean>^(?:true|false)$)|"
|
||||
|
||||
@@ -81,6 +81,7 @@ private:
|
||||
void setCollectionName(const QString &newCollectionName);
|
||||
void loadJsonCollection(const QString &source, const QString &collection);
|
||||
void loadCsvCollection(const QString &source, const QString &collectionName);
|
||||
void ensureSingleCell();
|
||||
QVariant variantFromString(const QString &value);
|
||||
|
||||
QHash<CollectionReference, CollectionDetails> m_openedCollections;
|
||||
|
||||
Reference in New Issue
Block a user