refs #535, stash componet

* allow to assign livery/ICAO to selected objects
* allow access to corresponding mapping component
This commit is contained in:
Klaus Basan
2015-12-13 19:59:48 +01:00
parent a7fc01ecff
commit 2c84c51a93
5 changed files with 248 additions and 31 deletions

View File

@@ -13,7 +13,7 @@
#include "blackmisc/simulation/fscommon/aircraftcfgparser.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/project.h"
#include <QShortcut>
using namespace BlackCore;
using namespace BlackMisc;
@@ -34,6 +34,7 @@ namespace BlackGui
ui(new Ui::CDbMappingComponent)
{
ui->setupUi(this);
this->ui->comp_StashAircraft->setMappingComponent(this);
this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
@@ -41,6 +42,7 @@ namespace BlackGui
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged);
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
@@ -78,7 +80,10 @@ namespace BlackGui
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(m_cachedVPilotModels.get());
const CAircraftModelList cachedModels(m_cachedVPilotModels.get());
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(cachedModels);
int noModels = cachedModels.size();
CLogMessage(this).info("%1 cached vPilot models loaded") << noModels;
}
this->m_vPilot1stInit = false;
this->ui->tab_VPilot->setEnabled(withVPilotRights);
@@ -123,6 +128,7 @@ namespace BlackGui
this->ui->editor_Livery->setProvider(provider);
this->ui->editor_Distributor->setProvider(provider);
this->ui->editor_AircraftIcao->setProvider(provider);
this->ui->comp_StashAircraft->setProvider(provider);
}
void CDbMappingComponent::gracefulShutdown()
@@ -256,25 +262,15 @@ namespace BlackGui
{
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(models);
}
QTime t;
t.start();
m_cachedVPilotModels.set(models);
qint64 e = t.elapsed();
qDebug() << e;
CLogMessage(this).info("Written %1 vPilot rules to cache") << models.size();
/**
t.start();
QString x = models.toJsonString();
e = t.elapsed();
t.start();
CAircraftModelList ml;
ml.convertFromJson(x);
e = t.elapsed();
t.start();
**/
CStatusMessage msg = m_cachedVPilotModels.set(models);
if (msg.isWarningOrAbove())
{
CLogMessage(this).preformatted(msg);
}
else
{
CLogMessage(this).info("Written %1 vPilot rules to cache") << models.size();
}
}
else
{
@@ -283,6 +279,23 @@ namespace BlackGui
this->ui->tvp_OwnAircraftModels->hideLoadIndicator();
}
void CDbMappingComponent::ps_onStashedModelsChanged()
{
bool hlvp = this->ui->tvp_AircraftModelsForVPilot->derivedModel()->highlightGivenModelStrings();
bool hlom = this->ui->tvp_OwnAircraftModels->derivedModel()->highlightGivenModelStrings();
bool highlight = hlom || hlvp;
if (!highlight) { return; }
const QStringList stashedModels(this->ui->comp_StashAircraft->getStashedModelStrings());
if (hlvp)
{
this->ui->tvp_AircraftModelsForVPilot->derivedModel()->setHighlightModelsStrings(stashedModels);
}
if (hlom)
{
this->ui->tvp_OwnAircraftModels->derivedModel()->setHighlightModelsStrings(stashedModels);
}
}
void CDbMappingComponent::ps_onVPilotCountChanged(int count, bool withFilter)
{
if (!m_withVPilot) { return; }
@@ -496,7 +509,9 @@ namespace BlackGui
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access mapping component");
if (mapComp->hasModelsForStash())
{
menu.addAction(CIcons::appMappings16(), "Stash", mapComp, SLOT(stashSelectedModels()));
QAction *a = menu.addAction(CIcons::appMappings16(), "Stash", mapComp, SLOT(stashSelectedModels()), Qt::ALT + Qt::Key_S);
a->setShortcut(Qt::ALT + Qt::Key_S);
}
this->nestedCustomMenu(menu);
}

View File

