Back to index

fet  5.18.0
advancedfilterform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           advancedfilterform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 by Lalescu Liviu
00006     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "advancedfilterform.h"
00019 
00020 #include "timetable_defs.h"
00021 
00022 #include "centerwidgetonscreen.h"
00023 
00024 AdvancedFilterForm::AdvancedFilterForm(QWidget* parent, bool all, QList<int> descrDetDescr, QList<int> contNCont, QStringList text, bool caseSensitive, const QString& textToSettings): QDialog(parent)
00025 {
00026        atts=textToSettings;
00027 
00028        assert(descrDetDescr.count()==contNCont.count());
00029        assert(contNCont.count()==text.count());
00030        assert(text.count()>=ADVANCED_FILTER_MIN_ROWS && text.count()<=ADVANCED_FILTER_MAX_ROWS);
00031        
00032        rows=descrDetDescr.count();
00033        
00034        setWindowTitle(tr("Advanced filter for constraints"));
00035        
00036        allRadio=new QRadioButton(tr("Match all of the following:"));
00037        anyRadio=new QRadioButton(tr("Match any of the following:"));
00038        if(all)
00039               allRadio->setChecked(true);
00040        else
00041               anyRadio->setChecked(true);
00042        
00043        caseSensitiveCheckBox=new QCheckBox(tr("Case sensitive"));
00044        caseSensitiveCheckBox->setChecked(caseSensitive);
00045        
00046        caseSensitiveLayout=new QHBoxLayout();
00047        caseSensitiveLayout->addStretch();
00048        caseSensitiveLayout->addWidget(caseSensitiveCheckBox);
00049        
00050        allAnyLayout=new QVBoxLayout();
00051        allAnyLayout->addWidget(allRadio);
00052        allAnyLayout->addWidget(anyRadio);
00053        
00054        for(int i=0; i<ADVANCED_FILTER_MAX_ROWS; i++){
00055               QComboBox* cb1=new QComboBox();
00056               cb1->addItem(tr("Description"));
00057               cb1->addItem(tr("Detailed description"));
00058               if(i<rows)
00059                      cb1->setCurrentIndex(descrDetDescr.at(i));
00060               else
00061                      cb1->setCurrentIndex(0);
00062               
00063               QComboBox* cb2=new QComboBox();
00064               cb2->addItem(tr("Contains", "A text string contains other substring"));
00065               cb2->addItem(tr("Does not contain", "A text string does not contain other substring"));
00066               cb2->addItem(tr("Matches regular expr.", "A text string matches a regular expression (regexp)."
00067                      " Regular expressions are a complex notion, see definition on the internet if you don't know about them or how to translate the words.  "
00068                      "\nDefinition from Wikipedia: 'In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means "
00069                      "for identifying strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in "
00070                      "a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or "
00071                      "examines text and identifies parts that match the provided specification."));
00072               cb2->addItem(tr("Does not match reg. expr.", "A text string does not match a regular expression (regexp)."
00073                      " Regular expressions are a complex notion, see definition on the internet if you don't know about them or how to translate the words.  "
00074                      "\nDefinition from Wikipedia: 'In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means "
00075                      "for identifying strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in "
00076                      "a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or "
00077                      "examines text and identifies parts that match the provided specification."));
00078               if(i<rows)
00079                      cb2->setCurrentIndex(contNCont.at(i));
00080               else
00081                      cb2->setCurrentIndex(0);
00082               
00083               QLineEdit* ln1=new QLineEdit();
00084               if(i<rows)
00085                      ln1->setText(text.at(i));
00086               else
00087                      ln1->setText(QString(""));
00088               
00089               descrDetDescrComboBoxList.append(cb1);
00090               contNContReNReComboBoxList.append(cb2);
00091               textLineEditList.append(ln1);
00092        }
00093        
00094        filtersLayout=new QGridLayout();
00095 
00096        assert(descrDetDescrComboBoxList.count()==contNContReNReComboBoxList.count());
00097        assert(descrDetDescrComboBoxList.count()==textLineEditList.count());
00098        assert(descrDetDescrComboBoxList.count()==ADVANCED_FILTER_MAX_ROWS);
00099        for(int i=0; i<ADVANCED_FILTER_MAX_ROWS; i++){
00100               QComboBox* cb1=descrDetDescrComboBoxList.at(i);
00101               QComboBox* cb2=contNContReNReComboBoxList.at(i);
00102               QLineEdit* ln1=textLineEditList.at(i);
00103               
00104               filtersLayout->addWidget(cb1, i, 0);
00105               filtersLayout->addWidget(cb2, i, 1);
00106               filtersLayout->addWidget(ln1, i, 2);
00107        }
00108        
00109        morePushButton=new QPushButton(tr("More"));
00110        fewerPushButton=new QPushButton(tr("Fewer"));
00111        moreFewerLayout=new QHBoxLayout();
00112        moreFewerLayout->addWidget(morePushButton);
00113        moreFewerLayout->addWidget(fewerPushButton);
00114        moreFewerLayout->addStretch();
00115        morePushButton->setEnabled(rows<ADVANCED_FILTER_MAX_ROWS);
00116        fewerPushButton->setEnabled(rows>ADVANCED_FILTER_MIN_ROWS);
00117        
00118        resetPushButton=new QPushButton(tr("Reset"));
00119        okPushButton=new QPushButton(tr("OK"));
00120        okPushButton->setDefault(true);
00121        cancelPushButton=new QPushButton(tr("Cancel"));
00122        buttonsLayout=new QHBoxLayout();
00123        buttonsLayout->addWidget(resetPushButton);
00124        buttonsLayout->addStretch();
00125        buttonsLayout->addWidget(okPushButton);
00126        buttonsLayout->addWidget(cancelPushButton);
00127        
00128        layout=new QVBoxLayout(this);
00129        layout->addLayout(allAnyLayout);
00130        layout->addLayout(filtersLayout);
00131        layout->addLayout(moreFewerLayout);
00132        layout->addLayout(caseSensitiveLayout);
00133        layout->addStretch();
00134        layout->addLayout(buttonsLayout);
00135        
00136        connect(resetPushButton, SIGNAL(clicked()), this, SLOT(reset()));
00137        connect(okPushButton, SIGNAL(clicked()), this, SLOT(accept()));
00138        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(reject()));
00139        connect(morePushButton, SIGNAL(clicked()), this, SLOT(more()));
00140        connect(fewerPushButton, SIGNAL(clicked()), this, SLOT(fewer()));
00141        
00142        int w=this->sizeHint().width();
00143        int h=this->sizeHint().height();
00144        this->resize(w, h);
00145        centerWidgetOnScreen(this);
00146        restoreFETDialogGeometry(this, atts);
00147        
00148        for(int i=0; i<ADVANCED_FILTER_MAX_ROWS; i++){
00149               descrDetDescrComboBoxList.at(i)->setVisible(i<rows);
00150               contNContReNReComboBoxList.at(i)->setVisible(i<rows);
00151               textLineEditList.at(i)->setVisible(i<rows);
00152        }
00153 }
00154 
00155 AdvancedFilterForm::~AdvancedFilterForm()
00156 {
00157        saveFETDialogGeometry(this, atts);
00158 }
00159 
00160 void AdvancedFilterForm::reset()
00161 {
00162        assert(descrDetDescrComboBoxList.count()==contNContReNReComboBoxList.count());
00163        assert(descrDetDescrComboBoxList.count()==textLineEditList.count());
00164        assert(descrDetDescrComboBoxList.count()==ADVANCED_FILTER_MAX_ROWS);
00165        
00166        rows=1;
00167 
00168        fewerPushButton->setEnabled(rows>ADVANCED_FILTER_MIN_ROWS);
00169        morePushButton->setEnabled(rows<ADVANCED_FILTER_MAX_ROWS);
00170        
00171        for(int i=0; i<ADVANCED_FILTER_MAX_ROWS; i++){
00172               if(i<rows){
00173                      descrDetDescrComboBoxList.at(i)->setVisible(true);
00174               }
00175               else{
00176                      descrDetDescrComboBoxList.at(i)->setVisible(false);
00177               }
00178               descrDetDescrComboBoxList.at(i)->setCurrentIndex(0);
00179 
00180               if(i<rows){
00181                      contNContReNReComboBoxList.at(i)->setVisible(true);
00182               }
00183               else{
00184                      contNContReNReComboBoxList.at(i)->setVisible(false);
00185               }
00186               contNContReNReComboBoxList.at(i)->setCurrentIndex(0);
00187 
00188               if(i<rows){
00189                      textLineEditList.at(i)->setVisible(true);
00190               }
00191               else{
00192                      textLineEditList.at(i)->setVisible(false);
00193               }
00194               textLineEditList.at(i)->setText(QString(""));
00195        }
00196        
00197        allRadio->setChecked(true);
00198        
00199        caseSensitiveCheckBox->setChecked(false);
00200 }
00201 
00202 void AdvancedFilterForm::more()
00203 {
00204        assert(descrDetDescrComboBoxList.count()==contNContReNReComboBoxList.count());
00205        assert(descrDetDescrComboBoxList.count()==textLineEditList.count());
00206        assert(descrDetDescrComboBoxList.count()==ADVANCED_FILTER_MAX_ROWS);
00207        
00208        assert(rows<ADVANCED_FILTER_MAX_ROWS);
00209        
00210        descrDetDescrComboBoxList.at(rows)->setCurrentIndex(0);
00211        contNContReNReComboBoxList.at(rows)->setCurrentIndex(0);
00212        textLineEditList.at(rows)->setText(QString(""));
00213        
00214        descrDetDescrComboBoxList.at(rows)->setVisible(true);
00215        contNContReNReComboBoxList.at(rows)->setVisible(true);
00216        textLineEditList.at(rows)->setVisible(true);
00217        
00218        rows++;
00219        
00220        fewerPushButton->setEnabled(rows>ADVANCED_FILTER_MIN_ROWS);
00221        morePushButton->setEnabled(rows<ADVANCED_FILTER_MAX_ROWS);
00222 }
00223 
00224 void AdvancedFilterForm::fewer()
00225 {
00226        assert(descrDetDescrComboBoxList.count()==contNContReNReComboBoxList.count());
00227        assert(descrDetDescrComboBoxList.count()==textLineEditList.count());
00228        assert(descrDetDescrComboBoxList.count()==ADVANCED_FILTER_MAX_ROWS);
00229        
00230        assert(rows>ADVANCED_FILTER_MIN_ROWS);
00231        
00232        rows--;
00233        
00234        descrDetDescrComboBoxList.at(rows)->setCurrentIndex(0);
00235        contNContReNReComboBoxList.at(rows)->setCurrentIndex(0);
00236        textLineEditList.at(rows)->setText(QString(""));
00237        
00238        descrDetDescrComboBoxList.at(rows)->setVisible(false);
00239        contNContReNReComboBoxList.at(rows)->setVisible(false);
00240        textLineEditList.at(rows)->setVisible(false);
00241        
00242        fewerPushButton->setEnabled(rows>ADVANCED_FILTER_MIN_ROWS);
00243        morePushButton->setEnabled(rows<ADVANCED_FILTER_MAX_ROWS);
00244 }