2016-03-05 11:35:32 +00:00
|
|
|
#include "profilesmodel.h"
|
|
|
|
|
|
|
|
CProfilesModel::CProfilesModel(QObject *parent):QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
m_profiles = CConfigFile::getInstance()->getProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
CProfilesModel::CProfilesModel(const CProfiles &profiles, QObject *parent):QAbstractListModel(parent), m_profiles(profiles)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CProfilesModel::~CProfilesModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CProfilesModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return m_profiles.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CProfilesModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (role != Qt::DisplayRole) return QVariant();
|
|
|
|
|
|
|
|
const CProfile &profile = m_profiles.at(index.row());
|
|
|
|
|
2016-05-16 12:46:08 +00:00
|
|
|
return tr("#%1: %2").arg(profile.id).arg(profile.name);
|
2016-03-05 11:35:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 14:59:21 +00:00
|
|
|
bool CProfilesModel::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
if (row < 0) return false;
|
|
|
|
|
|
|
|
beginInsertRows(parent, row, row + count - 1);
|
|
|
|
|
|
|
|
// prepend empty profiles
|
|
|
|
CProfile profile;
|
|
|
|
m_profiles.insert(row, count, profile);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-05 11:35:32 +00:00
|
|
|
bool CProfilesModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
if (row < 0) return false;
|
|
|
|
|
|
|
|
beginRemoveRows(parent, row, row + count - 1);
|
|
|
|
|
|
|
|
m_profiles.removeAt(row);
|
|
|
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProfilesModel::save() const
|
|
|
|
{
|
|
|
|
CConfigFile::getInstance()->setProfiles(m_profiles);
|
2016-03-12 21:00:43 +00:00
|
|
|
CConfigFile::getInstance()->save();
|
2016-03-05 11:35:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-12 20:57:24 +00:00
|
|
|
|
2016-05-16 12:45:43 +00:00
|
|
|
int CProfilesModel::getIndexFromProfileID(const QString &profileId) const
|
2016-03-12 20:57:24 +00:00
|
|
|
{
|
|
|
|
for(int i = 0; i < m_profiles.size(); ++i)
|
|
|
|
{
|
|
|
|
if (m_profiles[i].id == profileId) return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:45:43 +00:00
|
|
|
QString CProfilesModel::getProfileIDFromIndex(int index) const
|
2016-03-12 20:57:24 +00:00
|
|
|
{
|
2016-05-16 14:49:42 +00:00
|
|
|
if (index < 0 || index >= m_profiles.size()) return "";
|
2016-03-12 20:57:24 +00:00
|
|
|
|
|
|
|
return m_profiles[index].id;
|
|
|
|
}
|