mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
* context menu * timer based component can fire directly * View base class (non templated) so it can use Q_OBJECT
This commit is contained in:
@@ -100,9 +100,10 @@ namespace BlackGui
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
|
||||
QObject *sender = QObject::sender();
|
||||
if (sender == this->ui->pb_ReloadAtcStationsBooked && this->getIContextNetwork())
|
||||
if (sender == this->ui->tvp_AtcStationsBooked && this->getIContextNetwork())
|
||||
{
|
||||
// trigger new read, which takes some time. A signal will be received when this is done
|
||||
this->sendStatusMessage(CStatusMessage::getInfoMessage("Requested new bookings", CStatusMessage::TypeTrafficNetwork));
|
||||
this->getIContextNetwork()->readAtcBookingsFromSource();
|
||||
}
|
||||
else
|
||||
@@ -199,7 +200,9 @@ namespace BlackGui
|
||||
if (this->currentWidget() == this->ui->tb_AtcStationsOnline)
|
||||
{
|
||||
if (this->m_timestampLastReadBookedStations.isNull())
|
||||
{
|
||||
this->ps_reloadAtcStationsBooked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -277,13 +277,6 @@
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_ReloadAtcStationsBooked">
|
||||
<property name="text">
|
||||
<string>Reload</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -16,8 +16,12 @@ namespace BlackGui
|
||||
CTimerBasedComponent::CTimerBasedComponent(const char *slot, QObject *parent) :
|
||||
QObject(parent), m_timer(nullptr)
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
this->m_timer = new QTimer(this);
|
||||
this->m_timerSingleShot = new QTimer(this);
|
||||
this->m_timerSingleShot->setSingleShot(true);
|
||||
this->connect(this->m_timer, SIGNAL(timeout()), parent, slot);
|
||||
this->connect(this->m_timerSingleShot, SIGNAL(timeout()), parent, slot);
|
||||
}
|
||||
|
||||
CTimerBasedComponent::~CTimerBasedComponent()
|
||||
@@ -38,5 +42,11 @@ namespace BlackGui
|
||||
if (!this->m_timer->isActive()) this->m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void CTimerBasedComponent::fireTimer()
|
||||
{
|
||||
Q_ASSERT(this->m_timerSingleShot);
|
||||
this->m_timerSingleShot->start(10);
|
||||
}
|
||||
}
|
||||
} // guard
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace BlackGui
|
||||
//! Timer based componenet
|
||||
class CTimerBasedComponent: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CTimerBasedComponent(const char *slot, QObject *parent);
|
||||
@@ -46,8 +48,12 @@ namespace BlackGui
|
||||
//! Stop timer
|
||||
void stopTimer() { this->setUpdateInterval(-1); }
|
||||
|
||||
//! Fire the timer straight away
|
||||
void fireTimer();
|
||||
|
||||
private:
|
||||
QTimer *m_timer;
|
||||
QTimer *m_timerSingleShot;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,9 @@ namespace BlackGui
|
||||
{
|
||||
if (BlackMisc::CProject::isDebugBuild())
|
||||
{
|
||||
menu.addAction("Test: 1k ATC online stations", this, SLOT(ps_testRequest1kAtcOnlineDummies()));
|
||||
menu.addAction("Test: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies()));
|
||||
menu.addAction(CIcons::tableSheet16(), "Test: 1k ATC online stations", this, SLOT(ps_testRequest1kAtcOnlineDummies()));
|
||||
menu.addAction(CIcons::tableSheet16(), "Test: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies()));
|
||||
menu.addSeparator();
|
||||
}
|
||||
CViewBase::customMenu(menu);
|
||||
}
|
||||
|
||||
@@ -21,33 +21,10 @@ namespace BlackGui
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent), m_contextMenu(nullptr)
|
||||
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent)
|
||||
{
|
||||
this->standardInit(new CStatusMessageListModel(this));
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
this->m_contextMenu = new QMenu(this);
|
||||
this->m_contextMenu->addAction("Clear");
|
||||
connect(this, &QTableView::customContextMenuRequested, this, &CStatusMessageView::contextMenu);
|
||||
}
|
||||
|
||||
/*
|
||||
* Message list context menu
|
||||
*/
|
||||
void CStatusMessageView::contextMenu(const QPoint &position)
|
||||
{
|
||||
// position for most widgets
|
||||
QPoint globalPosition = this->mapToGlobal(position);
|
||||
QAction *selectedItem = this->m_contextMenu->exec(globalPosition);
|
||||
if (selectedItem)
|
||||
{
|
||||
// http://forum.technical-assistance.co.uk/sndvol32exe-command-line-parameters-vt1348.html
|
||||
const QList<QAction *> actions = this->m_contextMenu->actions();
|
||||
if (selectedItem == actions.at(0))
|
||||
{
|
||||
this->clear();
|
||||
this->resizeColumnsToContents();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -27,13 +27,6 @@ namespace BlackGui
|
||||
|
||||
//! Constructor
|
||||
explicit CStatusMessageView(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QMenu *m_contextMenu;
|
||||
|
||||
private slots:
|
||||
//! Context menu for message list
|
||||
void contextMenu(const QPoint &position);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#include "blackmisc/icons.h"
|
||||
#include <QTableView>
|
||||
#include <QMenu>
|
||||
#include <QPoint>
|
||||
@@ -20,8 +21,55 @@ namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
//! List model
|
||||
template <class ModelClass> class CViewBase : public QTableView
|
||||
|
||||
//! Non templated base class, allows Q_OBJECT and signals
|
||||
class CViewBaseNonTemplate : public QTableView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Clear data
|
||||
virtual void clear() = 0;
|
||||
|
||||
signals:
|
||||
//! Ask for new data
|
||||
void requestUpdate();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CViewBaseNonTemplate(QWidget *parent) : QTableView(parent)
|
||||
{
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::ps_customMenuRequested);
|
||||
}
|
||||
|
||||
//! Method creating the menu
|
||||
//! \remarks override this method to contribute to the menu
|
||||
virtual void customMenu(QMenu &menu) const
|
||||
{
|
||||
menu.addAction(BlackMisc::CIcons::refresh16(), "Update", this, SIGNAL(requestUpdate()));
|
||||
menu.addAction(BlackMisc::CIcons::delete16(), "Clear", this, SLOT(ps_clear()));
|
||||
}
|
||||
|
||||
private slots:
|
||||
//! Custom menu was requested
|
||||
void ps_customMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu;
|
||||
this->customMenu(menu);
|
||||
if (menu.isEmpty()) { return; }
|
||||
|
||||
QPoint globalPos = this->mapToGlobal(pos);
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
||||
//! Clear the model
|
||||
virtual void ps_clear() { this->clear(); }
|
||||
|
||||
};
|
||||
|
||||
//! Base class for views
|
||||
template <class ModelClass> class CViewBase : public CViewBaseNonTemplate
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -32,8 +80,8 @@ namespace BlackGui
|
||||
//! Model
|
||||
const ModelClass *derivedModel() const { return this->m_model; }
|
||||
|
||||
//! Clear
|
||||
void clear() { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||
//! \copydoc CViewBaseNonTemplate::clear
|
||||
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||
|
||||
//! Update whole container
|
||||
template<class ContainerType> int updateContainer(const ContainerType &container, bool resize = true)
|
||||
@@ -95,16 +143,13 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ModelClass *m_model = nullptr; //!< corresponding model
|
||||
|
||||
//! Constructor
|
||||
CViewBase(QWidget *parent, ModelClass *model = nullptr) : QTableView(parent), m_model(model)
|
||||
CViewBase(QWidget *parent, ModelClass *model = nullptr) : CViewBaseNonTemplate(parent), m_model(model)
|
||||
{
|
||||
this->setSortingEnabled(true);
|
||||
if (model) { this->setModel(this->m_model); }
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBase::ps_customMenuRequested);
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
@@ -137,25 +182,6 @@ namespace BlackGui
|
||||
this->setSortIndicator();
|
||||
this->horizontalHeader()->setStretchLastSection(true);
|
||||
}
|
||||
|
||||
//! Method creating the menu
|
||||
//! \remarks override this method to contribute to the menu
|
||||
virtual void customMenu(QMenu &menu) const
|
||||
{
|
||||
Q_UNUSED(menu);
|
||||
}
|
||||
|
||||
private slots:
|
||||
//! Custom menu was requested
|
||||
void ps_customMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu;
|
||||
this->customMenu(menu);
|
||||
if (menu.isEmpty()) { return; }
|
||||
|
||||
QPoint globalPos = this->mapToGlobal(pos);
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user