/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Copyright (C) 2013 Frederik Heber. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * FileQtQuery.cpp * * Created on: Oct 25, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "CodePatterns/MemDebug.hpp" #include "UIElements/Qt4/Query/QtQuery.hpp" #include #include #include "Parameters/Validators/getFlatListFromHierarchyOfValidators.hpp" #include "Parameters/Validators/Validator.hpp" #include "Parameters/Validators/Specific/FilePresentValidator.hpp" #include "Parameters/Validators/Specific/FileSuffixValidator.hpp" #include "Parameters/Validators/Specific/ParserFileValidator.hpp" #include "Parser/ParserTypes.hpp" #include "Parser/FormatParserStorage.hpp" QtDialog::FileQtQuery::FileQtQuery(Parameter &_param, const std::string &_title, const std::string &_description, QBoxLayout *_parent, Dialog *_dialog) : QtQuery(_param, _title, _description), parent(_parent), dialog(_dialog), mustBePresent(false) { filenameLineEdit = new QLineEdit(); filenameLineEdit->setText(QString()); filenameLineEdit->setReadOnly(true); filenameLabel = new QLabel(QString(_title.c_str())); filenameLabel->setBuddy(filenameLineEdit); filenameLabel->setToolTip(QString(getDescription().c_str())); filedialogButton = new QPushButton("&Choose"); theFileDialog = NULL; thisLayout = new QHBoxLayout(); parent->addLayout(thisLayout); thisLayout->addWidget(filenameLabel); thisLayout->addWidget(filenameLineEdit); thisLayout->addWidget(filedialogButton); QObject::connect(filedialogButton,SIGNAL(clicked()),this,SLOT(showFileDialog())); // fill list of suffixes const Validator &validator = _param.getValidator(); typedef std::vector *, bool> > validators_t; const validators_t validators = getFlatListFromHierarchyOfValidators(validator); for (validators_t::const_iterator iter = validators.begin(); iter != validators.end(); ++iter) { const Validator< boost::filesystem::path > ¤tvalidator = *iter->first; if (dynamic_cast(¤tvalidator) != NULL) suffixes.push_back(dynamic_cast(currentvalidator).getSuffix()); if (dynamic_cast(¤tvalidator) != NULL) { const std::vector moresuffixes = dynamic_cast(currentvalidator).getSuffixes(); suffixes.insert(suffixes.end(), moresuffixes.begin(), moresuffixes.end()); } if (dynamic_cast(¤tvalidator) != NULL) mustBePresent = iter->second; } std::sort(suffixes.begin(), suffixes.end()); } QtDialog::FileQtQuery::~FileQtQuery() { if (theFileDialog != NULL) delete theFileDialog; } void QtDialog::FileQtQuery::onUpdate() { QStringList ListOfFilenames = theFileDialog->selectedFiles(); std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl; temp = ListOfFilenames.at(0).toStdString(); filenameLineEdit->setText(QString::fromStdString(temp.string())); dialog->update(); } void QtDialog::FileQtQuery::showFileDialog() { filedialogButton->setFlat(true); if (theFileDialog == NULL) { theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString()); // gather all possible suffixes QStringList filters; std::stringstream filter_string; if (!suffixes.empty()) { filter_string << "Valid files ("; for (std::vector::const_iterator iter = suffixes.begin(); iter != suffixes.end(); ++iter) filter_string << (iter == suffixes.begin() ? "*." : " *.") << *iter << " "; filter_string << ")"; filters << tr(filter_string.str().c_str()); } filters << tr("Any files (*)"); theFileDialog->setNameFilters(filters); theFileDialog->setAcceptMode(QFileDialog::AcceptOpen); theFileDialog->setFileMode(QFileDialog::AnyFile); theFileDialog->setViewMode(QFileDialog::List); } theFileDialog->exec(); onUpdate(); filedialogButton->setFlat(false); }