Skip to content
Snippets Groups Projects
Commit 086b14b1 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #55020 ] Fix account creation

parent a17c6d64
Branches
Tags
No related merge requests found
...@@ -47,7 +47,7 @@ CategorizedAccountModel::~CategorizedAccountModel() ...@@ -47,7 +47,7 @@ CategorizedAccountModel::~CategorizedAccountModel()
QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const
{ {
if (!idx.isValid() || !idx.parent().isValid()) if (!idx.isValid() || !idx.parent().isValid() || idx.model() != this)
return QModelIndex(); return QModelIndex();
switch (idx.parent().row()) { switch (idx.parent().row()) {
case Categories::IP2IP: case Categories::IP2IP:
...@@ -55,7 +55,8 @@ QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const ...@@ -55,7 +55,8 @@ QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const
break; break;
case Categories::SERVER: { case Categories::SERVER: {
const QModelIndex& ip2ipIdx = AccountListModel::instance()->ip2ip()->index(); const QModelIndex& ip2ipIdx = AccountListModel::instance()->ip2ip()->index();
return AccountListModel::instance()->index((ip2ipIdx.row() < idx.row())?idx.row()+1:idx.row(),0); //TODO DHT: this will stop working
return AccountListModel::instance()->index((ip2ipIdx.row() <= idx.row())?idx.row()+1:idx.row(),0);
} }
break; break;
default: default:
...@@ -65,6 +66,18 @@ QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const ...@@ -65,6 +66,18 @@ QModelIndex CategorizedAccountModel::mapToSource(const QModelIndex& idx) const
return QModelIndex(); return QModelIndex();
} }
QModelIndex CategorizedAccountModel::mapFromSource(const QModelIndex& idx) const
{
if (!idx.isValid() || idx.model() != AccountListModel::instance())
return QModelIndex();
//TODO DHT: this will stop working
const QModelIndex& ip2ipIdx = AccountListModel::instance()->ip2ip()->index();
return idx.row() == ip2ipIdx.row()?index(0,0,index(Categories::IP2IP,0,QModelIndex())): (
index(idx.row()+(idx.row() > ip2ipIdx.row()?-1:0),0,index(Categories::SERVER,0,QModelIndex()))
);
}
QVariant CategorizedAccountModel::data(const QModelIndex& index, int role ) const QVariant CategorizedAccountModel::data(const QModelIndex& index, int role ) const
{ {
if (!index.isValid()) if (!index.isValid())
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
//Getter //Getter
QModelIndex mapToSource (const QModelIndex& idx) const; QModelIndex mapToSource (const QModelIndex& idx) const;
QModelIndex mapFromSource(const QModelIndex& idx) const;
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment