Commit 4e4580d4 authored by Christian Kandeler's avatar Christian Kandeler Committed by hjk

Make handling of model ids compatible with Qt 5.

QAbstractItemModel::internalId() returns a quintptr in Qt 5. Handle this
in a way compatible with both Qt 4 and Qt 5.

Change-Id: Iacb9ab71e95085f061fac1e3f4e4759ed43ca7ef
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent db0a6f52
......@@ -294,6 +294,12 @@ static int bitWidthFromType(int type, int subType)
return 0;
}
static const int TopLevelId = -1;
static bool isTopLevelItem(const QModelIndex &index)
{
return quintptr(index.internalId()) == quintptr(TopLevelId);
}
Register::Register(const QByteArray &name_)
: name(name_), changed(true)
{
......@@ -322,7 +328,7 @@ int RegisterHandler::rowCount(const QModelIndex &idx) const
return 0;
if (!idx.isValid())
return m_registers.size(); // Top level.
if (idx.internalId() >= 0)
if (!isTopLevelItem(idx))
return 0; // Sub-Items don't have children.
if (idx.row() >= m_registers.size())
return 0;
......@@ -335,7 +341,7 @@ int RegisterHandler::columnCount(const QModelIndex &idx) const
return 0;
if (!idx.isValid())
return 2;
if (idx.internalId() >= 0)
if (!isTopLevelItem(idx))
return 0; // Sub-Items don't have children.
return 2;
}
......@@ -345,8 +351,8 @@ QModelIndex RegisterHandler::index(int row, int col, const QModelIndex &parent)
if (row < 0 || col < 0 || col >= 2)
return QModelIndex();
if (!parent.isValid()) // Top level.
return createIndex(row, col, -1);
if (parent.internalId() >= 0) // Sub-Item has no children.
return createIndex(row, col, TopLevelId);
if (!isTopLevelItem(parent)) // Sub-Item has no children.
return QModelIndex();
if (parent.column() > 0)
return QModelIndex();
......@@ -357,8 +363,8 @@ QModelIndex RegisterHandler::parent(const QModelIndex &idx) const
{
if (!idx.isValid())
return QModelIndex();
if (idx.internalId() >= 0)
return createIndex(idx.internalId(), 0, -1);
if (!isTopLevelItem(idx))
return createIndex(idx.internalId(), 0, TopLevelId);
return QModelIndex();
}
......
......@@ -192,7 +192,7 @@ QModelIndex StackModel::parent(const QModelIndex &child) const
{
QTC_ASSERT(!child.isValid() || child.model() == this, return QModelIndex());
if (child.internalId() == -1)
if (quintptr(child.internalId()) == quintptr(-1))
return QModelIndex();
return createIndex(child.internalId(), 0, -1);
}
......
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