Commit 4b98d19d authored by Dirk Wilden's avatar Dirk Wilden

extended FileInterface

it is now possible to provide a special loadWidget/saveWidget for every nameFilter

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@2776 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1f9da75a
...@@ -80,13 +80,8 @@ class FileInterface { ...@@ -80,13 +80,8 @@ class FileInterface {
/// Get the Qt Filters for Filedialogs when saving files /// Get the Qt Filters for Filedialogs when saving files
virtual QString getSaveFilters() = 0; virtual QString getSaveFilters() = 0;
/** You can provide a special widget showing options for saving your file types
* Return 0 when you dont need one
*/
virtual QWidget* saveOptionsWidget() = 0;
/** You can also provide a special widget showing options for saving your file types /** You can provide a special widget showing options for saving your file types
* depending on the current filter * depending on the current filter
* *
* _currentFilter: one filter from saveFilters * _currentFilter: one filter from saveFilters
...@@ -94,13 +89,8 @@ class FileInterface { ...@@ -94,13 +89,8 @@ class FileInterface {
* Return 0 when you dont need one, OpenFlipper then uses saveOptionsWidget() if available * Return 0 when you dont need one, OpenFlipper then uses saveOptionsWidget() if available
*/ */
virtual QWidget* saveOptionsWidget(QString _currentFilter) = 0; virtual QWidget* saveOptionsWidget(QString _currentFilter) = 0;
/** You can provide a special widget showing options for loading your file types
* Return 0 when you dont need one
*/
virtual QWidget* loadOptionsWidget() = 0;
/** You can also provide a special widget showing options for loading your file types /** You can provide a special widget showing options for loading your file types
* depending on the current filter * depending on the current filter
* *
* _currentFilter: one filter from loadFilters * _currentFilter: one filter from loadFilters
......
...@@ -96,8 +96,6 @@ struct fileTypes { ...@@ -96,8 +96,6 @@ struct fileTypes {
QString loadFilters; QString loadFilters;
QString saveFilters; QString saveFilters;
FileInterface* plugin; FileInterface* plugin;
QWidget* loadWidget;
QWidget* saveWidget;
}; };
/** Core Widget of the Application /** Core Widget of the Application
......
...@@ -429,14 +429,6 @@ void Core::loadPlugin(QString filename, bool silent){ ...@@ -429,14 +429,6 @@ void Core::loadPlugin(QString filename, bool silent){
ft.saveFilters = filePlugin->getSaveFilters(); ft.saveFilters = filePlugin->getSaveFilters();
ft.plugin = filePlugin; ft.plugin = filePlugin;
if ( OpenFlipper::Options::gui() ) {
ft.loadWidget = filePlugin->loadOptionsWidget();
ft.saveWidget = filePlugin->saveOptionsWidget();
} else {
ft.loadWidget = 0;
ft.saveWidget = 0;
}
supportedTypes_.push_back(ft); supportedTypes_.push_back(ft);
filePlugin->setObjectRoot( objectRoot_ ); filePlugin->setObjectRoot( objectRoot_ );
} }
......
...@@ -49,7 +49,6 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent ...@@ -49,7 +49,6 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent
: QFileDialog(parent), : QFileDialog(parent),
loadMode_(true), loadMode_(true),
supportedTypes_(_supportedTypes) supportedTypes_(_supportedTypes)
{ {
// Get our layout // Get our layout
...@@ -100,16 +99,12 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent ...@@ -100,16 +99,12 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent
/// adjust the loadWidget / saveWidget when the selected nameFilter changed /// adjust the loadWidget / saveWidget when the selected nameFilter changed
void LoadWidget::currentFilterChanged(QString _currentFilter){ void LoadWidget::currentFilterChanged(QString _currentFilter){
for (int i=0; i < (int)supportedTypes_.size(); i++){ for (int i=0; i < boxWidgets_.size(); i++){
if (supportedTypes_[i].loadWidget != 0){ boxLayout_->removeWidget( boxWidgets_[i] );
boxLayout_->removeWidget(supportedTypes_[i].loadWidget); boxWidgets_[i]->setParent(0);
supportedTypes_[i].loadWidget->setParent(0); }
}
if (supportedTypes_[i].saveWidget != 0){ boxWidgets_.clear();
boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
supportedTypes_[i].saveWidget->setParent(0);
}
}
const DataType type = (DataType) typeBox_->itemData( typeBox_->currentIndex() ).toInt(); const DataType type = (DataType) typeBox_->itemData( typeBox_->currentIndex() ).toInt();
...@@ -122,10 +117,7 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){ ...@@ -122,10 +117,7 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){
if (nuWidget != 0){ if (nuWidget != 0){
boxLayout_->addWidget( nuWidget ); boxLayout_->addWidget( nuWidget );
box_->show(); boxWidgets_.push_back( nuWidget );
}else
if ( supportedTypes_[i].loadWidget != 0 ) {
boxLayout_->addWidget(supportedTypes_[i].loadWidget);
box_->show(); box_->show();
} }
} }
...@@ -138,10 +130,7 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){ ...@@ -138,10 +130,7 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){
if (nuWidget != 0){ if (nuWidget != 0){
boxLayout_->addWidget( nuWidget ); boxLayout_->addWidget( nuWidget );
box_->show(); boxWidgets_.push_back( nuWidget );
}else
if ( supportedTypes_[i].saveWidget != 0 ) {
boxLayout_->addWidget(supportedTypes_[i].saveWidget);
box_->show(); box_->show();
} }
} }
...@@ -152,17 +141,12 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){ ...@@ -152,17 +141,12 @@ void LoadWidget::currentFilterChanged(QString _currentFilter){
void LoadWidget::slotSetLoadFilters(int _typeIndex){ void LoadWidget::slotSetLoadFilters(int _typeIndex){
box_->setTitle("Load Options"); box_->setTitle("Load Options");
for (int i=0; i < (int)supportedTypes_.size(); i++){ for (int i=0; i < boxWidgets_.size(); i++){
if (supportedTypes_[i].loadWidget != 0){ boxLayout_->removeWidget( boxWidgets_[i] );
boxLayout_->removeWidget(supportedTypes_[i].loadWidget); boxWidgets_[i]->setParent(0);
supportedTypes_[i].loadWidget->setParent(0);
}
if (supportedTypes_[i].saveWidget != 0){
boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
supportedTypes_[i].saveWidget->setParent(0);
}
} }
boxWidgets_.clear();
const DataType type = (DataType) typeBox_->itemData(_typeIndex).toInt(); const DataType type = (DataType) typeBox_->itemData(_typeIndex).toInt();
for (int i=0; i < (int)supportedTypes_.size(); i++) for (int i=0; i < (int)supportedTypes_.size(); i++)
...@@ -173,12 +157,14 @@ void LoadWidget::slotSetLoadFilters(int _typeIndex){ ...@@ -173,12 +157,14 @@ void LoadWidget::slotSetLoadFilters(int _typeIndex){
setNameFilters(filters); setNameFilters(filters);
//add Widget for new Filter //add Widget for new Filter
if ( supportedTypes_[i].loadWidget != 0 ) { QWidget* nuWidget = 0;
boxLayout_->addWidget(supportedTypes_[i].loadWidget); nuWidget = supportedTypes_[i].plugin->loadOptionsWidget("");
// boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
if ( nuWidget != 0 ) {
boxLayout_->addWidget( nuWidget );
boxWidgets_.push_back( nuWidget );
box_->show(); box_->show();
} }
} }
if (box_->children().count() == 1) //only the layout is left if (box_->children().count() == 1) //only the layout is left
...@@ -189,17 +175,13 @@ void LoadWidget::slotSetLoadFilters(int _typeIndex){ ...@@ -189,17 +175,13 @@ void LoadWidget::slotSetLoadFilters(int _typeIndex){
void LoadWidget::slotSetSaveFilters(int _typeIndex){ void LoadWidget::slotSetSaveFilters(int _typeIndex){
box_->setTitle("Save Options"); box_->setTitle("Save Options");
for (int i=0; i < (int)supportedTypes_.size(); i++){ for (int i=0; i < boxWidgets_.size(); i++){
if (supportedTypes_[i].loadWidget != 0){ boxLayout_->removeWidget( boxWidgets_[i] );
boxLayout_->removeWidget(supportedTypes_[i].loadWidget); boxWidgets_[i]->setParent(0);
supportedTypes_[i].loadWidget->setParent(0);
}
if (supportedTypes_[i].saveWidget != 0){
boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
supportedTypes_[i].saveWidget->setParent(0);
}
} }
boxWidgets_.clear();
const DataType type = (DataType) typeBox_->itemData(_typeIndex).toInt(); const DataType type = (DataType) typeBox_->itemData(_typeIndex).toInt();
for (int i=0; i < (int)supportedTypes_.size(); i++) for (int i=0; i < (int)supportedTypes_.size(); i++)
if (supportedTypes_[i].type == type){ if (supportedTypes_[i].type == type){
...@@ -209,19 +191,15 @@ void LoadWidget::slotSetSaveFilters(int _typeIndex){ ...@@ -209,19 +191,15 @@ void LoadWidget::slotSetSaveFilters(int _typeIndex){
setNameFilters(filters); setNameFilters(filters);
//add Widget for new Filter //add Widget for new Filter
if ( supportedTypes_[i].saveWidget != 0 ) { QWidget* nuWidget = 0;
boxLayout_->addWidget(supportedTypes_[i].saveWidget); nuWidget = supportedTypes_[i].plugin->saveOptionsWidget("");
// boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
if ( nuWidget != 0 ) {
boxLayout_->addWidget( nuWidget );
boxWidgets_.push_back( nuWidget );
box_->show(); box_->show();
} }
} }
//remove Widget from last Filter
// if ( supportedTypes_[i].loadWidget != 0 ) {
// boxLayout_->removeWidget(supportedTypes_[i].loadWidget);
// boxLayout_->removeWidget(supportedTypes_[i].saveWidget);
// supportedTypes_[i].saveWidget->setParent(0);
// }
if (box_->children().count() == 1) //only the layout is left if (box_->children().count() == 1) //only the layout is left
box_->hide(); box_->hide();
......
...@@ -75,8 +75,9 @@ class LoadWidget : public QFileDialog ...@@ -75,8 +75,9 @@ class LoadWidget : public QFileDialog
QComboBox* typeBox_; QComboBox* typeBox_;
/// QFrame on the right /// QFrame on the right
QGroupBox* box_; QGroupBox* box_;
QHBoxLayout* boxLayout_; QHBoxLayout* boxLayout_;
QVector< QWidget* > boxWidgets_;
bool step_; bool step_;
......
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