@@ -78,6 +78,10 @@ namespace BlackGui
//! Current tab index
TabIndex currentTabIndex() const;
//! Unvalidated consolidated aircraft model from the subparts (icao, distributor)
//! \note not guaranteed to be valid, just snapshot of as it state
BlackMisc::Simulation::CAircraftModel getAircraftModel() const;
signals:
//! Request to filter by livery
void filterByLivery(const BlackMisc::Aviation::CLivery &livery);
@@ -111,6 +115,9 @@ namespace BlackGui
//! Data for vPilot have been loaded
void ps_onLoadVPilotDataFinished(bool success);
//! Stashed models changed
void ps_onStashedModelsChanged();
//! Row count for vPilot data changed
void ps_onVPilotCountChanged(int count, bool withFilter);
@@ -145,9 +152,6 @@ namespace BlackGui
bool m_vPilot1stInit = true;
bool m_withVPilot = false;
//! Consolidated aircraft model
BlackMisc::Simulation::CAircraftModel getAircraftModel() const;
//! Init vPilot if rights and suitable
void initVPilotLoading();

View File

@@ -9,12 +9,17 @@
#include "dbstashcomponent.h"
#include "ui_dbstashcomponent.h"
#include "dbmappingcomponent.h"
#include "blackgui/views/aircraftmodelview.h"
#include "blackmisc/icons.h"
#include "blackmisc/verify.h"
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Network;
using namespace BlackGui::Models;
using namespace BlackGui::Views;
namespace BlackGui
{
@@ -29,8 +34,23 @@ namespace BlackGui
connect(this->ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::ps_onUnstashPressed);
connect(this->ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::ps_onValidatePressed);
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged, this, &CDbStashComponent::stashedModelChanged);
// copy over buttons
connect(this->ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
connect(this->ui->pb_AirlineIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
connect(this->ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
// set mapping component reference if it is parent
CDbMappingComponent *mapping = qobject_cast<CDbMappingComponent *>(parent);
if (mapping)
{
m_mappingComponent = mapping;
}
}
CDbStashComponent::~CDbStashComponent()
@@ -84,6 +104,61 @@ namespace BlackGui
return ui->tvp_StashAircraftModels;
}
bool CDbStashComponent::hasStashedModels() const
{
return !this->ui->tvp_StashAircraftModels->isEmpty();
}
QStringList CDbStashComponent::getStashedModelStrings() const
{
return this->ui->tvp_StashAircraftModels->derivedModel()->getModelStrings(false);
}
void CDbStashComponent::applyToSelected(const CLivery &livery, bool acceptWarnings)
{
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
CStatusMessageList msgs(livery.validate());
if (this->showMessages(msgs, acceptWarnings)) { return; }
this->ui->tvp_StashAircraftModels->applyToSelected(livery);
}
void CDbStashComponent::applyToSelected(const CAircraftIcaoCode &icao, bool acceptWarnings)
{
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
CStatusMessageList msgs(icao.validate());
if (this->showMessages(msgs, acceptWarnings)) { return; }
this->ui->tvp_StashAircraftModels->applyToSelected(icao);
}
void CDbStashComponent::applyToSelected(const CAirlineIcaoCode &icao, bool acceptWarnings)
{
if (!icao.hasValidDesignator())
{
static const CStatusMessage msg(CStatusMessage::SeverityError, "No valid designator");
this->showMessage(msg);
return;
}
// retrieve the std livery
const CLivery stdLivery(this->getStdLiveryForAirlineCode(icao));
if (!stdLivery.hasValidDbKey())
{
static const CStatusMessage msg(CStatusMessage::SeverityError, "No valid standard livery for " + icao.getDesignator());
this->showMessage(msg);
return;
}
applyToSelected(stdLivery, acceptWarnings);
}
void CDbStashComponent::applyToSelected(const CDistributor &distributor, bool acceptWarnings)
{
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
CStatusMessageList msgs(distributor.validate());
if (this->showMessages(msgs, acceptWarnings)) { return; }
this->ui->tvp_StashAircraftModels->applyToSelected(distributor);
}
void CDbStashComponent::ps_onUnstashPressed()
{
this->ui->tvp_StashAircraftModels->removeSelectedRows();
@@ -94,11 +169,55 @@ namespace BlackGui
if (this->ui->tvp_StashAircraftModels->isEmpty()) { return; }
}
void CDbStashComponent::ps_copyOverValues()
{
QObject *sender = QObject::sender();
BLACK_VERIFY_X(this->m_mappingComponent, Q_FUNC_INFO, "missing mapping component");
if (!this->m_mappingComponent) { return; }
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
CAircraftModel model(this->m_mappingComponent->getAircraftModel());
if (sender == this->ui->pb_AircraftIcao)
{
this->applyToSelected(model.getAircraftIcaoCode());
}
else if (sender == this->ui->pb_AirlineIcao)
{
this->applyToSelected(model.getAirlineIcaoCode());
}
else if (sender == this->ui->pb_Distributor)
{
this->applyToSelected(model.getDistributor());
}
else if (sender == this->ui->pb_Livery)
{
this->applyToSelected(model.getLivery());
}
}
bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors)
{
if (msgs.isEmpty()) { return false; }
if (!msgs.hasErrorMessages() && onlyErrors) { return false; }
BLACK_VERIFY_X(this->m_mappingComponent, Q_FUNC_INFO, "missing mapping component");
if (!this->m_mappingComponent) { return false; }
this->m_mappingComponent->showMessages(msgs);
return true;
}
bool CDbStashComponent::showMessage(const CStatusMessage &msg)
{
if (msg.isEmpty()) { return false; }
BLACK_VERIFY_X(this->m_mappingComponent, Q_FUNC_INFO, "missing mapping component");
if (!this->m_mappingComponent) { return false; }
this->m_mappingComponent->showMessage(msg);
return true;
}
void CDbStashComponent::CStashModelsMenu::customMenu(QMenu &menu) const
{
menu.addAction(CIcons::database16(), "Unstash", this->parent(), SLOT(ps_onUnstashPressed()));
nestedCustomMenu(menu);
}
} // ns
} // ns

