Choice model settings was added
This commit is contained in:
57
viewmodels/settingsviewmodel.cpp
Normal file
57
viewmodels/settingsviewmodel.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "settingsviewmodel.h"
|
||||
|
||||
SettingsViewModel::SettingsViewModel(QObject *parent)
|
||||
: QAbstractListModel{parent}
|
||||
{
|
||||
m_items << SettingItem { tr("BeerLog service address"), "serverAddress", "text" }
|
||||
<< SettingItem { tr("Selected user id"), "selectedUserId", "choice", "users" }
|
||||
<< SettingItem { tr("Selected store"), "selectedStoreId", "choice", "stores" };
|
||||
|
||||
m_models["users"] = new BaseModel("users", this);
|
||||
m_models["stores"] = new BaseModel("stores", this);
|
||||
}
|
||||
|
||||
|
||||
int SettingsViewModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_items.count();
|
||||
}
|
||||
|
||||
QVariant SettingsViewModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
SettingItem item = m_items.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case Roles::Title: return item.title;
|
||||
case Roles::PropertyName: return item.propertyName;
|
||||
case Roles::ControlType: return item.controlType;
|
||||
case Roles::Model: return model(item.modelName);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SettingsViewModel::roleNames() const
|
||||
{
|
||||
return QHash<int, QByteArray> {
|
||||
{ Roles::Title, "title" },
|
||||
{ Roles::PropertyName, "name" },
|
||||
{ Roles::ControlType, "control" },
|
||||
{ Roles::Model, "choiceModel" }
|
||||
};
|
||||
}
|
||||
|
||||
QVariant SettingsViewModel::model(const QString &modelName) const
|
||||
{
|
||||
if (!m_models.contains(modelName)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return m_models[modelName]->items();
|
||||
}
|
||||
Reference in New Issue
Block a user