-
Notifications
You must be signed in to change notification settings - Fork 1
/
searchformcontroller.cpp
173 lines (145 loc) · 5.69 KB
/
searchformcontroller.cpp
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
162
163
164
165
166
167
168
169
170
171
172
#include "searchformcontroller.h"
#include "vlastnicisearchform.h"
#include "parcelysearchform.h"
#include "budovysearchform.h"
#include "jednotkysearchform.h"
#include <QDebug>
#include <QUrl>
#include <QRegExp>
#include <QStandardItemModel>
#include <QComboBox>
#include <QPushButton>
#include <QStackedWidget>
SearchFormController::SearchFormController(const MainControls &mainControls, const SearchForms &searchForms, QObject *parent)
: QObject( parent ), controls( mainControls ), forms( searchForms )
{
controls.formComboBox->addItem( QObject::trUtf8( "vlastníky" ), Vlastnici );
controls.formComboBox->addItem( QObject::trUtf8( "parcely" ), Parcely );
controls.formComboBox->addItem( QObject::trUtf8( "budovy" ), Budovy );
controls.formComboBox->addItem( QObject::trUtf8( "jednotky" ), Jednotky );
connect( controls.formComboBox, SIGNAL( activated( int ) ), controls.searchForms, SLOT( setCurrentIndex( int ) ) );
connect( controls.searchButton, SIGNAL( clicked() ), this, SLOT( search() ) );
controls.searchForms->setCurrentIndex( 0 );
controls.searchButton->setEnabled( false );
}
void SearchFormController::setConnectionName(const QString &connectionName)
{
mConnectionName = connectionName;
initComboBoxModels();
controls.searchButton->setEnabled( true );
}
void SearchFormController::search()
{
Form form = Form( controls.formComboBox->itemData( controls.formComboBox->currentIndex() ).toInt() );
QApplication::setOverrideCursor( Qt::WaitCursor );
qApp->processEvents();
switch( form )
{
case Parcely:
searchParcely();
break;
case Budovy:
searchBudovy();
break;
case Jednotky:
searchJednotky();
break;
case Vlastnici:
searchVlastnici();
break;
default:
break;
}
QApplication::restoreOverrideCursor();
}
void SearchFormController::searchVlastnici()
{
QString jmeno = forms.vlastnici->jmeno();
QString rcIco = forms.vlastnici->rcIco();
QString lv = forms.vlastnici->lv();
bool sjm = forms.vlastnici->isSjm();
bool opo = forms.vlastnici->isOpo();
bool ofo = forms.vlastnici->isOfo();
QUrl url = QString( "showText?page=search&type=vlastnici&jmeno=%1&rcIco=%2&sjm=%3&opo=%4&ofo=%5&lv=%6" )
.arg( jmeno ).arg( rcIco ).arg( sjm ? 1 : 0 ).arg( opo ? 1 : 0 ).arg( ofo ? 1 : 0 ).arg( lv );
emit actionTriggered( url );
}
void SearchFormController::searchParcely()
{
QString parcelniCislo = forms.parcely->parcelniCislo();
int typ = forms.parcely->typParcely();
QString druh = forms.parcely->druhPozemkuKod();
QString lv = forms.parcely->lv();
QUrl url = QString( "showText?page=search&type=parcely&parcelniCislo=%1&typ=%2&druh=%3&lv=%4" )
.arg( parcelniCislo ).arg( typ ).arg( druh ).arg( lv );
emit actionTriggered( url );
}
void SearchFormController::searchBudovy()
{
QString domovniCislo = forms.budovy->domovniCislo();
QString naParcele = forms.budovy->naParcele();
QString zpusobVyuziti = forms.budovy->zpusobVyuzitiKod();
QString lv = forms.budovy->lv();
QUrl url = QString( "showText?page=search&type=budovy&domovniCislo=%1&naParcele=%2&zpusobVyuziti=%3&lv=%4" )
.arg( domovniCislo ).arg( naParcele ).arg( zpusobVyuziti ).arg( lv );
qDebug()<< url;
emit actionTriggered( url );
}
void SearchFormController::searchJednotky()
{
QString cisloJednotky = forms.jednotky->cisloJednotky();
QString domovniCislo = forms.jednotky->domovniCislo();
QString naParcele = forms.jednotky->naParcele();
QString zpusobVyuziti = forms.jednotky->zpusobVyuzitiKod();
QString lv = forms.jednotky->lv();
QUrl url = QString( "showText?page=search&type=jednotky&"
"cisloJednotky=%1&domovniCislo=%2&naParcele=%3&zpusobVyuziti=%4&lv=%5" )
.arg( cisloJednotky ).arg( domovniCislo ).arg( naParcele ).arg( zpusobVyuziti ).arg( lv );
qDebug()<< url;
emit actionTriggered( url );
}
void SearchFormController::initComboBoxModels()
{
mDruhParcely = new VfkTableModel( mConnectionName, this );
mDruhParcely->druhyPozemku();
mDruhPozemkoveParcely = new VfkTableModel( mConnectionName, this );
mDruhPozemkoveParcely->druhyPozemku( true, false );
mDruhStavebniParcely = new VfkTableModel( mConnectionName, this );
mDruhStavebniParcely->druhyPozemku( false, true );
mZpusobVyuzitiBudovy = new VfkTableModel( mConnectionName, this );
mZpusobVyuzitiBudovy->zpusobVyuzitiBudov();
mZpusobVyuzitiJednotek = new VfkTableModel( mConnectionName, this );
mZpusobVyuzitiJednotek->zpusobVyuzitiJednotek();
QString falseKodForDefaultDruh = "";
QString text = trUtf8( "libovolný" );
QList<QString> fakeRow;
fakeRow << falseKodForDefaultDruh << text;
forms.parcely->setDruhPozemkuModel( addFirstRowToModel( mDruhParcely, fakeRow ) );
forms.parcely->setDruhPozemkuPozemkovaModel( addFirstRowToModel( mDruhPozemkoveParcely, fakeRow ) );
forms.parcely->setDruhPozemkuStavebniModel( mDruhStavebniParcely );
forms.budovy->setZpusobVyuzitiModel( addFirstRowToModel( mZpusobVyuzitiBudovy, fakeRow ) );
forms.jednotky->setZpusobVyuzitiModel( addFirstRowToModel( mZpusobVyuzitiJednotek, fakeRow ) );
}
QStandardItemModel *SearchFormController::addFirstRowToModel(QAbstractItemModel *oldModel, QList<QString> newRow)
{
QStandardItemModel *model = new QStandardItemModel( this );
QList< QStandardItem * > items;
foreach ( QString str, newRow )
{
items << new QStandardItem( str );
}
model->appendRow(items);
for ( int i = 0; i < oldModel->rowCount(); i++ )
{
QList< QStandardItem * > items;
for ( int j = 0; j < oldModel->columnCount(); j++ )
{
QModelIndex index = oldModel->index(i, j);
QVariant data = oldModel->data( index );
QStandardItem *item = new QStandardItem( data.toString() );
items << item;
}
model->appendRow( items );
}
return model;
}