[libcalamaresui] Shuffle the module interface

- introduce NamedEnum lookup tables for interface and type
 - drop "final" and "virtual" from methods that don't make
   sense as virtual
 - shuffle declaration order so the virtual API for modules
   sits together
This commit is contained in:
Adriaan de Groot 2020-01-12 12:18:13 +01:00
parent f89c137c90
commit ed4127f661
2 changed files with 81 additions and 67 deletions

View File

@ -27,6 +27,7 @@
#include "utils/Dirs.h" #include "utils/Dirs.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/Yaml.h" #include "utils/Yaml.h"
#ifdef WITH_PYTHON #ifdef WITH_PYTHON
@ -152,7 +153,7 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
cError() << "Module" << instanceId << "invalid ID"; cError() << "Module" << instanceId << "invalid ID";
return nullptr; return nullptr;
} }
m->initFrom( moduleDescriptor ); m->initFrom( moduleDescriptor );
try try
{ {
@ -243,42 +244,55 @@ void Module::loadConfigurationFile( const QString& configFileName ) //throws YA
} }
QString static const NamedEnumTable< Module::Type >&
Module::location() const typeNames()
{ {
return m_directory; using Type = Module::Type;
// *INDENT-OFF*
// clang-format off
static const NamedEnumTable< Type > table{
{ QStringLiteral( "job" ), Type::Job },
{ QStringLiteral( "view" ), Type::View },
{ QStringLiteral( "viewmodule" ), Type::View },
{ QStringLiteral( "jobmodule" ), Type::Job }
};
// *INDENT-ON*
// clang-format on
return table;
} }
QString QString
Module::typeString() const Module::typeString() const
{ {
switch ( type() ) bool ok = false;
{ QString v = typeNames().find( type(), ok );
case Type::Job: return ok ? v : QString();
return "Job Module";
case Type::View:
return "View Module";
}
return QString();
} }
static const NamedEnumTable< Module::Interface >&
interfaceNames()
{
using Interface = Module::Interface;
// *INDENT-OFF*
// clang-format off
static const NamedEnumTable< Interface > table {
{ QStringLiteral("process"), Interface::Process },
{ QStringLiteral("qtplugin"), Interface::QtPlugin },
{ QStringLiteral("python"), Interface::Python },
{ QStringLiteral("pythonqt"), Interface::PythonQt }
};
// *INDENT-ON*
// clang-format on
return table;
}
QString QString
Module::interfaceString() const Module::interfaceString() const
{ {
switch ( interface() ) bool ok = false;
{ QString v = interfaceNames().find( interface(), ok );
case Interface::Process: return ok ? v : QString();
return "External process";
case Interface::Python:
return "Python (Boost.Python)";
case Interface::PythonQt:
return "Python (experimental)";
case Interface::QtPlugin:
return "Qt Plugin";
}
return QString();
} }

View File

@ -106,43 +106,7 @@ public:
* @brief location returns the full path of this module's directory. * @brief location returns the full path of this module's directory.
* @return the path. * @return the path.
*/ */
virtual QString location() const final; QString location() const { return m_directory; }
/**
* @brief type returns the Type of this module object.
* @return the type enum value.
*/
virtual Type type() const = 0;
/**
* @brief typeString returns a user-visible string for the module's type.
* @return the type string.
*/
virtual QString typeString() const;
/**
* @brief interface the Interface used by this module.
* @return the interface enum value.
*/
virtual Interface interface() const = 0;
/**
* @brief interface returns a user-visible string for the module's interface.
* @return the interface string.
*/
virtual QString interfaceString() const;
/**
* @brief isLoaded reports on the loaded status of a module.
* @return true if the module's loading phase has finished, otherwise false.
*/
bool isLoaded() const { return m_loaded; }
/**
* @brief loadSelf initialized the module.
* Subclasses must reimplement this depending on the module type and interface.
*/
virtual void loadSelf() = 0;
/** /**
* @brief Is this an emergency module? * @brief Is this an emergency module?
@ -156,10 +120,10 @@ public:
bool isEmergency() const { return m_emergency; } bool isEmergency() const { return m_emergency; }
/** /**
* @brief jobs returns any jobs exposed by this module. * @brief isLoaded reports on the loaded status of a module.
* @return a list of jobs (can be empty). * @return true if the module's loading phase has finished, otherwise false.
*/ */
virtual JobList jobs() const = 0; bool isLoaded() const { return m_loaded; }
/** /**
* @brief configurationMap returns the contents of the configuration file for * @brief configurationMap returns the contents of the configuration file for
@ -168,6 +132,42 @@ public:
*/ */
QVariantMap configurationMap(); QVariantMap configurationMap();
/**
* @brief typeString returns a user-visible string for the module's type.
* @return the type string.
*/
QString typeString() const;
/**
* @brief interface returns a user-visible string for the module's interface.
* @return the interface string.
*/
QString interfaceString() const;
/**
* @brief loadSelf initialized the module.
* Subclasses must reimplement this depending on the module type and interface.
*/
virtual void loadSelf() = 0;
/**
* @brief jobs returns any jobs exposed by this module.
* @return a list of jobs (can be empty).
*/
virtual JobList jobs() const = 0;
/**
* @brief type returns the Type of this module object.
* @return the type enum value.
*/
virtual Type type() const = 0;
/**
* @brief interface the Interface used by this module.
* @return the interface enum value.
*/
virtual Interface interface() const = 0;
/** /**
* @brief Check the requirements of this module. * @brief Check the requirements of this module.
*/ */
@ -175,12 +175,12 @@ public:
protected: protected:
explicit Module(); explicit Module();
/// @brief For subclasses to read their part of the descriptor /// @brief For subclasses to read their part of the descriptor
virtual void initFrom( const QVariantMap& moduleDescriptor ) = 0; virtual void initFrom( const QVariantMap& moduleDescriptor ) = 0;
/// @brief Generic part of descriptor reading (and instance id) /// @brief Generic part of descriptor reading (and instance id)
void initFrom( const QVariantMap& moduleDescriptor, const QString& id ); void initFrom( const QVariantMap& moduleDescriptor, const QString& id );
QVariantMap m_configurationMap; QVariantMap m_configurationMap;
bool m_loaded = false; bool m_loaded = false;