mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-18 13:21:40 +00:00
Added: Profiles model class
This commit is contained in:
parent
c2c9fbed36
commit
38edd05618
2 changed files with 74 additions and 0 deletions
|
@ -0,0 +1,48 @@
|
|||
#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());
|
||||
|
||||
return QString("%1 (%2)").arg(profile.name).arg(profile.id);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return true;
|
||||
}
|
26
code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h
Normal file
26
code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef PROFILESMODEL_H
|
||||
#define PROFILESMODEL_H
|
||||
|
||||
#include "configfile.h"
|
||||
|
||||
class CProfilesModel : public QAbstractListModel
|
||||
{
|
||||
public:
|
||||
CProfilesModel(QObject *parent);
|
||||
CProfilesModel(const CProfiles &profiles, QObject *parent);
|
||||
virtual ~CProfilesModel();
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
|
||||
|
||||
CProfiles& getProfiles() { return m_profiles; }
|
||||
|
||||
bool save() const;
|
||||
|
||||
private:
|
||||
CProfiles m_profiles;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue