From 4d57a50fd23add75a32e9763b199867742e3514a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 13 May 2014 01:11:04 +0200 Subject: [PATCH] refs #236, aircraft indexer to read FSX/9 models on disk in background --- .../fscommon/aircraftcfgentrieslist.cpp | 9 ++++ .../fscommon/aircraftcfgentrieslist.h | 3 ++ src/blacksim/fscommon/aircraftindexer.cpp | 23 ++++++++++ src/blacksim/fscommon/aircraftindexer.h | 45 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/blacksim/fscommon/aircraftindexer.cpp create mode 100644 src/blacksim/fscommon/aircraftindexer.h diff --git a/src/blacksim/fscommon/aircraftcfgentrieslist.cpp b/src/blacksim/fscommon/aircraftcfgentrieslist.cpp index 5254a6843..95cedb89d 100644 --- a/src/blacksim/fscommon/aircraftcfgentrieslist.cpp +++ b/src/blacksim/fscommon/aircraftcfgentrieslist.cpp @@ -21,6 +21,15 @@ namespace BlackSim return (dir.exists()); } + /* + * Model for title + */ + bool CAircraftCfgEntriesList::containsModeWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity) + { + return this->contains([ = ](const CAircraftCfgEntries & entries) -> bool + { return title.compare(entries.getTitle(), caseSensitivity) == 0; }); + } + /* * Read all entrities in given directory */ diff --git a/src/blacksim/fscommon/aircraftcfgentrieslist.h b/src/blacksim/fscommon/aircraftcfgentrieslist.h index 9fd3b1ab3..3964d508a 100644 --- a/src/blacksim/fscommon/aircraftcfgentrieslist.h +++ b/src/blacksim/fscommon/aircraftcfgentrieslist.h @@ -68,6 +68,9 @@ namespace BlackSim //! \brief Current root directory QString getRootDirectory() const { return this->m_rootDirectory; } + //! Contains model with title? + bool containsModeWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive); + //! \brief Unknown entries static const CAircraftCfgEntries &UnknownCfgEntries() { diff --git a/src/blacksim/fscommon/aircraftindexer.cpp b/src/blacksim/fscommon/aircraftindexer.cpp new file mode 100644 index 000000000..1b6a2da6a --- /dev/null +++ b/src/blacksim/fscommon/aircraftindexer.cpp @@ -0,0 +1,23 @@ +#include "aircraftindexer.h" + +namespace BlackSim +{ + namespace FsCommon + { + CAircraftIndexer::CAircraftIndexer(QObject *parent) : QObject(parent) {} + + int CAircraftIndexer::read(const QString directory) + { + if (!directory.isEmpty()) indexer().m_entries.changeDirectory(directory); + int n = indexer().m_entries.read(); + emit indexer().entriesRead(n); + return n; + } + + QFuture CAircraftIndexer::readInBackground(const QString directory) + { + QFuture f = QtConcurrent::run(CAircraftIndexer::read, directory); + return f; + } + } +} diff --git a/src/blacksim/fscommon/aircraftindexer.h b/src/blacksim/fscommon/aircraftindexer.h new file mode 100644 index 000000000..514972d3b --- /dev/null +++ b/src/blacksim/fscommon/aircraftindexer.h @@ -0,0 +1,45 @@ +#ifndef BLACKSIM_FSCOMMON_AIRCRAFTINDEXER_H +#define BLACKSIM_FSCOMMON_AIRCRAFTINDEXER_H + +#include "aircraftcfgentrieslist.h" +#include +#include + +namespace BlackSim +{ + namespace FsCommon + { + /*! + * \brief Indexer for all modelsThe CAircraftIndexer class + */ + class CAircraftIndexer : QObject + { + Q_OBJECT + + private: + //! Constructor + CAircraftIndexer(QObject *parent = nullptr); + + CAircraftCfgEntriesList m_entries; //!< all entries + + signals: + void entriesRead(int number); + + public: + //! Single entity indexer + static CAircraftIndexer &indexer() + { + static CAircraftIndexer indexer; + return indexer; + } + + //! Read for directory or re-read + static int read(const QString directory = ""); + + //! Read in background + static QFuture readInBackground(const QString directory = ""); + + }; + } +} +#endif // guard