Add a mechanism to specify default loaders when loading, not just for saving. Make the off plugin the default loader for .off files so that lcc_plugin doesn't come first in the list.

This commit is contained in:
Maxime Gimeno 2019-04-24 10:35:45 +02:00
parent 564a6c72f4
commit d4b70a7703
4 changed files with 20 additions and 4 deletions

View File

@ -1107,7 +1107,12 @@ void MainWindow::open(QString filename)
if ( !io_plugin->canLoad() ) continue;
all_items << io_plugin->name();
if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) )
selected_items << io_plugin->name();
{
if(io_plugin->isDefaultLoader(fileinfo.completeSuffix()))
selected_items.prepend(io_plugin->name());
else
selected_items << io_plugin->name();
}
}
}
else

View File

@ -32,6 +32,13 @@ public:
return true;
return false;
}
bool isDefaultLoader(const QString& name) const
{
qDebug()<<name;
if(name == QString("off"))
return true;
return false;
}
QString name() const { return "off_plugin"; }
QString nameFilters() const { return "OFF files (*.off);;Wavefront OBJ (*.obj)"; }
bool canLoad() const;

View File

@ -62,9 +62,8 @@ public:
}
bool canSave(const CGAL::Three::Scene_item*){return true;}
bool canSave(const CGAL::Three::Scene_item*){return false;}
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo){
qDebug() << fileinfo.fileName() << "Implement me, you fool !";
return false;
}

View File

@ -70,10 +70,15 @@ public:
//! This must be overriden.
virtual bool save(const Scene_item*, QFileInfo fileinfo) = 0;
//! If this returns `true`, then the loader will be chosen as defaultin the
//! If this returns `true`, then the loader will be chosen as default in the
//! list of available loaders when saving a file, which means it will be the
//! first in the list.
virtual bool isDefaultLoader(const Scene_item*) const { return false; }
//! If this returns `true`, then the loader will be chosen as default in the
//! list of available loaders when loading a file, which means it will be the
//! first in the list.
//! @param name is the extension without the dot (e.g. "off" for a .off file)
virtual bool isDefaultLoader(const QString& name) const { return false; }
};
}
}