Commit 18e1dbed authored by Nikolai Kosjar's avatar Nikolai Kosjar

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's avatarFriedemann Kleint <Friedemann.Kleint@qt.io>
parent 23cc5f96
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment