"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bSearchInFilesPattern.cpp" (12 Feb 2021, 3607 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "c2bSearchInFilesPattern.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "c2bSearchInFilesPattern.h"
    8 
    9 #include "c2b.h"
   10 #include "c2bBibParser.h"
   11 #include "c2bSettings.h"
   12 
   13 #include <searchPattern.h>
   14 
   15 #include <QTreeWidgetItem>
   16 
   17 
   18 c2bSearchInFilesPattern::c2bSearchInFilesPattern(QWidget* parentw) : QWidget(parentw)
   19 {
   20     ui.setupUi(this);
   21     c2bBibParser* bp = c2b::bibParser();
   22     ui.patternType->addItems(searchPattern::types());
   23     ui.patternType->setCurrentIndex(c2bSettingsP->value("c2bSearchInFiles/PatternTypeIndex", 0).toInt());
   24     ui.patternScope->addItems(bp->sortedBibliographicFields());
   25     ui.yearScope->hide();
   26     ui.inputPattern->setFocus();
   27 
   28     connect(ui.clearB, SIGNAL(clicked()), this, SLOT(patternChanged()));
   29     connect(ui.inputPattern, SIGNAL(textEdited(QString)), this, SLOT(patternChanged()));
   30     connect(ui.patternScope, SIGNAL(currentIndexChanged(QString)), this, SLOT(showYearScope(QString)));
   31 }
   32 
   33 c2bSearchInFilesPattern::~c2bSearchInFilesPattern()
   34 {
   35     c2bSettingsP->setValue("c2bSearchInFiles/PatternTypeIndex", ui.patternType->currentIndex());
   36 }
   37 
   38 
   39 void c2bSearchInFilesPattern::patternChanged()
   40 {
   41     emit patternAvailable(isAvailable());
   42 }
   43 
   44 void c2bSearchInFilesPattern::setText(const QString& text)
   45 {
   46     ui.inputPattern->setText(text);
   47     ui.inputPattern->setFocus();
   48 }
   49 
   50 void c2bSearchInFilesPattern::clear()
   51 {
   52     ui.inputPattern->clear();
   53     ui.inputPattern->setFocus();
   54 }
   55 
   56 void c2bSearchInFilesPattern::setPattern(QTreeWidgetItem* pattern)
   57 {
   58     if (!pattern)
   59         return;
   60     if (pattern->columnCount() != ITEMS_IN_SEARCH_PATTERN)
   61         return;
   62 
   63     if (pattern->text(0) == "NOT")
   64         ui.NOT->setChecked(true);
   65     else
   66         ui.NOT->setChecked(false);
   67     if (pattern->text(1) == "Sensitive")
   68         ui.caseSensitive->setChecked(true);
   69     else
   70         ui.caseSensitive->setChecked(false);
   71     ui.patternType->setCurrentIndex(ui.patternType->findText(pattern->text(2)));
   72     ui.patternScope->setCurrentIndex(ui.patternScope->findText(pattern->text(3)));
   73     if (pattern->text(4) == "=")
   74         ui.yearScope->setCurrentIndex(ui.yearScope->findText("Exact"));
   75     else if (pattern->text(4) == ">")
   76         ui.yearScope->setCurrentIndex(ui.yearScope->findText("Newer"));
   77     else
   78         ui.yearScope->setCurrentIndex(ui.yearScope->findText("Older"));
   79     ui.inputPattern->setText(pattern->text(5));
   80 }
   81 
   82 const QStringList c2bSearchInFilesPattern::patterns()
   83 {
   84     QStringList p;
   85     if (ui.NOT->isChecked())
   86         p.append("NOT");
   87     else
   88         p.append(QString());
   89     if (ui.caseSensitive->isChecked())
   90         p.append("Sensitive");
   91     else
   92         p.append("Insensitive");
   93     p.append(ui.patternType->currentText());
   94     p.append(ui.patternScope->currentText());
   95     if (ui.yearScope->isHidden())
   96         p.append(" ");
   97     else if (ui.yearScope->currentText() == "Exact")
   98         p.append("=");
   99     else if (ui.yearScope->currentText() == "Newer")
  100         p.append(">");
  101     else if (ui.yearScope->currentText() == "Older")
  102         p.append("<");
  103     p.append(ui.inputPattern->text());
  104     return p;
  105 }
  106 
  107 void c2bSearchInFilesPattern::showYearScope(const QString& scope)
  108 {
  109     if (scope == "year")
  110         ui.yearScope->show();
  111     else
  112         ui.yearScope->hide();
  113 }
  114 
  115 void c2bSearchInFilesPattern::setFocus()
  116 {
  117     ui.inputPattern->setFocus();
  118 }