From 38edd056183569b562dd363825e415da44d36801 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 5 Mar 2016 12:35:32 +0100 Subject: [PATCH] Added: Profiles model class --- .../ryzom_installer/src/profilesmodel.cpp | 48 +++++++++++++++++++ .../ryzom_installer/src/profilesmodel.h | 26 ++++++++++ 2 files changed, 74 insertions(+) create mode 100644 code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp create mode 100644 code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp new file mode 100644 index 000000000..c64c9fb0f --- /dev/null +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp @@ -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; +} diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h new file mode 100644 index 000000000..78d0e61bf --- /dev/null +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h @@ -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