mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #368, updated aircraftcfgentries
* allow to exclude directories for read * added texture
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackSim
|
||||
@@ -43,6 +44,13 @@ namespace BlackSim
|
||||
/*
|
||||
* Aircraft model
|
||||
*/
|
||||
QString CAircraftCfgEntries::getFileDirectory() const
|
||||
{
|
||||
if (this->m_fileName.isEmpty()) { return ""; }
|
||||
QFileInfo fi(this->m_fileName);
|
||||
return fi.absolutePath();
|
||||
}
|
||||
|
||||
QString CAircraftCfgEntries::getUiCombinedDescription() const
|
||||
{
|
||||
QString d(this->m_uiManufacturer);
|
||||
@@ -64,6 +72,14 @@ namespace BlackSim
|
||||
return model;
|
||||
}
|
||||
|
||||
QString CAircraftCfgEntries::getThumbnailFileName() const
|
||||
{
|
||||
if (this->m_texture.isEmpty()) { return ""; }
|
||||
if (this->m_fileName.isEmpty()) { return ""; }
|
||||
QString fn = QDir::cleanPath(this->getFileDirectory() + QDir::separator() + "texture." + this->m_texture + QDir::separator() + "thumbnail.jpg");
|
||||
return fn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get particular column
|
||||
*/
|
||||
@@ -85,6 +101,10 @@ namespace BlackSim
|
||||
return CVariant::from(this->m_atcParkingCode);
|
||||
case IndexEntryIndex:
|
||||
return CVariant::from(this->m_index);
|
||||
case IndexTexture:
|
||||
return CVariant::from(this->m_texture);
|
||||
case IndexDescription:
|
||||
return CVariant::from(this->m_description);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -117,6 +137,12 @@ namespace BlackSim
|
||||
case IndexTitle:
|
||||
this->setTitle(variant.toQString());
|
||||
break;
|
||||
case IndexDescription:
|
||||
this->setDescription(variant.toQString());
|
||||
break;
|
||||
case IndexTexture:
|
||||
this->setTexture(variant.toQString());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#ifndef BLACKSIM_FSCOMMON_AIRCRAFTCFGENTRY_H
|
||||
#define BLACKSIM_FSCOMMON_AIRCRAFTCFGENTRY_H
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/nwaircraftmodel.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
namespace BlackSim
|
||||
@@ -37,7 +37,8 @@ namespace BlackSim
|
||||
IndexAtcType,
|
||||
IndexAtcModel,
|
||||
IndexParkingCode,
|
||||
IndexDescription
|
||||
IndexDescription,
|
||||
IndexTexture
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
@@ -49,6 +50,9 @@ namespace BlackSim
|
||||
//! File name
|
||||
QString getFileName() const { return this->m_fileName; }
|
||||
|
||||
//! Directory of entry
|
||||
QString getFileDirectory() const;
|
||||
|
||||
//! Title
|
||||
QString getTitle() const { return this->m_title; }
|
||||
|
||||
@@ -73,6 +77,9 @@ namespace BlackSim
|
||||
//! UI manufacturer (e.g. Airbus)
|
||||
QString getUiManufacturer() const { return this->m_uiManufacturer; }
|
||||
|
||||
//! Texture
|
||||
QString getTexture() const { return this->m_texture; }
|
||||
|
||||
//! Manufacturer + type
|
||||
QString getUiCombinedDescription() const;
|
||||
|
||||
@@ -97,6 +104,9 @@ namespace BlackSim
|
||||
//! Description
|
||||
void setDescription(const QString &description) { this->m_description = description.trimmed(); }
|
||||
|
||||
//! Texture
|
||||
void setTexture(const QString &texture) { this->m_texture = texture; }
|
||||
|
||||
//! UI type (e.g. A321-231 IAE)
|
||||
void setUiType(const QString &type) { this->m_uiType = type.trimmed(); }
|
||||
|
||||
@@ -104,7 +114,10 @@ namespace BlackSim
|
||||
void setUiManufacturer(const QString &manufacturer) { this->m_uiManufacturer = manufacturer.trimmed(); }
|
||||
|
||||
//! To aircraft model
|
||||
BlackMisc::Network::CAircraftModel toAircraftModel() const;
|
||||
BlackMisc::Simulation::CAircraftModel toAircraftModel() const;
|
||||
|
||||
//! Thumbnail.jpg path if possible
|
||||
QString getThumbnailFileName() const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
@@ -127,6 +140,7 @@ namespace BlackSim
|
||||
QString m_description; //!< descriptive text
|
||||
QString m_uiType; //!< e.g. A321-231 IAE
|
||||
QString m_uiManufacturer; //!< e.g. Airbus
|
||||
QString m_texture; //!< texture, needed to identify thumbnail.jpg
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackSim
|
||||
@@ -102,10 +103,20 @@ namespace BlackSim
|
||||
/*
|
||||
* Read all entrities in given directory
|
||||
*/
|
||||
int CAircraftCfgEntriesList::read(const QString &directory)
|
||||
int CAircraftCfgEntriesList::read(const QString &directory, const QStringList &excludeDirectories)
|
||||
{
|
||||
if (m_cancelRead) { return -1; }
|
||||
|
||||
// excluded?
|
||||
for (const QString &excludeDir : excludeDirectories)
|
||||
{
|
||||
if (directory.contains(excludeDir, Qt::CaseInsensitive))
|
||||
{
|
||||
CLogMessage(this).debug() << "Skipping directory " << directory;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// set directory with name filters, get aircraft.cfg and sub directories
|
||||
QDir dir(directory, "aircraft.cfg", QDir::Name, QDir::Files | QDir::AllDirs);
|
||||
if (!dir.exists()) return 0; // can happen if there are shortcuts or linked dirs not available
|
||||
@@ -123,8 +134,8 @@ namespace BlackSim
|
||||
{
|
||||
QString nextDir = file.absoluteFilePath();
|
||||
if (currentDir.startsWith(nextDir, Qt::CaseInsensitive)) continue; // do not go up
|
||||
if (dir == currentDir) continue; // do not recursively call same directory
|
||||
counter += CAircraftCfgEntriesList::read(nextDir);
|
||||
if (dir == currentDir) { continue; } // do not recursively call same directory
|
||||
counter += CAircraftCfgEntriesList::read(nextDir, excludeDirectories);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,6 +167,7 @@ namespace BlackSim
|
||||
entry.setDescription(fixedStringContent(aircraftCfg, "description"));
|
||||
entry.setUiManufacturer(fixedStringContent(aircraftCfg, "ui_manufacturer"));
|
||||
entry.setUiType(fixedStringContent(aircraftCfg, "ui_type"));
|
||||
entry.setTexture(fixedStringContent(aircraftCfg, "texture"));
|
||||
this->push_back(entry);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#ifndef BLACKSIM_FSCOMMON_AIRCRAFTCFGLIST_H
|
||||
#define BLACKSIM_FSCOMMON_AIRCRAFTCFGLIST_H
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "aircraftcfgentries.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/nwaircraftmodellist.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QVector>
|
||||
#include <QDebug>
|
||||
@@ -27,7 +26,7 @@ namespace BlackSim
|
||||
namespace FsCommon
|
||||
{
|
||||
|
||||
//! Utility, providing FSX aircraft.cfg entries
|
||||
//! Utility, providing FS aircraft.cfg entries
|
||||
class CAircraftCfgEntriesList : public BlackMisc::CSequence<CAircraftCfgEntries>
|
||||
{
|
||||
|
||||
@@ -44,7 +43,7 @@ namespace BlackSim
|
||||
// not read so far, read it
|
||||
this->clear();
|
||||
this->m_readForDirectory = true;
|
||||
return this->read(this->m_rootDirectory);
|
||||
return this->read(this->m_rootDirectory, excludeDirectories());
|
||||
}
|
||||
|
||||
//! Change the directory
|
||||
@@ -80,13 +79,13 @@ namespace BlackSim
|
||||
QStringList getTitles(bool sorted = false) const;
|
||||
|
||||
//! As aircraft models
|
||||
BlackMisc::Network::CAircraftModelList toAircraftModelList() const;
|
||||
BlackMisc::Simulation::CAircraftModelList toAircraftModelList() const;
|
||||
|
||||
//! Ambiguous titles
|
||||
QStringList detectAmbiguousTitles() const;
|
||||
|
||||
//! Find by title
|
||||
CAircraftCfgEntriesList findByTitle(const QString &title, Qt::CaseSensitivity caseSensitivity) const;
|
||||
CAircraftCfgEntriesList findByTitle(const QString &title, Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive) const;
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
@@ -94,11 +93,17 @@ namespace BlackSim
|
||||
//! \copydoc CValueObject::convertFromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
|
||||
|
||||
//! Unknown entries
|
||||
static const CAircraftCfgEntries &UnknownCfgEntries()
|
||||
//! Do not include the following directories for FS
|
||||
static const QStringList &excludeDirectories()
|
||||
{
|
||||
static CAircraftCfgEntries entries;
|
||||
return entries;
|
||||
static const QStringList exclude(
|
||||
{
|
||||
"SimObjects/Animals",
|
||||
"SimObjects/Misc",
|
||||
"SimObjects/GroundVehicles",
|
||||
"SimObjects/Boats"
|
||||
});
|
||||
return exclude;
|
||||
}
|
||||
|
||||
//! Register metadata
|
||||
@@ -110,7 +115,7 @@ namespace BlackSim
|
||||
bool m_cancelRead = false;
|
||||
|
||||
//! Read all entries in one directory
|
||||
int read(const QString &directory);
|
||||
int read(const QString &directory, const QStringList &excludeDirectories = QStringList());
|
||||
|
||||
//! Fix the content read
|
||||
static QString fixedStringContent(const QVariant &qv);
|
||||
|
||||
Reference in New Issue
Block a user