Reformating, adding accounts ui dummy
This commit is contained in:
parent
de36fe2a4e
commit
6823b41f24
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
Account::Account(const QString& p_jid, const QString& p_password, QObject* parent):
|
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, QObject* parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
jid(p_jid),
|
name(p_name),
|
||||||
|
login(p_login),
|
||||||
|
server(p_server),
|
||||||
password(p_password),
|
password(p_password),
|
||||||
client()
|
client()
|
||||||
{
|
{
|
||||||
|
@ -11,11 +11,13 @@ namespace Core
|
|||||||
class Account : public QObject
|
class Account : public QObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Account(const QString& p_jid, const QString& p_password, QObject* parent = 0);
|
Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, QObject* parent = 0);
|
||||||
~Account();
|
~Account();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString jid;
|
QString name;
|
||||||
|
QString login;
|
||||||
|
QString server;
|
||||||
QString password;
|
QString password;
|
||||||
QXmppClient client;
|
QXmppClient client;
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,47 @@
|
|||||||
#include "squawk.h"
|
#include "squawk.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace Core;
|
Core::Squawk::Squawk(QObject* parent):
|
||||||
|
|
||||||
Squawk::Squawk(QObject* parent):
|
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
accounts()
|
accounts()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Squawk::~Squawk()
|
Core::Squawk::~Squawk()
|
||||||
{
|
{
|
||||||
|
Accounts::const_iterator itr = accounts.begin();
|
||||||
|
Accounts::const_iterator end = accounts.end();
|
||||||
|
for (; itr != end; ++itr) {
|
||||||
|
(*itr)->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::Squawk::start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::Squawk::newAccountRequest(const QMap<QString, QVariant>& map)
|
||||||
|
{
|
||||||
|
QString name = map.value("name").toString();
|
||||||
|
QString login = map.value("login").toString();
|
||||||
|
QString server = map.value("server").toString();
|
||||||
|
QString password = map.value("password").toString();
|
||||||
|
|
||||||
|
addAccount(login, server, password, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name)
|
||||||
|
{
|
||||||
|
Account* acc = new Account(login, server, password, name);
|
||||||
|
accounts.push_back(acc);
|
||||||
|
|
||||||
|
QMap<QString, QVariant> map = {
|
||||||
|
{"login", login},
|
||||||
|
{"server", server},
|
||||||
|
{"name", name},
|
||||||
|
{"password", password},
|
||||||
|
{"state", 0}
|
||||||
|
};
|
||||||
|
emit newAccount(map);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#define CORE_SQUAWK_H
|
#define CORE_SQUAWK_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QMap>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
#include "account.h"
|
#include "account.h"
|
||||||
@ -16,10 +19,20 @@ public:
|
|||||||
Squawk(QObject* parent = 0);
|
Squawk(QObject* parent = 0);
|
||||||
~Squawk();
|
~Squawk();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void newAccount(const QMap<QString, QVariant>&);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void start();
|
||||||
|
void newAccountRequest(const QMap<QString, QVariant>& map);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<Account> Accounts;
|
typedef std::deque<Account*> Accounts;
|
||||||
|
|
||||||
Accounts accounts;
|
Accounts accounts;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
6
main.cpp
6
main.cpp
@ -15,6 +15,12 @@ int main(int argc, char *argv[])
|
|||||||
squawk->moveToThread(coreThread);
|
squawk->moveToThread(coreThread);
|
||||||
|
|
||||||
QObject::connect(coreThread, SIGNAL(finished()), squawk, SLOT(deleteLater()));
|
QObject::connect(coreThread, SIGNAL(finished()), squawk, SLOT(deleteLater()));
|
||||||
|
QObject::connect(coreThread, SIGNAL(started()), squawk, SLOT(start()));
|
||||||
|
|
||||||
|
QObject::connect(&w, SIGNAL(newAccountRequest(const QMap<QString, QVariant>&)), squawk, SLOT(newAccountRequest(const QMap<QString, QVariant>&)));
|
||||||
|
|
||||||
|
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
|
||||||
|
|
||||||
//QObject::connect(this, &Controller::operate, worker, &Worker::doWork);
|
//QObject::connect(this, &Controller::operate, worker, &Worker::doWork);
|
||||||
//QObject::connect(worker, &Worker::resultReady, this, &Controller::handleResults);
|
//QObject::connect(worker, &Worker::resultReady, this, &Controller::handleResults);
|
||||||
coreThread->start();
|
coreThread->start();
|
||||||
|
@ -12,6 +12,8 @@ find_package(Qt5Widgets CONFIG REQUIRED)
|
|||||||
set(squawkUI_SRC
|
set(squawkUI_SRC
|
||||||
squawk.cpp
|
squawk.cpp
|
||||||
accounts.cpp
|
accounts.cpp
|
||||||
|
account.cpp
|
||||||
|
models/accounts.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Tell CMake to create the helloworld executable
|
# Tell CMake to create the helloworld executable
|
||||||
|
23
ui/account.cpp
Normal file
23
ui/account.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "account.h"
|
||||||
|
#include "ui_account.h"
|
||||||
|
|
||||||
|
Account::Account()
|
||||||
|
: m_ui ( new Ui::Account )
|
||||||
|
{
|
||||||
|
m_ui->setupUi ( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
Account::~Account()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QVariant> Account::value() const
|
||||||
|
{
|
||||||
|
QMap<QString, QVariant> map;
|
||||||
|
map["login"] = m_ui->login->text();
|
||||||
|
map["password"] = m_ui->password->text();
|
||||||
|
map["server"] = m_ui->server->text();
|
||||||
|
map["name"] = m_ui->name->text();
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
29
ui/account.h
Normal file
29
ui/account.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef ACCOUNT_H
|
||||||
|
#define ACCOUNT_H
|
||||||
|
|
||||||
|
#include <QScopedPointer>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class Account;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Account : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Account();
|
||||||
|
~Account();
|
||||||
|
|
||||||
|
QMap<QString, QVariant> value() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer<Ui::Account> m_ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACCOUNT_H
|
154
ui/account.ui
Normal file
154
ui/account.ui
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Account</class>
|
||||||
|
<widget class="QDialog" name="Account">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>395</width>
|
||||||
|
<height>272</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Account</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<property name="horizontalSpacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="verticalSpacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="login">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Your account login</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Server</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="server">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>A server address of your account. Like 404.city or macaw.me</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Login</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Password</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLineEdit" name="password">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Password of your account</string>
|
||||||
|
</property>
|
||||||
|
<property name="inputMask">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="name">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Just a name how would you call this account, doesn't affect anything</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Account</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Account</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -1,10 +1,43 @@
|
|||||||
#include "accounts.h"
|
#include "accounts.h"
|
||||||
#include "ui_accounts.h"
|
#include "ui_accounts.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
Accounts::Accounts(QWidget *parent) :
|
Accounts::Accounts(QWidget *parent) :
|
||||||
m_ui(new Ui::Accounts)
|
m_ui(new Ui::Accounts),
|
||||||
|
tableModel()
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(m_ui->addButton, SIGNAL(clicked(bool)), this, SLOT(onAddButton(bool)));
|
||||||
|
m_ui->tableView->setModel(&tableModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Accounts::~Accounts() = default;
|
Accounts::~Accounts() = default;
|
||||||
|
|
||||||
|
void Accounts::onAddButton(bool clicked)
|
||||||
|
{
|
||||||
|
Account* acc = new Account();
|
||||||
|
connect(acc, SIGNAL(accepted()), this, SLOT(onAccountAccepted()));
|
||||||
|
connect(acc, SIGNAL(rejected()), this, SLOT(onAccountRejected()));
|
||||||
|
acc->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Accounts::onAccountAccepted()
|
||||||
|
{
|
||||||
|
Account* acc = static_cast<Account*>(sender());
|
||||||
|
QMap<QString, QVariant> map = acc->value();
|
||||||
|
|
||||||
|
emit newAccount(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Accounts::onAccountRejected()
|
||||||
|
{
|
||||||
|
Account* acc = static_cast<Account*>(sender());
|
||||||
|
acc->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Accounts::addAccount(const QMap<QString, QVariant>& map)
|
||||||
|
{
|
||||||
|
tableModel.addAccount(map);
|
||||||
|
}
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
#include "account.h"
|
||||||
|
#include "models/accounts.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class Accounts;
|
class Accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo write docs
|
|
||||||
*/
|
|
||||||
class Accounts : public QWidget
|
class Accounts : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -19,8 +19,19 @@ public:
|
|||||||
explicit Accounts(QWidget *parent = nullptr);
|
explicit Accounts(QWidget *parent = nullptr);
|
||||||
~Accounts() override;
|
~Accounts() override;
|
||||||
|
|
||||||
|
void addAccount(const QMap<QString, QVariant>&);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void newAccount(const QMap<QString, QVariant>&);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onAddButton(bool clicked = 0);
|
||||||
|
void onAccountAccepted();
|
||||||
|
void onAccountRejected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::Accounts> m_ui;
|
QScopedPointer<Ui::Accounts> m_ui;
|
||||||
|
Models::Accounts tableModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACCOUNTS_H
|
#endif // ACCOUNTS_H
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>768</width>
|
<width>539</width>
|
||||||
<height>235</height>
|
<height>249</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -15,20 +15,71 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="deleteButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" rowspan="8">
|
||||||
|
<widget class="QTableView" name="tableView">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<property name="showGrid">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="gridStyle">
|
||||||
|
<enum>Qt::SolidLine</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderHighlightSections">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QPushButton" name="addButton">
|
<widget class="QPushButton" name="addButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -38,12 +89,25 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QPushButton" name="editButton">
|
<widget class="QPushButton" name="editButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit</string>
|
<string>Edit</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="5" column="1">
|
||||||
|
<widget class="QPushButton" name="changePassword">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Change password</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="1">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -56,16 +120,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="6" column="1">
|
||||||
<widget class="QPushButton" name="deleteButton">
|
<widget class="QPushButton" name="connect">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Delete</string>
|
<string>Connect</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" rowspan="4">
|
|
||||||
<widget class="QTableView" name="tableView"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
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
|
@ -4,7 +4,8 @@
|
|||||||
Squawk::Squawk(QWidget *parent) :
|
Squawk::Squawk(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
m_ui(new Ui::Squawk),
|
m_ui(new Ui::Squawk),
|
||||||
accounts(0)
|
accounts(0),
|
||||||
|
accountsCache()
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
@ -21,9 +22,20 @@ void Squawk::onAccounts()
|
|||||||
accounts = new Accounts(this);
|
accounts = new Accounts(this);
|
||||||
accounts->setAttribute(Qt::WA_DeleteOnClose);
|
accounts->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(accounts, SIGNAL(destroyed(QObject*)), this, SLOT(onAccountsClosed(QObject*)));
|
connect(accounts, SIGNAL(destroyed(QObject*)), this, SLOT(onAccountsClosed(QObject*)));
|
||||||
|
connect(accounts, SIGNAL(newAccount(const QMap<QString, QVariant>&)), this, SIGNAL(newAccountRequest(const QMap<QString, QVariant>&)));
|
||||||
|
|
||||||
|
AC::const_iterator itr = accountsCache.begin();
|
||||||
|
AC::const_iterator end = accountsCache.end();
|
||||||
|
|
||||||
|
for (; itr != end; ++itr) {
|
||||||
|
accounts->addAccount(*itr);
|
||||||
|
}
|
||||||
|
|
||||||
accounts->show();
|
accounts->show();
|
||||||
} else {
|
} else {
|
||||||
accounts->focusWidget();
|
accounts->show();
|
||||||
|
accounts->raise();
|
||||||
|
accounts->activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,3 +53,11 @@ void Squawk::onAccountsClosed(QObject* parent)
|
|||||||
{
|
{
|
||||||
accounts = 0;
|
accounts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Squawk::newAccount(const QMap<QString, QVariant>& account)
|
||||||
|
{
|
||||||
|
accountsCache.push_back(account);
|
||||||
|
if (accounts != 0) {
|
||||||
|
accounts->addAccount(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
11
ui/squawk.h
11
ui/squawk.h
@ -4,6 +4,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
#include "accounts.h"
|
#include "accounts.h"
|
||||||
|
|
||||||
@ -18,11 +19,19 @@ class Squawk : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit Squawk(QWidget *parent = nullptr);
|
explicit Squawk(QWidget *parent = nullptr);
|
||||||
~Squawk() override;
|
~Squawk() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void newAccountRequest(const QMap<QString, QVariant>&);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void newAccount(const QMap<QString, QVariant>& account);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef std::deque<QMap<QString, QVariant>> AC;
|
||||||
QScopedPointer<Ui::Squawk> m_ui;
|
QScopedPointer<Ui::Squawk> m_ui;
|
||||||
|
|
||||||
Accounts* accounts;
|
Accounts* accounts;
|
||||||
|
AC accountsCache;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent * event) override;
|
void closeEvent(QCloseEvent * event) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user