squawk/ui/models/account.cpp

105 lines
2.0 KiB
C++
Raw Normal View History

2019-04-03 15:09:29 +00:00
#include "account.h"
Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* parentItem):
Item(account, data, parentItem),
login(data.value("login").toString()),
password(data.value("password").toString()),
server(data.value("server").toString()),
state(data.value("state").toInt())
{
}
Models::Account::~Account()
{
}
void Models::Account::setState(int p_state)
{
2019-04-03 18:15:36 +00:00
if (state != p_state) {
state = p_state;
emit changed(2);
}
2019-04-03 15:09:29 +00:00
}
QString Models::Account::getLogin() const
{
return login;
}
QString Models::Account::getPassword() const
{
return password;
}
QString Models::Account::getServer() const
{
return server;
}
int Models::Account::getState() const
{
return state;
}
void Models::Account::setLogin(const QString& p_login)
{
2019-04-03 18:15:36 +00:00
if (login != p_login) {
login = p_login;
emit changed(3);
}
2019-04-03 15:09:29 +00:00
}
void Models::Account::setPassword(const QString& p_password)
{
2019-04-03 18:15:36 +00:00
if (password != p_password) {
password = p_password;
emit changed(4);
}
2019-04-03 15:09:29 +00:00
}
void Models::Account::setServer(const QString& p_server)
{
2019-04-03 18:15:36 +00:00
if (server != p_server) {
server = p_server;
emit changed(1);
}
2019-04-03 15:09:29 +00:00
}
QVariant Models::Account::data(int column) const
{
switch (column) {
case 0:
return Item::data(column);
case 1:
return server;
case 2:
2019-04-03 18:15:36 +00:00
return Shared::ConnectionStateNames[state];
2019-04-03 15:09:29 +00:00
case 3:
return login;
case 4:
return password;
default:
return QVariant();
}
}
int Models::Account::columnCount() const
{
return 5;
}
2019-04-03 18:15:36 +00:00
void Models::Account::update(const QString& field, const QVariant& value)
{
if (field == "name") {
setName(value.toString());
} else if (field == "server") {
setServer(value.toString());
} else if (field == "login") {
setLogin(value.toString());
} else if (field == "password") {
setPassword(value.toString());
} else if (field == "state") {
setState(value.toInt());
}
}