View File

@@ -18,6 +18,7 @@
#include "blackmisc/network/webdataservicesprovider.h"
#include <QFrame>
#include <QScopedPointer>
#include <QStringList>
namespace Ui { class CDbStashComponent; }
@@ -25,6 +26,8 @@ namespace BlackGui
{
namespace Components
{
class CDbMappingComponent;
/*!
* Stashed objects
*/
@@ -60,10 +63,34 @@ namespace BlackGui
//! The embedded view
const BlackGui::Views::CAircraftModelView *getView() const;
//! Corresponding mapping component
void setMappingComponent(CDbMappingComponent *mappingComponent) { m_mappingComponent = mappingComponent; }
//! Has stashed models
bool hasStashedModels() const;
//! Stashed model strings
QStringList getStashedModelStrings() const;
//! Apply object to select objects
void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true);
//! Apply object to select objects
void applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao, bool acceptWarnings = true);
//! Apply object to select objects
void applyToSelected(const BlackMisc::Aviation::CAirlineIcaoCode &icao, bool acceptWarnings = true);
//! Apply object to select objects
void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor, bool acceptWarnings = true);
signals:
//! Unstash
void unstashed(BlackMisc::Simulation::CAircraftModel &model);
//! Stashed models have been changed
void stashedModelChanged();
private slots:
//! Unstash pressed
void ps_onUnstashPressed();
@@ -71,8 +98,18 @@ namespace BlackGui
//! Validate pressed
void ps_onValidatePressed();
//! Copy over values
void ps_copyOverValues();
private:
QScopedPointer<Ui::CDbStashComponent> ui;
CDbMappingComponent *m_mappingComponent = nullptr; //!< corresponding mapping component
//! Display messages
bool showMessages(const BlackMisc::CStatusMessageList &msgs, bool onlyErrors = false);
//! Display message
bool showMessage(const BlackMisc::CStatusMessage &msg);
//! Custom menu for the stashed models
class CStashModelsMenu : public BlackGui::IMenuDelegate

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>616</width>
<height>221</height>
</rect>
</property>
<property name="windowTitle">
@@ -72,21 +72,63 @@
<item>
<widget class="QPushButton" name="pb_Unstash">
<property name="text">
<string>Unstash</string>
<string>unstash</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_Sep1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Validate">
<property name="text">
<string>Validate</string>
<string>validate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Save">
<property name="text">
<string>Save</string>
<string>save</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_Sep2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Distributor">
<property name="text">
<string>distributor</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_AircraftIcao">
<property name="text">
<string>aircraft ICAO</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Livery">
<property name="text">
<string>livery</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_AirlineIcao">
<property name="text">
<string>airline ICAO</string>
</property>
</widget>
</item>