mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
As of workshop RW/KB, improved / fixed text messages
Also refs #351 * messages can be formatted with style sheet * fixed: removed command from message * added originator to command line * msg parsing now in core * using ITimestampBased for text messages and status messages * allow to resize rows to content (view base) * model / views for text messages * removed old qt stylesheets
This commit is contained in:
@@ -118,6 +118,11 @@ namespace BlackGui
|
||||
return CVariant();
|
||||
}
|
||||
|
||||
int CDefaultFormatter::alignDefault()
|
||||
{
|
||||
return alignLeftVCenter();
|
||||
}
|
||||
|
||||
CVariant CDefaultFormatter::keepStandardTypesConvertToStringOtherwise(const CVariant &inputData) const
|
||||
{
|
||||
if (static_cast<QMetaType::Type>(inputData.type()) == QMetaType::QString) { return inputData; }
|
||||
@@ -178,6 +183,12 @@ namespace BlackGui
|
||||
QTime t = dateTime.value<QTime>();
|
||||
return t.toString(m_formatString);
|
||||
}
|
||||
else if (static_cast<QMetaType::Type>(dateTime.type()) == QMetaType::Int)
|
||||
{
|
||||
//! \todo potential risk if int is not qint64
|
||||
QDateTime t = QDateTime::fromMSecsSinceEpoch(dateTime.toInt());
|
||||
return t.toString(m_formatString);
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT_X(false, "formatQVariant", "No QDate, QTime or QDateTime");
|
||||
|
||||
@@ -68,11 +68,14 @@ namespace BlackGui
|
||||
virtual BlackMisc::CVariant data(int role, const BlackMisc::CVariant &inputData) const;
|
||||
|
||||
//! Default value
|
||||
static int alignDefault() { return alignLeftVCenter(); }
|
||||
static int alignDefault();
|
||||
|
||||
//! Align left/vertically centered
|
||||
static int alignLeftVCenter() { return Qt::AlignVCenter | Qt::AlignLeft; }
|
||||
|
||||
//! Align left/vertically on top
|
||||
static int alignLeftTop() { return Qt::AlignTop | Qt::AlignLeft; }
|
||||
|
||||
//! Align centered
|
||||
static int alignCentered() { return Qt::AlignVCenter | Qt::AlignHCenter; }
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackmisc/nwserverlist.h"
|
||||
#include "blackmisc/nwuserlist.h"
|
||||
#include "blackmisc/nwclientlist.h"
|
||||
#include "blackmisc/nwtextmessagelist.h"
|
||||
#include "blackmisc/nwaircraftmappinglist.h"
|
||||
#include "blackmisc/setkeyboardhotkeylist.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
@@ -404,9 +405,12 @@ namespace BlackGui
|
||||
emit this->rowCountChanged(n, this->hasFilter());
|
||||
}
|
||||
|
||||
/*
|
||||
* Sort requested by abstract model
|
||||
*/
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::sort()
|
||||
{
|
||||
this->sort(this->getSortColumn(), this->getSortOrder());
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
@@ -421,6 +425,16 @@ namespace BlackGui
|
||||
this->updateContainerMaybeAsync(this->m_container, true);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
void CListModelBase<ObjectType, ContainerType>::truncate(int maxNumber, bool forceSort)
|
||||
{
|
||||
if (this->rowCount() <= maxNumber) { return; }
|
||||
if (forceSort) { this->sort(); } // make sure container is sorted
|
||||
ContainerType container(this->getContainer());
|
||||
container.truncate(maxNumber);
|
||||
this->updateContainerMaybeAsync(container, false);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
ContainerType CListModelBase<ObjectType, ContainerType>::sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const
|
||||
{
|
||||
@@ -452,6 +466,7 @@ namespace BlackGui
|
||||
template class CListModelBase<BlackMisc::Aviation::CAirport, BlackMisc::Aviation::CAirportList>;
|
||||
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
|
||||
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
|
||||
template class CListModelBase<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
|
||||
template class CListModelBase<BlackMisc::Simulation::CAircraftModel, BlackMisc::Simulation::CAircraftModelList>;
|
||||
template class CListModelBase<BlackMisc::Network::CAircraftMapping, BlackMisc::Network::CAircraftMappingList>;
|
||||
|
||||
@@ -162,17 +162,21 @@ namespace BlackGui
|
||||
//! Object at row position
|
||||
virtual const ObjectType &at(const QModelIndex &index) const;
|
||||
|
||||
//! Sort by given sort order \sa getSortColumn() \sa getSortOrder()
|
||||
void sort();
|
||||
|
||||
//! \copydoc QAbstractItemModel::sort()
|
||||
virtual void sort(int column, Qt::SortOrder order) override;
|
||||
|
||||
/*!
|
||||
* Sort container by given column / order. This is used by sort() but als
|
||||
* for asynchronous updates in the views
|
||||
* \param container used list
|
||||
* \param column column inder
|
||||
* \param order sort order (ascending / descending)
|
||||
* \threadsafe under normal conditions thread safe as long as the column metadata are not changed
|
||||
*/
|
||||
//! Truncate to given number
|
||||
void truncate(int maxNumber, bool forceSort = false);
|
||||
|
||||
//! Sort container by given column / order. This is used by sort() but als
|
||||
//! for asynchronous updates in the views
|
||||
//! \param container used list
|
||||
//! \param column column inder
|
||||
//! \param order sort order (ascending / descending)
|
||||
//! \threadsafe under normal conditions thread safe as long as the column metadata are not changed
|
||||
ContainerType sortContainerByColumn(const ContainerType &container, int column, Qt::SortOrder order) const;
|
||||
|
||||
//! Similar to ContainerType::push_back
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackGui
|
||||
CStatusMessageListModel::CStatusMessageListModel(QObject *parent) :
|
||||
CListModelBase<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>("ViewStatusMessageList", parent)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
||||
this->m_columns.addColumn(CColumn("time", CStatusMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
||||
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadable));
|
||||
CColumn col = CColumn("severity", CStatusMessage::IndexIcon);
|
||||
col.setSortPropertyIndex(CStatusMessage::IndexSeverityAsString);
|
||||
@@ -34,7 +34,7 @@ namespace BlackGui
|
||||
this->m_columns.addColumn(CColumn::standardString("message", CStatusMessage::IndexMessage));
|
||||
this->m_columns.addColumn(CColumn::standardString("all categories", CStatusMessage::IndexCategories));
|
||||
|
||||
this->m_sortedColumn = CStatusMessage::IndexTimestamp;
|
||||
this->m_sortedColumn = CStatusMessage::IndexUtcTimestamp;
|
||||
this->m_sortOrder = Qt::DescendingOrder;
|
||||
|
||||
// force strings for translation in resource files
|
||||
|
||||
79
src/blackgui/models/textmessagelistmodel.cpp
Normal file
79
src/blackgui/models/textmessagelistmodel.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "textmessagelistmodel.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CTextMessageListModel::CTextMessageListModel(TextMessageMode mode, QObject *parent) :
|
||||
CListModelBase("ModelTextMessageList", parent), m_textMessageMode(NotSet)
|
||||
{
|
||||
this->setTextMessageMode(mode);
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("ModelTextMessageList", "time");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTextMessageList", "from");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTextMessageList", "to");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTextMessageList", "message");
|
||||
}
|
||||
|
||||
void CTextMessageListModel::setTextMessageMode(CTextMessageListModel::TextMessageMode mode)
|
||||
{
|
||||
if (this->m_textMessageMode == mode) return;
|
||||
this->m_textMessageMode = mode;
|
||||
this->m_columns.clear();
|
||||
switch (mode)
|
||||
{
|
||||
case NotSet:
|
||||
case FromTo:
|
||||
{
|
||||
CColumn col = CColumn("type", CTextMessage::IndexIcon);
|
||||
col.setSortPropertyIndex({ CTextMessage::IndexSenderCallsign, CCallsign::IndexSuffix });
|
||||
this->m_columns.addColumn(col);
|
||||
this->m_columns.addColumn(CColumn("time", "received", CTextMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
||||
this->m_columns.addColumn(CColumn::standardString("from", { CTextMessage::IndexSenderCallsign, CCallsign::IndexCallsignString }));
|
||||
this->m_columns.addColumn(CColumn::standardString("to", CTextMessage::IndexRecipientCallsignOrFrequency));
|
||||
this->m_columns.addColumn(CColumn::standardString("message", CTextMessage::IndexMessage));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CTextMessage::IndexUtcTimestamp);
|
||||
this->m_sortOrder = Qt::DescendingOrder;
|
||||
}
|
||||
break;
|
||||
|
||||
case From:
|
||||
{
|
||||
this->m_columns.addColumn(CColumn("time", "received", CTextMessage::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
||||
this->m_columns.addColumn(CColumn::standardString("from", { CTextMessage::IndexSenderCallsign, CCallsign::IndexCallsignString }));
|
||||
this->m_columns.addColumn(CColumn::standardString("message", CTextMessage::IndexMessage));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CTextMessage::IndexUtcTimestamp);
|
||||
this->m_sortOrder = Qt::DescendingOrder;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
qFatal("Wrong mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
55
src/blackgui/models/textmessagelistmodel.h
Normal file
55
src/blackgui/models/textmessagelistmodel.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_TEXTMESSAGELISTMODEL_H
|
||||
#define BLACKGUI_TEXTMESSAGELISTMODEL_H
|
||||
|
||||
#include "blackmisc/nwtextmessagelist.h"
|
||||
#include "blackgui/models/listmodelbase.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QStandardItemModel>
|
||||
#include <QDBusConnection>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
//! ATC list model
|
||||
class CTextMessageListModel : public CListModelBase<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>
|
||||
{
|
||||
|
||||
public:
|
||||
//! What kind of stations
|
||||
enum TextMessageMode
|
||||
{
|
||||
NotSet,
|
||||
FromTo,
|
||||
From
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit CTextMessageListModel(TextMessageMode stationMode, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CTextMessageListModel() {}
|
||||
|
||||
//! Set mode
|
||||
void setTextMessageMode(TextMessageMode mode);
|
||||
|
||||
//! Mode
|
||||
TextMessageMode getTextMessageMode() const { return this->m_textMessageMode; }
|
||||
|
||||
private:
|
||||
TextMessageMode m_textMessageMode = NotSet;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user