Raw FSD message component and dialog

Maniphest Tasks: T222
This commit is contained in:
Roland Winklmeier
2018-01-22 14:19:41 +01:00
parent 704068d299
commit 7c903001d5
12 changed files with 503 additions and 15 deletions

View File

@@ -34,6 +34,7 @@
#include <Qt>
#include <QtGlobal>
#include <QDesktopServices>
#include <QDateTime>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;

View File

@@ -6,17 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>314</width>
<width>360</width>
<height>590</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="vl_InternalsComponent">
<property name="spacing">
<number>2</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>2</number>
</property>
@@ -29,10 +26,10 @@
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<item row="0" column="0">
<widget class="QTabWidget" name="tw_Internals">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tb_Debug">
<attribute name="title">
@@ -579,6 +576,35 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_RawFsdMessages">
<attribute name="title">
<string>FSD Messages</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Components::CRawFsdMessagesComponent" name="comp_RawFsdMessages">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@@ -596,6 +622,12 @@
<header>blackgui/components/remoteaircraftselector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CRawFsdMessagesComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/rawfsdmessagescomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../blackmisc/blackmisc.qrc"/>

View File

@@ -0,0 +1,111 @@
/* Copyright (C) 2018
* 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 "ui_rawfsdmessagescomponent.h"
#include "blackgui/components/rawfsdmessagescomponent.h"
#include "blackgui/guiapplication.h"
#include "blackcore/context/contextnetwork.h"
#include "blackmisc/directoryutils.h"
#include <QFileDialog>
#include <QDir>
#include <QtGlobal>
using namespace BlackMisc;
using namespace BlackMisc::Network;
using namespace BlackCore;
using namespace BlackCore::Vatsim;
namespace BlackGui
{
namespace Components
{
CRawFsdMessagesComponent::CRawFsdMessagesComponent(QWidget *parent) :
QFrame(parent), ui(new Ui::CRawFsdMessagesComponent)
{
ui->setupUi(this);
ui->cb_FileWritingMode->addItem(QApplication::translate("CRawFsdMessagesComponent", "Truncate", nullptr), QVariant::fromValue(CRawFsdMessageSettings::Truncate));
ui->cb_FileWritingMode->addItem(QApplication::translate("CRawFsdMessagesComponent", "Append", nullptr), QVariant::fromValue(CRawFsdMessageSettings::Append));
ui->cb_FileWritingMode->addItem(QApplication::translate("CRawFsdMessagesComponent", "Timestamped", nullptr), QVariant::fromValue(CRawFsdMessageSettings::Timestamped));
QMetaObject::Connection c = sGui->getIContextNetwork()->connectRawFsdMessageSignal(this, std::bind(&CRawFsdMessagesComponent::addFsdMessage, this, std::placeholders::_1));
if (!c)
{
ui->cb_EnableFileWriting->setEnabled(false);
ui->lw_RawFsdMessages->addItem(QStringLiteral("Could not connect to raw FSD message."));
ui->lw_RawFsdMessages->addItem(QStringLiteral("This is most likely because core is not running in this process."));
ui->lw_RawFsdMessages->addItem(QStringLiteral("Open this component again from the process running core."));
}
else
{
m_signalConnections.append(c);
readSettings();
connect(ui->cb_EnableFileWriting, &QCheckBox::toggled, this, &CRawFsdMessagesComponent::changeWritingToFile);
connect(ui->pb_SelectFileDir, &QPushButton::clicked, this, &CRawFsdMessagesComponent::selectFileDir);
connect(ui->cb_FileWritingMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CRawFsdMessagesComponent::changeFileWritingMode);
}
}
CRawFsdMessagesComponent::~CRawFsdMessagesComponent()
{ }
void CRawFsdMessagesComponent::changeWritingToFile(bool enable)
{
ui->le_FileDir->setEnabled(enable);
ui->pb_SelectFileDir->setEnabled(enable);
ui->cb_FileWritingMode->setEnabled(enable);
m_setting.setProperty(Vatsim::CRawFsdMessageSettings::IndexWriteEnabled, CVariant::fromValue(enable));
}
void CRawFsdMessagesComponent::selectFileDir()
{
QString fileDir = ui->le_FileDir->text();
fileDir = QFileDialog::getExistingDirectory(this, tr("Select File Directory"), fileDir);
if (fileDir.isEmpty()) { return; }
ui->le_FileDir->setText(fileDir);
m_setting.setProperty(Vatsim::CRawFsdMessageSettings::IndexFileDir, CVariant::fromValue(fileDir));
}
void CRawFsdMessagesComponent::changeFileWritingMode()
{
CRawFsdMessageSettings::FileWriteMode mode = ui->cb_FileWritingMode->currentData().value<CRawFsdMessageSettings::FileWriteMode>();
m_setting.setProperty(Vatsim::CRawFsdMessageSettings::IndexFileWriteMode, CVariant::fromValue(mode));
}
void CRawFsdMessagesComponent::setFileWritingModeFromSettings(CRawFsdMessageSettings::FileWriteMode mode)
{
ui->cb_FileWritingMode->setCurrentIndex(static_cast<int>(mode));
}
void CRawFsdMessagesComponent::addFsdMessage(const CRawFsdMessage &rawFsdMessage)
{
ui->lw_RawFsdMessages->addItem(rawFsdMessage.toQString());
ui->lw_RawFsdMessages->scrollToBottom();
while (ui->lw_RawFsdMessages->count() > 100)
{
QListWidgetItem *item = ui->lw_RawFsdMessages->takeItem(0);
delete item;
}
}
void CRawFsdMessagesComponent::readSettings()
{
const Vatsim::CRawFsdMessageSettings setting = m_setting.get();
ui->le_FileDir->setText(setting.getFileDir());
const bool enable = setting.isFileWritingEnabled();
ui->cb_EnableFileWriting->setChecked(enable);
ui->le_FileDir->setEnabled(enable);
ui->pb_SelectFileDir->setEnabled(enable);
ui->cb_FileWritingMode->setEnabled(enable);
const CRawFsdMessageSettings::FileWriteMode mode = setting.getFileWriteMode();
ui->cb_FileWritingMode->setCurrentIndex(static_cast<int>(mode));
}
}
} // namespace

View File

@@ -0,0 +1,58 @@
/* Copyright (C) 2018
* 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_RAWFSDMESSAGESCOMPONENT_H
#define BLACKGUI_RAWFSDMESSAGESCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackcore/vatsim/vatsimsettings.h"
#include "blackmisc/network/rawfsdmessage.h"
#include "blackmisc/connectionguard.h"
#include <QFrame>
class QAction;
class QPoint;
class QWidget;
namespace Ui { class CRawFsdMessagesComponent; }
namespace BlackGui
{
namespace Components
{
//! GUI displaying raw FSD messages
class BLACKGUI_EXPORT CRawFsdMessagesComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CRawFsdMessagesComponent(QWidget *parent = nullptr);
//! Destructor
virtual ~CRawFsdMessagesComponent();
private:
void changeWritingToFile(bool enable);
void selectFileDir();
void changeFileWritingMode();
void setFileWritingModeFromSettings(BlackCore::Vatsim::CRawFsdMessageSettings::FileWriteMode mode);
void addFsdMessage(const BlackMisc::Network::CRawFsdMessage &rawFsdMessage);
void readSettings();
BlackMisc::CSetting<BlackCore::Vatsim::TRawFsdMessageSetting> m_setting { this };
QScopedPointer<Ui::CRawFsdMessagesComponent> ui;
BlackMisc::CConnectionGuard m_signalConnections; //!< connected signal/slots
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CRawFsdMessagesComponent</class>
<widget class="QFrame" name="CRawFsdMessagesComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>427</width>
<height>516</height>
</rect>
</property>
<property name="windowTitle">
<string>Log component</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<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 row="0" column="0">
<widget class="QListWidget" name="lw_RawFsdMessages">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="gb_WriteToFile">
<property name="title">
<string>Write to File</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="0">
<widget class="QLabel" name="lbl_FileDir">
<property name="text">
<string>Directory:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cb_FileWritingMode">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_FileWriteMode">
<property name="text">
<string>Write Mode</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="cb_EnableFileWriting">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_FileDir">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="pb_SelectFileDir">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Set</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 2017
* 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 "rawfsdmessagesdialog.h"
#include "ui_rawfsdmessagesdialog.h"
namespace BlackGui
{
namespace Components
{
CRawFsdMessagesDialog::CRawFsdMessagesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CRawFsdMessagesDialog)
{
ui->setupUi(this);
}
CRawFsdMessagesDialog::~CRawFsdMessagesDialog()
{ }
} // ns
} // ns

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 2018
* 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_COMPONENTS_RAWFSDMESSAGESDIALOG_H
#define BLACKGUI_COMPONENTS_RAWFSDMESSAGESDIALOG_H
#include "blackgui/blackguiexport.h"
#include "blackgui/components/rawfsdmessagescomponent.h"
#include <QDialog>
#include <QScopedPointer>
namespace Ui { class CRawFsdMessagesDialog; }
namespace BlackGui
{
namespace Components
{
//! CRawFsdMessageComponent as dialog
class BLACKGUI_EXPORT CRawFsdMessagesDialog : public QDialog
{
Q_OBJECT
public:
//! Constructor
explicit CRawFsdMessagesDialog(QWidget *parent = nullptr);
//! Destructor
virtual ~CRawFsdMessagesDialog();
private:
QScopedPointer<Ui::CRawFsdMessagesDialog> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CRawFsdMessagesDialog</class>
<widget class="QDialog" name="CRawFsdMessagesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>463</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>425</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>FSD Messages</string>
</property>
<layout class="QVBoxLayout" name="vl_RawFsdMessagesDialog">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="BlackGui::Components::CRawFsdMessagesComponent" name="comp_RawFsdMessages">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CRawFsdMessagesComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/rawfsdmessagescomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>