mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-22 21:35:40 +08:00
refs #227, view/model for client class
* model * view * and GUI component which now encapsulates the user table view
This commit is contained in:
49
src/blackgui/clientlistmodel.cpp
Normal file
49
src/blackgui/clientlistmodel.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "clientlistmodel.h"
|
||||||
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
|
#include <QMetaProperty>
|
||||||
|
#include <QBrush>
|
||||||
|
|
||||||
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
CClientListModel::CClientListModel(QObject *parent) :
|
||||||
|
CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>("ViewClientList", parent)
|
||||||
|
{
|
||||||
|
this->m_columns.addColumn(CColumn("", CClient::IndexCallsignIcon));
|
||||||
|
this->m_columns.addColumn(CColumn("callsign", CClient::IndexCallsign));
|
||||||
|
this->m_columns.addColumn(CColumn("realname", CClient::IndexRealName));
|
||||||
|
this->m_columns.addColumn(CColumn("capabilities", CClient::IndexCapabilitiesString));
|
||||||
|
this->m_columns.addColumn(CColumn("model", CClient::IndexQueriedModelString));
|
||||||
|
this->m_columns.addColumn(CColumn("host", CClient::IndexHost));
|
||||||
|
|
||||||
|
// force strings for translation in resource files
|
||||||
|
// force strings for translation in resource files
|
||||||
|
(void)QT_TRANSLATE_NOOP("ViewClientList", "callsign");
|
||||||
|
(void)QT_TRANSLATE_NOOP("ViewClientList", "realname");
|
||||||
|
(void)QT_TRANSLATE_NOOP("ViewClientList", "userid");
|
||||||
|
(void)QT_TRANSLATE_NOOP("ViewClientList", "model");
|
||||||
|
(void)QT_TRANSLATE_NOOP("ViewClientList", "host");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display icons
|
||||||
|
*/
|
||||||
|
QVariant CClientListModel::data(const QModelIndex &modelIndex, int role) const
|
||||||
|
{
|
||||||
|
// shortcut, fast check
|
||||||
|
if (role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role);
|
||||||
|
if (this->columnToPropertyIndex(modelIndex.column()) == CClient::IndexCallsignIcon)
|
||||||
|
{
|
||||||
|
if (role == Qt::DecorationRole)
|
||||||
|
{
|
||||||
|
CClient u = this->at(modelIndex);
|
||||||
|
return u.toIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CListModelBase::data(modelIndex, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/blackgui/clientlistmodel.h
Normal file
29
src/blackgui/clientlistmodel.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef BLACKGUI_CLIENTLISTMODEL_H
|
||||||
|
#define BLACKGUI_CLIENTLISTMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include "blackmisc/nwclientlist.h"
|
||||||
|
#include "blackgui/listmodelbase.h"
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Server list model
|
||||||
|
*/
|
||||||
|
class CClientListModel : public CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! \brief Constructor
|
||||||
|
explicit CClientListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
//! \brief Destructor
|
||||||
|
virtual ~CClientListModel() {}
|
||||||
|
|
||||||
|
//! \copydoc CListModelBase::data
|
||||||
|
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // guard
|
||||||
19
src/blackgui/clientview.cpp
Normal file
19
src/blackgui/clientview.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "clientview.h"
|
||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
CClientView::CClientView(QWidget *parent) : CViewBase(parent)
|
||||||
|
{
|
||||||
|
this->m_model = new CClientListModel(this);
|
||||||
|
this->setModel(this->m_model); // via QTableView
|
||||||
|
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Network::CClient::IndexRealName);
|
||||||
|
if (this->m_model->hasValidSortColumn())
|
||||||
|
this->horizontalHeader()->setSortIndicator(
|
||||||
|
this->m_model->getSortColumn(),
|
||||||
|
this->m_model->getSortOrder());
|
||||||
|
this->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/blackgui/clientview.h
Normal file
21
src/blackgui/clientview.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef BLACKGUI_CLIENTVIEW_H
|
||||||
|
#define BLACKGUI_CLIENTVIEW_H
|
||||||
|
|
||||||
|
#include "viewbase.h"
|
||||||
|
#include "clientlistmodel.h"
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Client view
|
||||||
|
*/
|
||||||
|
class CClientView : public CViewBase<CClientListModel>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
explicit CClientView(QWidget *parent = nullptr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // guard
|
||||||
43
src/blackgui/usercomponent.cpp
Normal file
43
src/blackgui/usercomponent.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include "usercomponent.h"
|
||||||
|
#include "ui_usercomponent.h"
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
CUserComponent::CUserComponent(QWidget *parent) :
|
||||||
|
QTabWidget(parent), CRuntimeBasedComponent(nullptr, false), ui(new Ui::CUserComponent), m_timer(nullptr)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
this->m_timer = new QTimer(this);
|
||||||
|
this->connect(this->m_timer, &QTimer::timeout, this, &CUserComponent::update);
|
||||||
|
}
|
||||||
|
|
||||||
|
CUserComponent::~CUserComponent()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUserComponent::update()
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->ui->tvp_AllUsers);
|
||||||
|
Q_ASSERT(this->ui->tvp_Clients);
|
||||||
|
Q_ASSERT(this->getIContextNetwork());
|
||||||
|
|
||||||
|
if (this->getIContextNetwork()->isConnected())
|
||||||
|
{
|
||||||
|
this->ui->tvp_Clients->update(this->getIContextNetwork()->getOtherClients());
|
||||||
|
this->ui->tvp_AllUsers->update(this->getIContextNetwork()->getUsers());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUserComponent::setUpdateInterval(int milliSeconds)
|
||||||
|
{
|
||||||
|
if (milliSeconds < 100)
|
||||||
|
this->m_timer->stop();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->m_timer->setInterval(milliSeconds);
|
||||||
|
if (!this->m_timer->isActive()) this->m_timer->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // guard
|
||||||
43
src/blackgui/usercomponent.h
Normal file
43
src/blackgui/usercomponent.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef BLACKGUI_USERCOMPONENT_H
|
||||||
|
#define BLACKGUI_USERCOMPONENT_H
|
||||||
|
|
||||||
|
#include "blackgui/runtimebasedcomponent.h"
|
||||||
|
#include "blackmisc/nwuserlist.h"
|
||||||
|
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
namespace Ui { class CUserComponent; }
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
//! User componenet (users, clients)
|
||||||
|
class CUserComponent : public QTabWidget, public CRuntimeBasedComponent
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
explicit CUserComponent(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~CUserComponent();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
//! Update users
|
||||||
|
void update();
|
||||||
|
|
||||||
|
//! Update time, time < 100 stops updates
|
||||||
|
void setUpdateInterval(int milliSeconds);
|
||||||
|
|
||||||
|
//! Update time
|
||||||
|
void setUpdateIntervalSeconds(int seconds) { this->setUpdateInterval(1000 * seconds); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CUserComponent *ui;
|
||||||
|
QTimer *m_timer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
92
src/blackgui/usercomponent.ui
Normal file
92
src/blackgui/usercomponent.ui
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CUserComponent</class>
|
||||||
|
<widget class="QTabWidget" name="CUserComponent">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>TabWidget</string>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tb_AllUsers">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Users</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="vl_AllUsers">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CUserView" name="tvp_AllUsers">
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tb_Clients">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Clients</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="vl_Clients">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CClientView" name="tvp_Clients">
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CUserView</class>
|
||||||
|
<extends>QTableView</extends>
|
||||||
|
<header>blackgui/userview.h</header>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CClientView</class>
|
||||||
|
<extends>QTableView</extends>
|
||||||
|
<header>blackgui/clientview.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user