1
/* ****************************************************************************
2
This file is part of KAider
4
Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
In addition, as a special exception, the copyright holders give
21
permission to link the code of this program with any edition of
22
the Qt library by Trolltech AS, Norway (or with modified versions
23
of Qt that use the same license as Qt), and distribute linked
24
combinations including the two. You must obey the GNU General
25
Public License in all respects for all of the code used other than
26
Qt. If you modify this file, you may extend this exception to
27
your version of the file, but you are not obligated to do so. If
28
you do not wish to do so, delete this exception statement from
31
**************************************************************************** */
34
#include "ui_queryoptions.h"
36
#include "dbfilesmodel.h"
39
#include <kstandarddirs.h>
43
#include <QSqlQueryModel>
44
#include <QButtonGroup>
47
TMDBModel::TMDBModel(QObject* parent)
48
: QSqlQueryModel(parent)
49
, m_queryType(WordOrder)
51
setHeaderData(0, Qt::Horizontal, i18nc("@title:column Original text","Original"));
52
setHeaderData(1, Qt::Horizontal, i18nc("@title:column Text in target language","Target"));
55
void TMDBModel::setDB(const QString& str)
57
m_db=QSqlDatabase::database(str);
60
void TMDBModel::setQueryType(int type)
62
m_queryType=(QueryType)type;
65
void TMDBModel::setFilter(const QString& str)
68
escaped.replace('\'',"''");
70
if (m_queryType==SubStr)
72
setQuery("SELECT tm_main.english, tm_main.target FROM tm_main "
73
"WHERE tm_main.english LIKE '%"+escaped+"%' "
74
"OR tm_main.target LIKE '%"+escaped+"%' "
76
"SELECT tm_main.english, tm_dups.target FROM tm_main, tm_dups "
77
"WHERE tm_main.id==tm_dups.id "
78
"AND (tm_main.english LIKE '%"+escaped+"%' "
79
"OR tm_dups.target LIKE '%"+escaped+"%') "
80
/*"ORDER BY tm_main.english"*/ ,m_db);
82
else if (m_queryType==WordOrder)
84
QStringList strList=str.split(QRegExp("\\W"),QString::SkipEmptyParts);
85
setQuery("SELECT tm_main.english, tm_main.target FROM tm_main "
86
"WHERE tm_main.english LIKE '%"+
87
strList.join("%' AND tm_main.english LIKE '%")+
90
"SELECT tm_main.english, tm_main.target FROM tm_main "
91
"WHERE tm_main.target LIKE '%"+
92
strList.join("%' AND tm_main.target LIKE '%")+
95
"SELECT tm_main.english, tm_dups.target FROM tm_main, tm_dups "
96
"WHERE tm_main.id==tm_dups.id "
97
"AND tm_main.english LIKE '%"+
98
strList.join("%' AND tm_main.english LIKE '%")+
101
"SELECT tm_main.english, tm_dups.target FROM tm_main, tm_dups "
102
"WHERE tm_main.id==tm_dups.id "
103
"AND tm_dups.target LIKE '%"+
104
strList.join("%' AND tm_dups.target LIKE '%")+
106
/*"ORDER BY tm_main.english"*/ ,m_db);
111
setQuery("SELECT tm_main.english, tm_main.target FROM tm_main "
112
"WHERE tm_main.english GLOB '*"+escaped+"*' "
113
"OR tm_main.target GLOB '*"+escaped+"*' "
115
"SELECT tm_main.english, tm_dups.target FROM tm_main, tm_dups "
116
"WHERE tm_main.id==tm_dups.id "
117
"AND (tm_main.english GLOB '*"+escaped+"*' "
118
"OR tm_dups.target GLOB '*"+escaped+"*') "
119
/*"ORDER BY tm_main.english"*/ ,m_db);
131
TMWindow::TMWindow(QWidget *parent)
132
: KMainWindow(parent)
134
setCaption(i18nc("@title:window","Translation Memory Query"),false);
136
QWidget* w=new QWidget(this);
137
Ui_QueryOptions ui_queryOptions;
138
ui_queryOptions.setupUi(w);
141
connect(ui_queryOptions.query,SIGNAL(returnPressed()),
142
this,SLOT(performQuery()));
144
QTreeView* view=ui_queryOptions.treeView;
145
m_query=ui_queryOptions.query;
147
m_model = new TMDBModel(this);
148
m_model->setDB(Project::instance()->projectID());
150
view->setModel(m_model);
152
QButtonGroup* btnGrp=new QButtonGroup(this);
153
btnGrp->addButton(ui_queryOptions.substr,(int)TMDBModel::SubStr);
154
btnGrp->addButton(ui_queryOptions.like,(int)TMDBModel::WordOrder);
155
btnGrp->addButton(ui_queryOptions.rx,(int)TMDBModel::RegExp);
156
connect(btnGrp,SIGNAL(buttonClicked(int)),
157
m_model,SLOT(setQueryType(int)));
159
ui_queryOptions.db->setModel(DBFilesModel::instance());
160
ui_queryOptions.db->setCurrentIndex(ui_queryOptions.db->findText(Project::instance()->projectID()));
161
connect(ui_queryOptions.db,SIGNAL(currentIndexChanged(QString)),
162
m_model,SLOT(setDB(QString)));
164
m_dbCombo=ui_queryOptions.db;
166
m_dbCombo->setCurrentIndex(m_dbCombo->findText(Project::instance()->projectID()));
169
TMWindow::~TMWindow()
173
void TMWindow::selectDB(int i)
175
m_dbCombo->setCurrentIndex(i);
178
void TMWindow::performQuery()
180
m_model->setFilter(m_query->text());
183
void TMWindow::setOptions(int i)