ServerContainers qml ui started to fix
This commit is contained in:
parent
40fa2d6779
commit
542f363e92
17 changed files with 837 additions and 507 deletions
|
|
@ -1,51 +0,0 @@
|
|||
#include "all_containers_model.h"
|
||||
|
||||
AllContainersModel::AllContainersModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int AllContainersModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return amnezia::allContainers().size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> AllContainersModel::roleNames() const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name";
|
||||
roles[DescRole] = "desc";
|
||||
roles[TypeRole] = "is_vpn";
|
||||
roles[InstalledRole] = "installed";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant AllContainersModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= amnezia::allContainers().size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
DockerContainer c = amnezia::allContainers().at(index.row());
|
||||
if (role == NameRole) {
|
||||
return containerHumanNames().value(c);
|
||||
}
|
||||
if (role == DescRole) {
|
||||
return containerDescriptions().value(c);
|
||||
}
|
||||
if (role == TypeRole) {
|
||||
return isContainerVpnType(c);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void AllContainersModel::setServerData(const QJsonObject &server)
|
||||
{
|
||||
beginResetModel();
|
||||
m_serverData = server;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
58
client/ui/models/containers_model.cpp
Normal file
58
client/ui/models/containers_model.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "containers_model.h"
|
||||
|
||||
ContainersModel::ContainersModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ContainersModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return amnezia::allContainers().size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ContainersModel::roleNames() const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name_role";
|
||||
roles[DescRole] = "desc_role";
|
||||
roles[isVpnTypeRole] = "is_vpn_role";
|
||||
roles[isOtherTypeRole] = "is_other_role";
|
||||
roles[isInstalledRole] = "is_installed_role";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= amnezia::allContainers().size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
DockerContainer c = amnezia::allContainers().at(index.row());
|
||||
if (role == NameRole) {
|
||||
return containerHumanNames().value(c);
|
||||
}
|
||||
if (role == DescRole) {
|
||||
return containerDescriptions().value(c);
|
||||
}
|
||||
if (role == isVpnTypeRole) {
|
||||
return isContainerVpnType(c);
|
||||
}
|
||||
// if (role == isOtherTypeRole) {
|
||||
// return isContainerVpnType(c)
|
||||
// }
|
||||
if (role == isInstalledRole) {
|
||||
return m_settings.containers(m_selectedServerIndex).contains(c);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ContainersModel::setSelectedServerIndex(int index)
|
||||
{
|
||||
beginResetModel();
|
||||
m_selectedServerIndex = index;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,36 +1,39 @@
|
|||
#ifndef ALL_CONTAINERS_MODEL_H
|
||||
#define ALL_CONTAINERS_MODEL_H
|
||||
#ifndef CONTAINERS_MODEL_H
|
||||
#define CONTAINERS_MODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "settings.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class AllContainersModel : public QAbstractListModel
|
||||
class ContainersModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AllContainersModel(QObject *parent = nullptr);
|
||||
ContainersModel(QObject *parent = nullptr);
|
||||
public:
|
||||
enum SiteRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DescRole,
|
||||
TypeRole,
|
||||
InstalledRole
|
||||
isVpnTypeRole,
|
||||
isOtherTypeRole,
|
||||
isInstalledRole
|
||||
};
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void setServerData(const QJsonObject &server);
|
||||
void setSelectedServerIndex(int index);
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
QJsonObject m_serverData;
|
||||
int m_selectedServerIndex;
|
||||
Settings m_settings;
|
||||
};
|
||||
|
||||
#endif // ALL_CONTAINERS_MODEL_H
|
||||
#endif // CONTAINERS_MODEL_H
|
||||
65
client/ui/models/protocols_model.cpp
Normal file
65
client/ui/models/protocols_model.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "protocols_model.h"
|
||||
|
||||
ProtocolsModel::ProtocolsModel(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return amnezia::allContainers().size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name_role";
|
||||
roles[DescRole] = "desc_role";
|
||||
roles[isVpnTypeRole] = "is_vpn_role";
|
||||
roles[isOtherTypeRole] = "is_other_role";
|
||||
roles[isInstalledRole] = "is_installed_role";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= amnezia::allContainers().size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Protocol p = amnezia::allProtocols().at(index.row());
|
||||
if (role == NameRole) {
|
||||
return protocolHumanNames().value(p);
|
||||
}
|
||||
if (role == DescRole) {
|
||||
return protocolDescriptions().value(p);
|
||||
}
|
||||
if (role == isVpnTypeRole) {
|
||||
return isProtocolVpnType(p);
|
||||
}
|
||||
// if (role == isOtherTypeRole) {
|
||||
// return isContainerVpnType(c)
|
||||
// }
|
||||
if (role == isInstalledRole) {
|
||||
return protocolsForContainer(m_selectedDockerContainer).contains(p);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ProtocolsModel::setSelectedServerIndex(int index)
|
||||
{
|
||||
beginResetModel();
|
||||
m_selectedServerIndex = index;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ProtocolsModel::setSelectedDockerContainer(DockerContainer c)
|
||||
{
|
||||
beginResetModel();
|
||||
m_selectedDockerContainer = c;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
41
client/ui/models/protocols_model.h
Normal file
41
client/ui/models/protocols_model.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef PROTOCOLS_MODEL_H
|
||||
#define PROTOCOLS_MODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QJsonObject>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "settings.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
class ProtocolsModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProtocolsModel(QObject *parent = nullptr);
|
||||
public:
|
||||
enum SiteRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DescRole,
|
||||
isVpnTypeRole,
|
||||
isOtherTypeRole,
|
||||
isInstalledRole
|
||||
};
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void setSelectedServerIndex(int index);
|
||||
void setSelectedDockerContainer(DockerContainer c);
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
int m_selectedServerIndex;
|
||||
DockerContainer m_selectedDockerContainer;
|
||||
Settings m_settings;
|
||||
};
|
||||
|
||||
#endif // PROTOCOLS_MODEL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue