Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/Query/FileQtQuery.cpp

    rf130d4 rf8bccc  
    4545#include "UIElements/Qt4/Query/QtQuery.hpp"
    4646
     47#include <algorithm>
     48#include <boost/filesystem.hpp>
     49
     50#include "Parameters/Validators/getFlatListFromHierarchyOfValidators.hpp"
     51#include "Parameters/Validators/Validator.hpp"
     52#include "Parameters/Validators/Specific/FilePresentValidator.hpp"
     53#include "Parameters/Validators/Specific/FileSuffixValidator.hpp"
     54#include "Parameters/Validators/Specific/ParserFileValidator.hpp"
    4755#include "Parser/ParserTypes.hpp"
    4856#include "Parser/FormatParserStorage.hpp"
     
    5159    QtQuery<boost::filesystem::path>(_param, _title, _description),
    5260    parent(_parent),
    53     dialog(_dialog)
     61    dialog(_dialog),
     62    mustBePresent(false)
    5463{
    5564  filenameLineEdit = new QLineEdit();
     
    5766  filenameLineEdit->setReadOnly(true);
    5867
    59   filenameLabel = new QLabel(QString("Input file:"));
     68  filenameLabel = new QLabel(QString(_title.c_str()));
    6069  filenameLabel->setBuddy(filenameLineEdit);
    6170  filenameLabel->setToolTip(QString(getDescription().c_str()));
     
    7180
    7281  QObject::connect(filedialogButton,SIGNAL(clicked()),this,SLOT(showFileDialog()));
     82
     83  // fill list of suffixes
     84  const Validator<boost::filesystem::path> &validator =
     85      _param.getValidator();
     86  typedef std::vector<std::pair<const Validator<boost::filesystem::path> *, bool> > validators_t;
     87  const validators_t validators =
     88      getFlatListFromHierarchyOfValidators<boost::filesystem::path>(validator);
     89  for (validators_t::const_iterator iter = validators.begin();
     90      iter != validators.end(); ++iter) {
     91    const Validator< boost::filesystem::path > &currentvalidator = *iter->first;
     92    if (dynamic_cast<const FileSuffixValidator * const>(&currentvalidator) != NULL)
     93      suffixes.push_back(dynamic_cast<const FileSuffixValidator &>(currentvalidator).getSuffix());
     94    if (dynamic_cast<const ParserFileValidator * const>(&currentvalidator) != NULL) {
     95      const std::vector<std::string> moresuffixes =
     96          dynamic_cast<const ParserFileValidator &>(currentvalidator).getSuffixes();
     97      suffixes.insert(suffixes.end(), moresuffixes.begin(), moresuffixes.end());
     98    }
     99    if (dynamic_cast<const FilePresentValidator * const>(&currentvalidator) != NULL)
     100      mustBePresent = iter->second;
     101  }
     102  std::sort(suffixes.begin(), suffixes.end());
    73103}
    74104
     
    93123    // gather all possible suffixes
    94124    QStringList filters;
    95     std::stringstream parsersuffixes;
    96     parsersuffixes << std::string("Config files (");
    97     for (ParserTypes t = ParserTypes_begin; t < ParserTypes_end; ++t){
    98       if (t != ParserTypes_begin)
    99         parsersuffixes << std::string(" ");
    100       parsersuffixes << std::string("*.") <<
    101           FormatParserStorage::getInstance().getSuffixFromType(t);
     125    std::stringstream filter_string;
     126    if (!suffixes.empty()) {
     127      filter_string << "Valid files (";
     128      for (std::vector<std::string>::const_iterator iter = suffixes.begin();
     129          iter != suffixes.end(); ++iter)
     130        filter_string << (iter == suffixes.begin() ? "*." : " *.") << *iter << " ";
     131      filter_string << ")";
     132      filters << tr(filter_string.str().c_str());
    102133    }
    103     parsersuffixes << std::string(")");
    104     filters << tr(parsersuffixes.str().c_str());
    105     filters << tr("Data files (*.dat)");
    106134    filters << tr("Any files (*)");
    107135    theFileDialog->setNameFilters(filters);
Note: See TracChangeset for help on using the changeset viewer.