mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +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());
|
Q_ASSERT(this->getIContextNetwork());
|
||||||
|
|
||||||
QObject *sender = QObject::sender();
|
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
|
// 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();
|
this->getIContextNetwork()->readAtcBookingsFromSource();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -199,7 +200,9 @@ namespace BlackGui
|
|||||||
if (this->currentWidget() == this->ui->tb_AtcStationsOnline)
|
if (this->currentWidget() == this->ui->tb_AtcStationsOnline)
|
||||||
{
|
{
|
||||||
if (this->m_timestampLastReadBookedStations.isNull())
|
if (this->m_timestampLastReadBookedStations.isNull())
|
||||||
|
{
|
||||||
this->ps_reloadAtcStationsBooked();
|
this->ps_reloadAtcStationsBooked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -277,13 +277,6 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pb_ReloadAtcStationsBooked">
|
|
||||||
<property name="text">
|
|
||||||
<string>Reload</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ namespace BlackGui
|
|||||||
CTimerBasedComponent::CTimerBasedComponent(const char *slot, QObject *parent) :
|
CTimerBasedComponent::CTimerBasedComponent(const char *slot, QObject *parent) :
|
||||||
QObject(parent), m_timer(nullptr)
|
QObject(parent), m_timer(nullptr)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(parent);
|
||||||
this->m_timer = new QTimer(this);
|
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_timer, SIGNAL(timeout()), parent, slot);
|
||||||
|
this->connect(this->m_timerSingleShot, SIGNAL(timeout()), parent, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTimerBasedComponent::~CTimerBasedComponent()
|
CTimerBasedComponent::~CTimerBasedComponent()
|
||||||
@@ -38,5 +42,11 @@ namespace BlackGui
|
|||||||
if (!this->m_timer->isActive()) this->m_timer->start();
|
if (!this->m_timer->isActive()) this->m_timer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTimerBasedComponent::fireTimer()
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->m_timerSingleShot);
|
||||||
|
this->m_timerSingleShot->start(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // guard
|
} // guard
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace BlackGui
|
|||||||
//! Timer based componenet
|
//! Timer based componenet
|
||||||
class CTimerBasedComponent: public QObject
|
class CTimerBasedComponent: public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CTimerBasedComponent(const char *slot, QObject *parent);
|
CTimerBasedComponent(const char *slot, QObject *parent);
|
||||||
@@ -46,8 +48,12 @@ namespace BlackGui
|
|||||||
//! Stop timer
|
//! Stop timer
|
||||||
void stopTimer() { this->setUpdateInterval(-1); }
|
void stopTimer() { this->setUpdateInterval(-1); }
|
||||||
|
|
||||||
|
//! Fire the timer straight away
|
||||||
|
void fireTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
|
QTimer *m_timerSingleShot;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (BlackMisc::CProject::isDebugBuild())
|
if (BlackMisc::CProject::isDebugBuild())
|
||||||
{
|
{
|
||||||
menu.addAction("Test: 1k ATC online stations", this, SLOT(ps_testRequest1kAtcOnlineDummies()));
|
menu.addAction(CIcons::tableSheet16(), "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: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies()));
|
||||||
|
menu.addSeparator();
|
||||||
}
|
}
|
||||||
CViewBase::customMenu(menu);
|
CViewBase::customMenu(menu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,33 +21,10 @@ namespace BlackGui
|
|||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent), m_contextMenu(nullptr)
|
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->standardInit(new CStatusMessageListModel(this));
|
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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -27,13 +27,6 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CStatusMessageView(QWidget *parent = nullptr);
|
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
|
//! \file
|
||||||
|
|
||||||
|
#include "blackmisc/icons.h"
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
@@ -20,8 +21,55 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
namespace Views
|
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:
|
public:
|
||||||
@@ -32,8 +80,8 @@ namespace BlackGui
|
|||||||
//! Model
|
//! Model
|
||||||
const ModelClass *derivedModel() const { return this->m_model; }
|
const ModelClass *derivedModel() const { return this->m_model; }
|
||||||
|
|
||||||
//! Clear
|
//! \copydoc CViewBaseNonTemplate::clear
|
||||||
void clear() { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||||
|
|
||||||
//! Update whole container
|
//! Update whole container
|
||||||
template<class ContainerType> int updateContainer(const ContainerType &container, bool resize = true)
|
template<class ContainerType> int updateContainer(const ContainerType &container, bool resize = true)
|
||||||
@@ -95,16 +143,13 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ModelClass *m_model = nullptr; //!< corresponding model
|
ModelClass *m_model = nullptr; //!< corresponding model
|
||||||
|
|
||||||
//! Constructor
|
//! 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);
|
this->setSortingEnabled(true);
|
||||||
if (model) { this->setModel(this->m_model); }
|
if (model) { this->setModel(this->m_model); }
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBase::ps_customMenuRequested);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
@@ -137,25 +182,6 @@ namespace BlackGui
|
|||||||
this->setSortIndicator();
|
this->setSortIndicator();
|
||||||
this->horizontalHeader()->setStretchLastSection(true);
|
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