Commit cacda20f authored by Jan Möbius's avatar Jan Möbius
Browse files

Extend typeInterface for addEmpty function via type

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7843 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8b0cd6c1
......@@ -91,6 +91,7 @@
// Required Interface definition ( Some variables were defined there )
#include "OpenFlipper/BasePlugin/BaseInterface.hh"
#include "OpenFlipper/BasePlugin/FileInterface.hh"
#include "OpenFlipper/BasePlugin/TypeInterface.hh"
#include "OpenFlipper/BasePlugin/MenuInterface.hh"
#include "OpenFlipper/BasePlugin/ContextMenuInterface.hh"
......@@ -115,6 +116,12 @@ struct fileTypes {
FileInterface* plugin;
};
struct dataTypes {
QString name;
DataType type;
TypeInterface* plugin;
};
/** Core Widget of the Application
*/
class Core : public QObject
......@@ -1015,6 +1022,9 @@ private:
/// File-Plugins
std::vector<fileTypes> supportedTypes_;
/// Type-Plugins
std::vector<dataTypes> supportedDataTypes_;
private :
///Pointer to the data rootNode;
BaseObject* objectRoot_;
......
......@@ -541,13 +541,6 @@ void Core::loadPlugin(QString filename, bool silent){
this, SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
}
//Check if the plugin is a typePlugin
TypeInterface* typePlugin = qobject_cast< TypeInterface * >(plugin);
if ( typePlugin ) {
// The only purpose of typePlugins is to register the types before all other Plugins are loaded
typePlugin->registerType();
}
//Check if the plugin supports Logging
LoggingInterface* logPlugin = qobject_cast< LoggingInterface * >(plugin);
if ( logPlugin ) {
......@@ -1170,6 +1163,24 @@ void Core::loadPlugin(QString filename, bool silent){
supportedTypes_.push_back(ft);
}
//Check if it's a typePlugin
TypeInterface* typePlugin = qobject_cast< TypeInterface * >(plugin);
if ( typePlugin ){
supported = supported + "Type ";
// Call register type
typePlugin->registerType();
// Collect supported Data from type plugin
dataTypes dt;
dt.name = basePlugin->name();
dt.type = typePlugin->supportedType();
dt.plugin = typePlugin;
// Add type info
supportedDataTypes_.push_back(dt);
}
emit log(LOGOUT,"=============================================================================================");
} else {
emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( filename ) );
......
......@@ -246,10 +246,22 @@ int Core::loadObject( DataType _type, QString _filename) {
int Core::addEmptyObject( DataType _type ) {
// Iterate over all plugins. The first plugin supporting the addEmpty function for the
// specified type will be used to create the new object.
int retCode = -1;
// Type plugins
for (int i=0; i < (int)supportedDataTypes_.size(); i++)
if ( supportedDataTypes_[i].type & _type )
retCode = supportedDataTypes_[i].plugin->addEmpty();
if(retCode != -1) return retCode;
// File plugins
for (int i=0; i < (int)supportedTypes_.size(); i++)
if ( supportedTypes_[i].type & _type )
return supportedTypes_[i].plugin->addEmpty();
return -1; //no plugin found
retCode = supportedTypes_[i].plugin->addEmpty();
return retCode; // -1 if no plugin found
}
//========================================================================================
......@@ -514,13 +526,39 @@ void Core::slotAddEmptyObjectMenu() {
//
for ( uint i = 0 ; i < typeCount() - 2 ; ++i) {
// iterate over all support types (created from plugins on load.
// Iterate over all supported types (created from plugins on load)
// Check if a plugin supports addEmpty for the current type.
// Only if the type is supported, add it to the addEmpty Dialog
// typePlugin
for ( uint j = 0 ; j < supportedDataTypes_.size(); j++) {
// Check if a plugin supports the current type
if ( supportedDataTypes_[j].type & currentType ) {
types.push_back(currentType);
typeNames.push_back( typeName( currentType ) );
// Stop here as we need only one plugin supporting addEmpty for a given type
break;
}
}
// filePlugin
for ( uint j = 0 ; j < supportedTypes_.size(); j++) {
// Check if a plugin supports the current Type
if ( supportedTypes_[j].type & currentType ) {
// Avoid duplicates
bool duplicate = false;
for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
if(*it == currentType) {
duplicate = true;
break;
}
}
if(!duplicate) {
types.push_back(currentType);
typeNames.push_back( typeName( currentType ) );
......@@ -528,6 +566,7 @@ void Core::slotAddEmptyObjectMenu() {
break;
}
}
}
// Advance to next type ( Indices are bits so multiply by to to get next bit)
currentType *= 2;
......
Supports Markdown
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