Changeset dae158 for src


Ignore:
Timestamp:
Sep 8, 2014, 9:37:32 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
95cfac
Parents:
ce4126
git-author:
Frederik Heber <heber@…> (09/07/14 17:44:06)
git-committer:
Frederik Heber <heber@…> (09/08/14 21:37:32)
Message:

FileQtQuery retrieves valid suffixes from validators.

  • added getFlatListFromHierarchyOfValidators() that steps through the hierarchy of validators and generates a flat vector with all matching types.
  • Or_Validatorm Not_Validator::getA(), ::getB() added. (present for And_... already).
  • FileSuffixValidator::getSuffix(), ParserFileValidator::getSuffixes() added.
Location:
src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/Makefile.am

    rce4126 rdae158  
    3939        Parameters/Validators/GenericValidators.hpp \
    4040        Parameters/Validators/GenericValidators_impl.hpp \
     41        Parameters/Validators/getFlatListFromHierarchyOfValidators.hpp \
    4142        Parameters/Validators/Ops_Validator.hpp \
    4243        Parameters/Validators/Ops_Validator_impl.hpp \
  • src/Parameters/Validators/Ops_Validator_impl.hpp

    rce4126 rdae158  
    5252  Validator<T> *getA(){ return a; }
    5353  Validator<T> *getB(){ return b; }
     54  const Validator<T> *getA() const { return a; }
     55  const Validator<T> *getB() const { return b; }
    5456
    5557private:
     
    9092  }
    9193
     94  Validator<T> *getA(){ return a; }
     95  Validator<T> *getB(){ return b; }
     96  const Validator<T> *getA() const { return a; }
     97  const Validator<T> *getB() const { return b; }
     98
    9299private:
    93100  Validator<T> *a;
     
    126133  }
    127134
     135  Validator<T> *getA(){ return a; }
     136  const Validator<T> *getA() const { return a; }
     137
    128138private:
    129139  Validator<T> *a;
  • src/Parameters/Validators/Specific/FileSuffixValidator.hpp

    rce4126 rdae158  
    3333  Validator< boost::filesystem::path >* clone() const;
    3434
     35  const std::string & getSuffix() const
     36  { return suffix; }
     37
    3538private:
    3639  std::string suffix;
  • src/Parameters/Validators/Specific/ParserFileValidator.cpp

    rce4126 rdae158  
    7272}
    7373
     74std::vector<std::string> ParserFileValidator::getSuffixes() const
     75{
     76  std::vector<std::string> suffixes;
     77  for (ParserTypes t = ParserTypes_begin; t < ParserTypes_end; ++ t){
     78    suffixes.push_back(
     79        FormatParserStorage::getInstance().getSuffixFromType(t));
     80  }
     81  return suffixes;
     82}
    7483
    7584
    76 
  • src/Parameters/Validators/Specific/ParserFileValidator.hpp

    rce4126 rdae158  
    2727  bool operator==(const Validator<boost::filesystem::path> &_instance) const;
    2828  Validator< boost::filesystem::path >* clone() const;
     29
     30public:
     31  std::vector<std::string> getSuffixes() const;
    2932};
    3033
  • src/Parameters/Validators/Validator.hpp

    rce4126 rdae158  
    3535};
    3636
    37 
    3837#endif /* VALIDATOR_HPP_ */
  • src/UIElements/Qt4/Query/FileQtQuery.cpp

    rce4126 rdae158  
    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();
     
    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);
  • src/UIElements/Qt4/Query/QtQuery.hpp

    rce4126 rdae158  
    211211  QFileDialog *theFileDialog;
    212212  Dialog *dialog;
     213  std::vector<std::string> suffixes;
     214  bool mustBePresent;
    213215};
    214216
Note: See TracChangeset for help on using the changeset viewer.