1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "serversmodel.h"
20 CServersModel::CServersModel(QObject
*parent
):QAbstractListModel(parent
)
22 m_servers
= CConfigFile::getInstance()->getServers();
25 CServersModel::CServersModel(const CServers
&servers
, QObject
*parent
):QAbstractListModel(parent
), m_servers(servers
)
29 CServersModel::~CServersModel()
33 int CServersModel::rowCount(const QModelIndex
&parent
) const
35 return m_servers
.size();
38 QVariant
CServersModel::data(const QModelIndex
&index
, int role
) const
40 if (role
!= Qt::DisplayRole
) return QVariant();
42 const CServer
&server
= m_servers
.at(index
.row());
47 bool CServersModel::removeRows(int row
, int count
, const QModelIndex
&parent
)
49 if (row
< 0) return false;
51 beginRemoveRows(parent
, row
, row
+ count
- 1);
53 m_servers
.removeAt(row
);
60 bool CServersModel::save() const
62 CConfigFile::getInstance()->setServers(m_servers
);
67 int CServersModel::getIndexFromServerID(const QString
&serverId
) const
69 for(int i
= 0; i
< m_servers
.size(); ++i
)
71 if (m_servers
[i
].id
== serverId
) return i
;
77 QString
CServersModel::getServerIDFromIndex(int index
) const
79 if (index
< 0 || index
>= m_servers
.size()) return "";
81 return m_servers
[index
].id
;