Child: [94da03] (diff)

Download this file

searchclause_w.cpp    162 lines (144 with data), 4.5 kB

  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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Copyright (C) 2005 J.F.Dockes
* This program 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.
*
* This program 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 this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include "recoll.h"
#include "searchclause_w.h"
#include <qvariant.h>
#include <qcombobox.h>
#include <qspinbox.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
/*
* Constructs a SearchClauseW as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*/
SearchClauseW::SearchClauseW(QWidget* parent)
: QWidget(parent)
{
QHBoxLayout* hLayout = new QHBoxLayout(this);
sTpCMB = new QComboBox(this);
sTpCMB->setEditable(false);
hLayout->addWidget(sTpCMB);
fldCMB = new QComboBox(this);
fldCMB->setEditable(false);
hLayout->addWidget(fldCMB);
proxSlackSB = new QSpinBox(this);
hLayout->addWidget(proxSlackSB);
wordsLE = new QLineEdit(this);
wordsLE->setMinimumSize(QSize(250, 0));
hLayout->addWidget(wordsLE);
languageChange();
resize(QSize(0, 0).expandedTo(minimumSizeHint()));
connect(sTpCMB, SIGNAL(activated(int)), this, SLOT(tpChange(int)));
}
/*
* Destroys the object and frees any allocated resources
*/
SearchClauseW::~SearchClauseW()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void SearchClauseW::languageChange()
{
sTpCMB->clear();
sTpCMB->addItem(tr("Any of these")); // 0
sTpCMB->addItem(tr("All of these")); //1
sTpCMB->addItem(tr("None of these"));//2
sTpCMB->addItem(tr("This phrase"));//3
sTpCMB->addItem(tr("Terms in proximity"));//4
sTpCMB->addItem(tr("File name matching"));//5
// sTpCMB->insertItem(tr("Complex clause"));//6
fldCMB->addItem(tr("In field"));
if (theconfig) {
set<string> fields = theconfig->getIndexedFields();
for (set<string>::const_iterator it = fields.begin();
it != fields.end(); it++) {
// Some fields don't make sense here
if (it->compare("filename")) {
fldCMB->addItem(QString::fromUtf8(it->c_str()));
}
}
}
// Ensure that the spinbox will be enabled/disabled depending on
// combobox state
tpChange(0);
sTpCMB->setToolTip(tr("Select the type of query that will be performed with the words"));
proxSlackSB->setToolTip(tr("Number of additional words that may be interspersed with the chosen ones"));
}
using namespace Rcl;
// Translate my window state into an Rcl search clause
SearchDataClause *
SearchClauseW::getClause()
{
if (wordsLE->text().isEmpty())
return 0;
string field;
if (fldCMB->currentIndex() != 0) {
field = (const char *)fldCMB->currentText().toUtf8();
}
string text = (const char *)wordsLE->text().toUtf8();
switch (sTpCMB->currentIndex()) {
case 0:
return new SearchDataClauseSimple(SCLT_OR, text, field);
case 1:
return new SearchDataClauseSimple(SCLT_AND, text, field);
case 2:
return new SearchDataClauseSimple(SCLT_EXCL, text, field);
case 3:
return new SearchDataClauseDist(SCLT_PHRASE, text,
proxSlackSB->value(), field);
case 4:
return new SearchDataClauseDist(SCLT_NEAR, text,
proxSlackSB->value(), field);
case 5:
return new SearchDataClauseFilename(text);
case 6:
default:
return 0;
}
}
// Handle combobox change: may need to enable/disable the distance
// spinbox and field spec
void SearchClauseW::tpChange(int index)
{
if (index < 0 || index > 5)
return;
if (sTpCMB->currentIndex() != index)
sTpCMB->setCurrentIndex(index);
switch (index) {
case 3:
case 4:
proxSlackSB->show();
proxSlackSB->setEnabled(true);
if (index == 4)
proxSlackSB->setValue(10);
break;
default:
proxSlackSB->close();
}
if (index == 5) {
fldCMB->close();
} else {
fldCMB->show();
}
}