mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 19:25:49 +08:00
Display number of table rows in tab
* countChanged event * applied in components
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
#include "dockwidgetinfoareacomponent.h"
|
#include "dockwidgetinfoareacomponent.h"
|
||||||
#include "../guiutility.h"
|
#include "../guiutility.h"
|
||||||
|
|
||||||
|
using namespace BlackGui;
|
||||||
|
using namespace BlackGui::Views;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
@@ -25,6 +28,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
||||||
|
|
||||||
|
connect(this->ui->tvp_AircraftsInRange, &CAircraftView::countChanged, this, &CAircraftComponent::ps_countChanged);
|
||||||
|
connect(this->ui->tvp_AirportsInRange, &CAircraftView::countChanged, this, &CAircraftComponent::ps_countChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftComponent::~CAircraftComponent()
|
CAircraftComponent::~CAircraftComponent()
|
||||||
@@ -92,5 +98,19 @@ namespace BlackGui
|
|||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAircraftComponent::ps_countChanged(int count)
|
||||||
|
{
|
||||||
|
Q_UNUSED(count);
|
||||||
|
int ac = this->indexOf(this->ui->tb_AircraftsInRange);
|
||||||
|
int ap = this->indexOf(this->ui->tb_AirportsInRange);
|
||||||
|
QString acs = this->tabBar()->tabText(ac);
|
||||||
|
QString aps = this->tabBar()->tabText(ap);
|
||||||
|
acs = CGuiUtility::replaceTabCountValue(acs, this->countAircrafts());
|
||||||
|
aps = CGuiUtility::replaceTabCountValue(aps, this->countAirportsInRange());
|
||||||
|
this->tabBar()->setTabText(ac, acs);
|
||||||
|
this->tabBar()->setTabText(ap, aps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ namespace BlackGui
|
|||||||
//! Info area tab bar has changed
|
//! Info area tab bar has changed
|
||||||
void ps_infoAreaTabBarChanged(int index);
|
void ps_infoAreaTabBarChanged(int index);
|
||||||
|
|
||||||
|
//! Number of elements changed
|
||||||
|
void ps_countChanged(int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CAircraftComponent *ui;
|
Ui::CAircraftComponent *ui;
|
||||||
CTimerBasedComponent *m_timerComponent;
|
CTimerBasedComponent *m_timerComponent;
|
||||||
|
|||||||
@@ -11,10 +11,12 @@
|
|||||||
|
|
||||||
#include "atcstationcomponent.h"
|
#include "atcstationcomponent.h"
|
||||||
#include "../views/atcstationview.h"
|
#include "../views/atcstationview.h"
|
||||||
|
#include "../guiutility.h"
|
||||||
#include "ui_atcstationcomponent.h"
|
#include "ui_atcstationcomponent.h"
|
||||||
#include "blackmisc/avinformationmessage.h"
|
#include "blackmisc/avinformationmessage.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
|
||||||
|
using namespace BlackGui;
|
||||||
using namespace BlackGui::Models;
|
using namespace BlackGui::Models;
|
||||||
using namespace BlackGui::Views;
|
using namespace BlackGui::Views;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -42,6 +44,7 @@ namespace BlackGui
|
|||||||
// set station mode
|
// set station mode
|
||||||
this->ui->tvp_AtcStationsOnline->setStationMode(CAtcStationListModel::StationsOnline);
|
this->ui->tvp_AtcStationsOnline->setStationMode(CAtcStationListModel::StationsOnline);
|
||||||
this->ui->tvp_AtcStationsBooked->setStationMode(CAtcStationListModel::StationsBooked);
|
this->ui->tvp_AtcStationsBooked->setStationMode(CAtcStationListModel::StationsBooked);
|
||||||
|
this->ui->tvp_AtcStationsBooked->setResizeMode(CAtcStationView::ResizingOnce);
|
||||||
|
|
||||||
// Signal / Slots
|
// Signal / Slots
|
||||||
bool connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar()));
|
bool connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar()));
|
||||||
@@ -52,7 +55,12 @@ namespace BlackGui
|
|||||||
connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected);
|
connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected);
|
||||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations);
|
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations);
|
||||||
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
|
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
|
||||||
|
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
|
||||||
|
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
|
||||||
|
|
||||||
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
|
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
|
||||||
|
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
|
||||||
|
|
||||||
connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
|
connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +232,19 @@ namespace BlackGui
|
|||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAtcStationComponent::ps_countChanged(int count)
|
||||||
|
{
|
||||||
|
Q_UNUSED(count);
|
||||||
|
int io = this->indexOf(this->ui->tb_AtcStationsOnline);
|
||||||
|
int ib = this->indexOf(this->ui->tb_AtcStationsBooked);
|
||||||
|
QString o = this->tabBar()->tabText(io);
|
||||||
|
QString b = this->tabBar()->tabText(ib);
|
||||||
|
o = CGuiUtility::replaceTabCountValue(o, this->countOnlineStations());
|
||||||
|
b = CGuiUtility::replaceTabCountValue(b, this->countBookedStations());
|
||||||
|
this->tabBar()->setTabText(io, o);
|
||||||
|
this->tabBar()->setTabText(ib, b);
|
||||||
|
}
|
||||||
|
|
||||||
void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index)
|
void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index)
|
||||||
{
|
{
|
||||||
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
|
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ namespace BlackGui
|
|||||||
//! Info area tab bar has changed
|
//! Info area tab bar has changed
|
||||||
void ps_infoAreaTabBarChanged(int index);
|
void ps_infoAreaTabBarChanged(int index);
|
||||||
|
|
||||||
|
//! Count has been changed
|
||||||
|
void ps_countChanged(int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CAtcStationComponent *ui;
|
Ui::CAtcStationComponent *ui;
|
||||||
CTimerBasedComponent *m_timerComponent;
|
CTimerBasedComponent *m_timerComponent;
|
||||||
|
|||||||
@@ -9,8 +9,12 @@
|
|||||||
|
|
||||||
#include "usercomponent.h"
|
#include "usercomponent.h"
|
||||||
#include "ui_usercomponent.h"
|
#include "ui_usercomponent.h"
|
||||||
|
#include "../guiutility.h"
|
||||||
#include "blackmisc/nwuserlist.h"
|
#include "blackmisc/nwuserlist.h"
|
||||||
|
|
||||||
|
using namespace BlackGui;
|
||||||
|
using namespace BlackGui::Views;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
@@ -23,6 +27,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
this->m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
||||||
|
|
||||||
|
connect(this->ui->tvp_AllUsers, &CUserView::countChanged, this, &CUserComponent::ps_countChanged);
|
||||||
|
connect(this->ui->tvp_Clients, &CClientView::countChanged, this, &CUserComponent::ps_countChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserComponent::~CUserComponent()
|
CUserComponent::~CUserComponent()
|
||||||
@@ -63,5 +70,19 @@ namespace BlackGui
|
|||||||
this->ui->tvp_AllUsers->updateContainer(this->getIContextNetwork()->getUsers());
|
this->ui->tvp_AllUsers->updateContainer(this->getIContextNetwork()->getUsers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} // guard
|
void CUserComponent::ps_countChanged(int count)
|
||||||
|
{
|
||||||
|
Q_UNUSED(count);
|
||||||
|
int iu = this->indexOf(this->ui->tb_AllUsers);
|
||||||
|
int ic = this->indexOf(this->ui->tb_Clients);
|
||||||
|
QString u = this->tabBar()->tabText(iu);
|
||||||
|
QString c = this->tabBar()->tabText(ic);
|
||||||
|
u = CGuiUtility::replaceTabCountValue(u, this->countUsers());
|
||||||
|
c = CGuiUtility::replaceTabCountValue(c, this->countClients());
|
||||||
|
this->tabBar()->setTabText(iu, u);
|
||||||
|
this->tabBar()->setTabText(ic, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ namespace BlackGui
|
|||||||
//! \copydoc CTimerBasedComponent::stopTimer
|
//! \copydoc CTimerBasedComponent::stopTimer
|
||||||
void stopTimer() { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->stopTimer(); }
|
void stopTimer() { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->stopTimer(); }
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
//! Number of elements changed
|
||||||
|
void ps_countChanged(int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CUserComponent *ui;
|
Ui::CUserComponent *ui;
|
||||||
CTimerBasedComponent *m_timerComponent;
|
CTimerBasedComponent *m_timerComponent;
|
||||||
|
|||||||
@@ -61,4 +61,14 @@ namespace BlackGui
|
|||||||
QPoint p = mainWindowPosition();
|
QPoint p = mainWindowPosition();
|
||||||
return (p.isNull()) ? introWindowPosition() : p;
|
return (p.isNull()) ? introWindowPosition() : p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CGuiUtility::replaceTabCountValue(const QString &oldName, int count)
|
||||||
|
{
|
||||||
|
const QString v = QString("(").append(QString::number(count)).append(")");
|
||||||
|
if (oldName.isEmpty()) {return v; }
|
||||||
|
int index = oldName.lastIndexOf('(');
|
||||||
|
if (index == 0) { return v; }
|
||||||
|
if (index < 0) { return QString(oldName).append(" ").append(v); }
|
||||||
|
return QString(oldName.left(index)).append(" ").append(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ namespace BlackGui
|
|||||||
//! During initialization, when main window position might not be set set
|
//! During initialization, when main window position might not be set set
|
||||||
static QPoint assumedMainWindowPosition();
|
static QPoint assumedMainWindowPosition();
|
||||||
|
|
||||||
|
//! Replace count in name such as "stations (4)"
|
||||||
|
static QString replaceTabCountValue(const QString &oldName, int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Constructor, use static methods only
|
//! Constructor, use static methods only
|
||||||
CGuiUtility() {}
|
CGuiUtility() {}
|
||||||
|
|||||||
@@ -92,21 +92,15 @@ namespace BlackGui
|
|||||||
if (station.getCallsign().isEmpty()) return;
|
if (station.getCallsign().isEmpty()) return;
|
||||||
if (added)
|
if (added)
|
||||||
{
|
{
|
||||||
if (this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign()))
|
bool c = this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign());
|
||||||
{
|
if (!c) { this->insert(station); }
|
||||||
this->m_container.replaceIf(&CAtcStation::getCallsign, station.getCallsign(), station);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->insert(station);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), 0, 0);
|
beginRemoveRows(QModelIndex(), 0, 0);
|
||||||
this->m_container.removeIf(&CAtcStation::getCallsign, station.getCallsign());
|
this->removeIf(&CAtcStation::getCallsign, station.getCallsign());
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
}
|
} // namespace
|
||||||
|
|||||||
@@ -127,27 +127,22 @@ namespace BlackGui
|
|||||||
template <typename ObjectType, typename ContainerType>
|
template <typename ObjectType, typename ContainerType>
|
||||||
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container, bool sort)
|
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container, bool sort)
|
||||||
{
|
{
|
||||||
// KWB remove: qDebug() will be removed soon
|
|
||||||
qDebug() << "update" << this->objectName() << "size" << container.size() << "thread:" << QThread::currentThreadId();
|
|
||||||
QTime myTimer;
|
|
||||||
|
|
||||||
// Keep sorting out of begin/end reset model
|
// Keep sorting out of begin/end reset model
|
||||||
ContainerType sortedContainer;
|
ContainerType sortedContainer;
|
||||||
|
int oldSize = this->m_container.size();
|
||||||
bool performSort = sort && container.size() > 1 && this->hasValidSortColumn();
|
bool performSort = sort && container.size() > 1 && this->hasValidSortColumn();
|
||||||
if (performSort)
|
if (performSort)
|
||||||
{
|
{
|
||||||
myTimer.start();
|
|
||||||
sortedContainer = this->sortContainerByColumn(container, this->getSortColumn(), this->m_sortOrder);
|
sortedContainer = this->sortContainerByColumn(container, this->getSortColumn(), this->m_sortOrder);
|
||||||
qDebug() << this->objectName() << "Sort performed ms:" << myTimer.restart() << "thread:" << QThread::currentThreadId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->beginResetModel();
|
this->beginResetModel();
|
||||||
this->m_container = performSort ? sortedContainer : container;
|
this->m_container = performSort ? sortedContainer : container;
|
||||||
this->endResetModel();
|
this->endResetModel();
|
||||||
|
|
||||||
// TODO: KWB remove
|
int newSize = this->m_container.size();
|
||||||
qDebug() << this->objectName() << "Reset performed ms:" << myTimer.restart() << "objects:" << this->m_container.size() << "thread:" << QThread::currentThreadId();
|
if (oldSize != newSize) { rowCountChanged(newSize); }
|
||||||
return this->m_container.size();
|
return newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -223,6 +218,7 @@ namespace BlackGui
|
|||||||
beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size());
|
beginInsertRows(QModelIndex(), this->m_container.size(), this->m_container.size());
|
||||||
this->m_container.push_back(object);
|
this->m_container.push_back(object);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
emit rowCountChanged(this->m_container.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -234,6 +230,8 @@ namespace BlackGui
|
|||||||
beginInsertRows(QModelIndex(), 0, 0);
|
beginInsertRows(QModelIndex(), 0, 0);
|
||||||
this->m_container.insert(this->m_container.begin(), object);
|
this->m_container.insert(this->m_container.begin(), object);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
int newSize = this->m_container.size();
|
||||||
|
emit rowCountChanged(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -242,9 +240,12 @@ namespace BlackGui
|
|||||||
template <typename ObjectType, typename ContainerType>
|
template <typename ObjectType, typename ContainerType>
|
||||||
void CListModelBase<ObjectType, ContainerType>::remove(const ObjectType &object)
|
void CListModelBase<ObjectType, ContainerType>::remove(const ObjectType &object)
|
||||||
{
|
{
|
||||||
|
int oldSize = this->m_container.size();
|
||||||
beginRemoveRows(QModelIndex(), 0, 0);
|
beginRemoveRows(QModelIndex(), 0, 0);
|
||||||
this->m_container.remove(object);
|
this->m_container.remove(object);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
int newSize = this->m_container.size();
|
||||||
|
if (oldSize != newSize) { emit rowCountChanged(newSize); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -252,9 +253,11 @@ namespace BlackGui
|
|||||||
*/
|
*/
|
||||||
template <typename ObjectType, typename ContainerType> void CListModelBase<ObjectType, ContainerType>::clear()
|
template <typename ObjectType, typename ContainerType> void CListModelBase<ObjectType, ContainerType>::clear()
|
||||||
{
|
{
|
||||||
|
int oldSize = this->m_container.size();
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
this->m_container.clear();
|
this->m_container.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
if (oldSize > 0) { emit rowCountChanged(0);}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ namespace BlackGui
|
|||||||
//! Asynchronous update finished
|
//! Asynchronous update finished
|
||||||
void asyncUpdateFinished();
|
void asyncUpdateFinished();
|
||||||
|
|
||||||
|
//! Number of elements changed
|
||||||
|
void rowCountChanged(int count);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
//! Helper method with template free signature
|
//! Helper method with template free signature
|
||||||
//! \param variant container is transferred in variant
|
//! \param variant container is transferred in variant
|
||||||
@@ -113,7 +116,6 @@ namespace BlackGui
|
|||||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* List model
|
* List model
|
||||||
*/
|
*/
|
||||||
@@ -182,6 +184,15 @@ namespace BlackGui
|
|||||||
//! Remove object
|
//! Remove object
|
||||||
virtual void remove(const ObjectType &object);
|
virtual void remove(const ObjectType &object);
|
||||||
|
|
||||||
|
//! \copydoc ContainerBase::removeIf
|
||||||
|
template <class K0, class V0, class... KeysValues>
|
||||||
|
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
|
||||||
|
{
|
||||||
|
int c = m_container.removeIf(BlackMisc::Predicates::MemberEqual(k0, v0, keysValues...));
|
||||||
|
if (c > 0) { emit rowCountChanged(this->rowCount());}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
//! Clear the list
|
//! Clear the list
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ namespace BlackGui
|
|||||||
//! Asynchronous update finished
|
//! Asynchronous update finished
|
||||||
void asyncUpdateFinished();
|
void asyncUpdateFinished();
|
||||||
|
|
||||||
|
//! Number of elements changed
|
||||||
|
void countChanged(int count);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Resize to contents, strategy depends on container size
|
//! Resize to contents, strategy depends on container size
|
||||||
virtual void resizeToContents();
|
virtual void resizeToContents();
|
||||||
|
|||||||
Reference in New Issue
Block a user