Commit 588e4d2c authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

Fix some cornercases in the models

Found by ModelTest class, special thanks to fregl!

svn path=/trunk/KDE/kdeutils/kgpg/; revision=816882
parent f64059b9
......@@ -71,7 +71,7 @@ GroupEditProxyModel::columnCount(const QModelIndex &) const
QVariant
GroupEditProxyModel::data(const QModelIndex &index, int role) const
{
if ((index.column() >= 3) || (role != Qt::DisplayRole))
if (!index.isValid() || (index.column() >= 3) || (role != Qt::DisplayRole))
return QVariant();
KGpgNode *nd = m_model->nodeForIndex(mapToSource(index));
......
......@@ -49,7 +49,8 @@ KGpgItemModel::index(int row, int column, const QModelIndex &parent) const
QModelIndex
KGpgItemModel::parent(const QModelIndex &child) const
{
Q_ASSERT(child.isValid());
if (!child.isValid())
return QModelIndex();
KGpgNode *childNode = nodeForIndex(child);
KGpgNode *parentNode = childNode->m_parent;
......@@ -66,6 +67,9 @@ KGpgItemModel::parent(const QModelIndex &child) const
int
KGpgItemModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0)
return 0;
KGpgNode *parentNode = nodeForIndex(parent);
return parentNode->getChildCount();
......@@ -74,6 +78,9 @@ KGpgItemModel::rowCount(const QModelIndex &parent) const
bool
KGpgItemModel::hasChildren(const QModelIndex &parent) const
{
if (parent.column() > 0)
return false;
KGpgNode *parentNode = nodeForIndex(parent);
return parentNode->hasChildren();
......
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