forked from qt-creator/qt-creator
QmlDesigner: Prevent accepting invalid lines on collection sort
Task-number: QDS-11117 Change-Id: Id603e5a5b85e99cf87972c853b130b26a195b223 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -176,6 +176,7 @@ bool CollectionDetailsModel::insertRows(int row, int count, const QModelIndex &p
|
|||||||
m_currentCollection.insertEmptyElements(row, count);
|
m_currentCollection.insertEmptyElements(row, count);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
selectRow(row);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +190,11 @@ 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();
|
||||||
|
|
||||||
|
int nextColumn = column - 1;
|
||||||
|
if (nextColumn < 0 && columnCount(parent) > 0)
|
||||||
|
nextColumn = 0;
|
||||||
|
|
||||||
|
selectColumn(nextColumn);
|
||||||
return columnsRemoved;
|
return columnsRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,24 +14,24 @@ CollectionDetailsSortFilterModel::CollectionDetailsSortFilterModel(QObject *pare
|
|||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
connect(this, &CollectionDetailsSortFilterModel::rowsInserted,
|
connect(this, &CollectionDetailsSortFilterModel::rowsInserted,
|
||||||
this, &CollectionDetailsSortFilterModel::updateEmpty);
|
this, &CollectionDetailsSortFilterModel::updateRowCountChanges);
|
||||||
connect(this, &CollectionDetailsSortFilterModel::rowsRemoved,
|
connect(this, &CollectionDetailsSortFilterModel::rowsRemoved,
|
||||||
this, &CollectionDetailsSortFilterModel::updateEmpty);
|
this, &CollectionDetailsSortFilterModel::updateRowCountChanges);
|
||||||
connect(this, &CollectionDetailsSortFilterModel::modelReset,
|
connect(this, &CollectionDetailsSortFilterModel::modelReset,
|
||||||
this, &CollectionDetailsSortFilterModel::updateEmpty);
|
this, &CollectionDetailsSortFilterModel::updateRowCountChanges);
|
||||||
|
|
||||||
|
setDynamicSortFilter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionDetailsSortFilterModel::setSourceModel(CollectionDetailsModel *model)
|
void CollectionDetailsSortFilterModel::setSourceModel(CollectionDetailsModel *model)
|
||||||
{
|
{
|
||||||
m_source = model;
|
m_source = model;
|
||||||
Super::setSourceModel(model);
|
Super::setSourceModel(model);
|
||||||
connect(m_source, &CollectionDetailsModel::selectedColumnChanged, this, [this](int sourceColumn) {
|
connect(m_source, &CollectionDetailsModel::selectedColumnChanged,
|
||||||
emit selectedColumnChanged(mapFromSource(m_source->index(0, sourceColumn)).column());
|
this, &CollectionDetailsSortFilterModel::updateSelectedColumn);
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_source, &CollectionDetailsModel::selectedRowChanged, this, [this](int sourceRow) {
|
connect(m_source, &CollectionDetailsModel::selectedRowChanged,
|
||||||
emit selectedRowChanged(mapFromSource(m_source->index(sourceRow, 0)).row());
|
this, &CollectionDetailsSortFilterModel::updateSelectedRow);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CollectionDetailsSortFilterModel::selectedRow() const
|
int CollectionDetailsSortFilterModel::selectedRow() const
|
||||||
@@ -64,10 +64,12 @@ bool CollectionDetailsSortFilterModel::selectColumn(int column)
|
|||||||
|
|
||||||
CollectionDetailsSortFilterModel::~CollectionDetailsSortFilterModel() = default;
|
CollectionDetailsSortFilterModel::~CollectionDetailsSortFilterModel() = default;
|
||||||
|
|
||||||
bool CollectionDetailsSortFilterModel::filterAcceptsRow(
|
bool CollectionDetailsSortFilterModel::filterAcceptsRow(int sourceRow,
|
||||||
[[maybe_unused]] int sourceRow, [[maybe_unused]] const QModelIndex &sourceParent) const
|
const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
return true;
|
QTC_ASSERT(m_source, return false);
|
||||||
|
QModelIndex sourceIndex(m_source->index(sourceRow, 0, sourceParent));
|
||||||
|
return sourceIndex.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CollectionDetailsSortFilterModel::lessThan(const QModelIndex &sourceleft,
|
bool CollectionDetailsSortFilterModel::lessThan(const QModelIndex &sourceleft,
|
||||||
@@ -93,4 +95,61 @@ void CollectionDetailsSortFilterModel::updateEmpty()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsSortFilterModel::updateSelectedRow()
|
||||||
|
{
|
||||||
|
const int upToDateSelectedRow = selectedRow();
|
||||||
|
if (m_selectedRow == upToDateSelectedRow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int rows = rowCount();
|
||||||
|
const int columns = columnCount();
|
||||||
|
const int previousRow = m_selectedRow;
|
||||||
|
|
||||||
|
m_selectedRow = upToDateSelectedRow;
|
||||||
|
emit this->selectedRowChanged(m_selectedRow);
|
||||||
|
|
||||||
|
auto notifySelectedDataChanged = [this, rows, columns](int notifyingRow) {
|
||||||
|
if (notifyingRow > -1 && notifyingRow < rows && columns) {
|
||||||
|
emit dataChanged(index(notifyingRow, 0),
|
||||||
|
index(notifyingRow, columns - 1),
|
||||||
|
{CollectionDetailsModel::SelectedRole});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
notifySelectedDataChanged(previousRow);
|
||||||
|
notifySelectedDataChanged(m_selectedRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsSortFilterModel::updateSelectedColumn()
|
||||||
|
{
|
||||||
|
const int upToDateSelectedColumn = selectedColumn();
|
||||||
|
if (m_selectedColumn == upToDateSelectedColumn)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int rows = rowCount();
|
||||||
|
const int columns = columnCount();
|
||||||
|
const int previousColumn = m_selectedColumn;
|
||||||
|
|
||||||
|
m_selectedColumn = upToDateSelectedColumn;
|
||||||
|
emit this->selectedColumnChanged(m_selectedColumn);
|
||||||
|
|
||||||
|
auto notifySelectedDataChanged = [this, rows, columns](int notifyingCol) {
|
||||||
|
if (notifyingCol > -1 && notifyingCol < columns && rows) {
|
||||||
|
emit dataChanged(index(0, notifyingCol),
|
||||||
|
index(rows - 1, notifyingCol),
|
||||||
|
{CollectionDetailsModel::SelectedRole});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
notifySelectedDataChanged(previousColumn);
|
||||||
|
notifySelectedDataChanged(m_selectedColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsSortFilterModel::updateRowCountChanges()
|
||||||
|
{
|
||||||
|
updateEmpty();
|
||||||
|
updateSelectedRow();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -44,8 +44,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateEmpty();
|
void updateEmpty();
|
||||||
|
void updateSelectedRow();
|
||||||
|
void updateSelectedColumn();
|
||||||
|
void updateRowCountChanges();
|
||||||
|
|
||||||
QPointer<CollectionDetailsModel> m_source;
|
QPointer<CollectionDetailsModel> m_source;
|
||||||
|
int m_selectedColumn = -1;
|
||||||
|
int m_selectedRow = -1;
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user