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);
|
bool columnsRemoved = m_currentCollection.removeColumns(column, count);
|
||||||
endRemoveColumns();
|
endRemoveColumns();
|
||||||
|
|
||||||
|
if (!columnCount(parent))
|
||||||
|
removeRows(0, rowCount(parent), parent);
|
||||||
|
|
||||||
int nextColumn = column - 1;
|
int nextColumn = column - 1;
|
||||||
if (nextColumn < 0 && columnCount(parent) > 0)
|
if (nextColumn < 0 && columnCount(parent) > 0)
|
||||||
nextColumn = 0;
|
nextColumn = 0;
|
||||||
|
|
||||||
selectColumn(nextColumn);
|
selectColumn(nextColumn);
|
||||||
|
|
||||||
|
ensureSingleCell();
|
||||||
return columnsRemoved;
|
return columnsRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +242,7 @@ bool CollectionDetailsModel::removeRows(int row, int count, const QModelIndex &p
|
|||||||
bool rowsRemoved = m_currentCollection.removeElements(row, count);
|
bool rowsRemoved = m_currentCollection.removeElements(row, count);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
|
ensureSingleCell();
|
||||||
return rowsRemoved;
|
return rowsRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,8 +323,8 @@ bool CollectionDetailsModel::selectColumn(int section)
|
|||||||
|
|
||||||
const int columns = columnCount();
|
const int columns = columnCount();
|
||||||
|
|
||||||
if (m_selectedColumn >= columns)
|
if (section >= columns)
|
||||||
return false;
|
section = columns - 1;
|
||||||
|
|
||||||
selectRow(-1);
|
selectRow(-1);
|
||||||
|
|
||||||
@@ -415,6 +421,7 @@ void CollectionDetailsModel::loadCollection(const ModelNode &sourceNode, const Q
|
|||||||
deselectAll();
|
deselectAll();
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
switchToCollection(newReference);
|
switchToCollection(newReference);
|
||||||
|
ensureSingleCell();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -583,6 +590,7 @@ void CollectionDetailsModel::loadJsonCollection(const QString &source, const QSt
|
|||||||
SourceFormat sourceFormat = jsonFileIsOk ? SourceFormat::Json : SourceFormat::Unknown;
|
SourceFormat sourceFormat = jsonFileIsOk ? SourceFormat::Json : SourceFormat::Unknown;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_currentCollection.resetDetails(getJsonHeaders(collectionNodes), elements, sourceFormat);
|
m_currentCollection.resetDetails(getJsonHeaders(collectionNodes), elements, sourceFormat);
|
||||||
|
ensureSingleCell();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,9 +643,24 @@ void CollectionDetailsModel::loadCsvCollection(const QString &source,
|
|||||||
SourceFormat sourceFormat = csvFileIsOk ? SourceFormat::Csv : SourceFormat::Unknown;
|
SourceFormat sourceFormat = csvFileIsOk ? SourceFormat::Csv : SourceFormat::Unknown;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_currentCollection.resetDetails(headers, elements, sourceFormat);
|
m_currentCollection.resetDetails(headers, elements, sourceFormat);
|
||||||
|
ensureSingleCell();
|
||||||
endResetModel();
|
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)
|
QVariant CollectionDetailsModel::variantFromString(const QString &value)
|
||||||
{
|
{
|
||||||
constexpr QStringView typesPattern{u"(?<boolean>^(?:true|false)$)|"
|
constexpr QStringView typesPattern{u"(?<boolean>^(?:true|false)$)|"
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ private:
|
|||||||
void setCollectionName(const QString &newCollectionName);
|
void setCollectionName(const QString &newCollectionName);
|
||||||
void loadJsonCollection(const QString &source, const QString &collection);
|
void loadJsonCollection(const QString &source, const QString &collection);
|
||||||
void loadCsvCollection(const QString &source, const QString &collectionName);
|
void loadCsvCollection(const QString &source, const QString &collectionName);
|
||||||
|
void ensureSingleCell();
|
||||||
QVariant variantFromString(const QString &value);
|
QVariant variantFromString(const QString &value);
|
||||||
|
|
||||||
QHash<CollectionReference, CollectionDetails> m_openedCollections;
|
QHash<CollectionReference, CollectionDetails> m_openedCollections;
|
||||||
|
|||||||
Reference in New Issue
Block a user