File: c2bSearchInFilesPattern.cpp

package info (click to toggle)
cb2bib 1.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,368 kB
  • sloc: cpp: 24,179; sh: 481; makefile: 16
file content (118 lines) | stat: -rw-r--r-- 3,628 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/***************************************************************************
 *   Copyright (C) 2004-2015 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.9.2. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "c2bSearchInFilesPattern.h"

#include "c2b.h"
#include "c2bBibParser.h"
#include "c2bSettings.h"

#include <searchPattern.h>

#include <QTreeWidgetItem>


c2bSearchInFilesPattern::c2bSearchInFilesPattern(QWidget* parentw) : QWidget(parentw)
{
    ui.setupUi(this);
    c2bBibParser* bp = c2b::bibParser();
    ui.patternType->addItems(searchPattern::types());
    ui.patternType->setCurrentIndex(c2bSettingsP->value("c2bSearchInFiles/PatternTypeIndex", 0).toInt());
    ui.patternScope->addItems(bp->sortedBibliographicFields());
    ui.yearScope->hide();
    ui.inputPattern->setFocus();

    connect(ui.clearB, SIGNAL(clicked()), this, SLOT(patternChanged()));
    connect(ui.inputPattern, SIGNAL(textEdited(const QString&)), this, SLOT(patternChanged()));
    connect(ui.patternScope, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(showYearScope(const QString&)));
}

c2bSearchInFilesPattern::~c2bSearchInFilesPattern()
{
    c2bSettingsP->setValue("c2bSearchInFiles/PatternTypeIndex", ui.patternType->currentIndex());
}


void c2bSearchInFilesPattern::patternChanged()
{
    emit patternAvailable(isAvailable());
}

void c2bSearchInFilesPattern::setText(const QString& text)
{
    ui.inputPattern->setText(text);
    ui.inputPattern->setFocus();
}

void c2bSearchInFilesPattern::clear()
{
    ui.inputPattern->clear();
    ui.inputPattern->setFocus();
}

void c2bSearchInFilesPattern::setPattern(QTreeWidgetItem* pattern)
{
    if (!pattern)
        return;
    if (pattern->columnCount() != ITEMS_IN_SEARCH_PATTERN)
        return;

    if (pattern->text(0) == "NOT")
        ui.NOT->setChecked(true);
    else
        ui.NOT->setChecked(false);
    if (pattern->text(1) == "Sensitive")
        ui.caseSensitive->setChecked(true);
    else
        ui.caseSensitive->setChecked(false);
    ui.patternType->setCurrentIndex(ui.patternType->findText(pattern->text(2)));
    ui.patternScope->setCurrentIndex(ui.patternScope->findText(pattern->text(3)));
    if (pattern->text(4) == "=")
        ui.yearScope->setCurrentIndex(ui.yearScope->findText("Exact"));
    else if (pattern->text(4) == ">")
        ui.yearScope->setCurrentIndex(ui.yearScope->findText("Newer"));
    else
        ui.yearScope->setCurrentIndex(ui.yearScope->findText("Older"));
    ui.inputPattern->setText(pattern->text(5));
}

const QStringList c2bSearchInFilesPattern::patterns()
{
    QStringList p;
    if (ui.NOT->isChecked())
        p.append("NOT");
    else
        p.append(QString());
    if (ui.caseSensitive->isChecked())
        p.append("Sensitive");
    else
        p.append("Insensitive");
    p.append(ui.patternType->currentText());
    p.append(ui.patternScope->currentText());
    if (ui.yearScope->isHidden())
        p.append(" ");
    else if (ui.yearScope->currentText() == "Exact")
        p.append("=");
    else if (ui.yearScope->currentText() == "Newer")
        p.append(">");
    else if (ui.yearScope->currentText() == "Older")
        p.append("<");
    p.append(ui.inputPattern->text());
    return p;
}

void c2bSearchInFilesPattern::showYearScope(const QString& scope)
{
    if (scope == "year")
        ui.yearScope->show();
    else
        ui.yearScope->hide();
}

void c2bSearchInFilesPattern::setFocus()
{
    ui.inputPattern->setFocus();
}