forked from blue/squawk
Reformating, adding accounts ui dummy
This commit is contained in:
parent
de36fe2a4e
commit
6823b41f24
16 changed files with 551 additions and 31 deletions
77
ui/models/accounts.cpp
Normal file
77
ui/models/accounts.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include "accounts.h"
|
||||
|
||||
std::deque<QString> Models::Accounts::columns = {
|
||||
"name",
|
||||
"server",
|
||||
"state"
|
||||
};
|
||||
|
||||
Models::Accounts::Accounts(QObject* parent):
|
||||
QAbstractTableModel(parent),
|
||||
accs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Models::Accounts::~Accounts()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::data ( const QModelIndex& index, int role ) const
|
||||
{
|
||||
QVariant answer;
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
const Account& acc = accs[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
answer = acc.name;
|
||||
break;
|
||||
case 1:
|
||||
answer = acc.server;
|
||||
break;
|
||||
case 2:
|
||||
answer = acc.state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
int Models::Accounts::columnCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
return columns.size();
|
||||
}
|
||||
|
||||
int Models::Accounts::rowCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
return accs.size();
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
return columns[section];
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
void Models::Accounts::addAccount(const QMap<QString, QVariant>& map)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), accs.size(), accs.size());
|
||||
accs.push_back({
|
||||
map.value("name").toString(),
|
||||
map.value("server").toString(),
|
||||
map.value("login").toString(),
|
||||
map.value("password").toString(),
|
||||
map.value("state").toInt()
|
||||
});
|
||||
endInsertRows();
|
||||
}
|
43
ui/models/accounts.h
Normal file
43
ui/models/accounts.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef MODELS_ACCOUNTS_H
|
||||
#define MODELS_ACCOUNTS_H
|
||||
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <deque>
|
||||
|
||||
namespace Models
|
||||
{
|
||||
struct Account;
|
||||
|
||||
class Accounts : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Accounts(QObject* parent = 0);
|
||||
~Accounts();
|
||||
|
||||
void addAccount(const QMap<QString, QVariant>& map);
|
||||
|
||||
|
||||
QVariant data ( const QModelIndex& index, int role ) const override;
|
||||
int columnCount ( const QModelIndex& parent ) const override;
|
||||
int rowCount ( const QModelIndex& parent ) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
private:
|
||||
std::deque<Account> accs;
|
||||
|
||||
static std::deque<QString> columns;
|
||||
|
||||
};
|
||||
|
||||
struct Account {
|
||||
QString name;
|
||||
QString server;
|
||||
QString login;
|
||||
QString password;
|
||||
int state;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MODELS_ACCOUNT_H
|
Loading…
Add table
Add a link
Reference in a new issue