Commit c7f7f056 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

ToolCategory mechanism modified so that user can declare on the fly during...

ToolCategory mechanism modified so that user can declare on the fly during application initialization its own categories.
parent 4d55a2b1
......@@ -59,8 +59,8 @@ void AlgorithmSelector::populateTools( ToolInterface *plugin )
foreach( int i, toolIds )
{
ToolCategory::CategoryId categoryId = plugin->category(i);
if( categoryId != ToolCategory::invalidId() )
int categoryId = plugin->category(i);
if( ToolCategory::isCategoryDeclared(categoryId) )
{
ToolDescriptor tool;
tool.plugin = plugin;
......
......@@ -11,13 +11,6 @@
QString ToolCategory::s_CategoryName[CATEGORIES_END] = {
"Fourier",
"Experimental"
};
QString ToolCategory::s_CategoryIcon[CATEGORIES_END] = {
":/images/resources/categories/Fourier.png",
":/images/resources/categories/Experimental.png"
};
QVector<QString> ToolCategory::s_CategoryNames;
QVector<QString> ToolCategory::s_CategoryIcons;
QMap<int,int> ToolCategory::s_CategoryById;
......@@ -17,25 +17,31 @@
class ToolCategory
{
public:
enum CategoryId
{
FOURIER ,
EXPERIMENTAL ,
CATEGORIES_END
};
private:
static QString s_CategoryName[CATEGORIES_END];
static QString s_CategoryIcon[CATEGORIES_END];
static QVector<QString> s_CategoryNames;
static QVector<QString> s_CategoryIcons;
static QMap<int,int> s_CategoryById;
public:
static inline int categoriesCount() { return CATEGORIES_END; }
static inline QList<CategoryId> categoriesId() { QList<CategoryId> ids; for(int i=0;i<CATEGORIES_END;++i) ids<<(CategoryId)i; return ids; }
static inline const QString& categoryName( int id ) { return s_CategoryName[id]; }
static inline QIcon categoryIcon( int id ) { return QIcon( s_CategoryIcon[id] ); }
static inline CategoryId invalidId() { return CATEGORIES_END; }
static inline const QString& categoryName( int id ) { return s_CategoryNames[ s_CategoryById[id] ]; }
static inline QIcon categoryIcon( int id ) { return QIcon( s_CategoryIcons[ s_CategoryById[id] ] ); }
static inline bool isCategoryDeclared( int id ) { return s_CategoryById.contains( id ); }
static inline void declareCategory( int id, const QString& name, const QString &icon )
{
s_CategoryById[id] = s_CategoryNames.size();
s_CategoryNames.append( name );
s_CategoryIcons.append( icon );
}
static inline int categoriesCount() { return s_CategoryById.size(); }
static inline QList<int> categoriesId()
{
QList<int> ids;
for( auto i=s_CategoryById.begin(); i!=s_CategoryById.end(); ++i )
ids.append( i.key() );
return ids;
}
};
......
......@@ -83,6 +83,8 @@ public:
virtual void onInitializingApp() {}
virtual void onReleasingApp() {}
inline void declareToolCategory( int id, const QString& name, const QString &icon ) { ToolCategory::declareCategory(id,name,icon); }
virtual UIProject* onCreatingProject( const QString &name ) { return new UIProject(name); }
private:
......
......@@ -13,8 +13,6 @@
<file>resources/animationStop.png</file>
<file>resources/animationStepFwd.png</file>
<file>resources/animationStepBwd.png</file>
<file>resources/categories/Experimental.png</file>
<file>resources/categories/Fourier.png</file>
</qresource>
<qresource prefix="/AboutLicences">
<file>resources/AboutLicences/ArrowLeft.png</file>
......
......@@ -30,7 +30,7 @@ public:
*/
virtual void toolIds( QList<int> &ids ) const = 0;
/** Category to which the tool belongs. */
virtual ToolCategory::CategoryId category( int id ) const = 0;
virtual int category( int id ) const = 0;
/** Name of the tool, as it will be displayed in the GUI. */
virtual QString name( int id ) const = 0;
/** Extended description of the tool, as it will be displayed in the GUI. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment