forked from qt-creator/qt-creator
C++: Handle invalid indices in OverviewModel
This makes the following ModelTests pass: ModelTest::nonDestructiveBasicTest() Q_ASSERT(model->data(QModelIndex()) == QVariant()); Qt::ItemFlags flags = model->flags(QModelIndex()); Q_ASSERT(flags == Qt::ItemIsDropEnabled || flags == 0); Task-number: QTCREATORBUG-13142 Change-Id: If639981079b79d8b5b3bed22fb47453650449706 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
@@ -140,6 +140,9 @@ int OverviewModel::columnCount(const QModelIndex &) const
|
||||
|
||||
QVariant OverviewModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
// account for no symbol item
|
||||
if (!index.parent().isValid() && index.row() == 0) {
|
||||
switch (role) {
|
||||
@@ -243,7 +246,9 @@ void OverviewModel::rebuild(Document::Ptr doc)
|
||||
|
||||
Qt::ItemFlags OverviewModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user