-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddmWidget.cpp
174 lines (138 loc) · 4.93 KB
/
ddmWidget.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
173
174
#include <QDir>
#include <QMessageBox>
#include <QPointF>
#include <QResizeEvent>
#include <QWebFrame>
#include "ui_ddmwidget.h"
#include "ddmWidget.h"
#include "ddmModel.h"
#include "ddmMapViewPage.h"
#include "ddmInfoWindowWidget.h"
#include "ddmEmptyfilter.h"
#include "ddmFrictionCountyFilter.h"
#include "ddmMigrationCountyFilter.h"
ddmWidget::ddmWidget( ddmModel* model, QWidget* parent ) : QWidget( parent ),
ui( new Ui::ddmWidget ),
m_model( model )
{
ui->setupUi( this );
m_infoWindow = new ddmInfoWindowWidget( this );
ui->m_vlPlainTextEditContainer->addWidget( m_infoWindow );
m_curWidget = NULL;
ddmMapView* mapView = this->mapView();
ddmMapViewPage* mapPage = new ddmMapViewPage;
mapView->setPage( mapPage );
// устанавливаем соединение с БД
QString pathToDb = QObject::tr( "%1/ddm.sqlite" ).arg( QApplication::applicationDirPath() );
if ( !QFile::exists( pathToDb ) )
{
// Если в текущем каталоге БД нет, то ищем в родительских
pathToDb = QObject::tr( "%1/../../ddm.sqlite" ).arg( QApplication::applicationDirPath() );
}
this->model()->openDatabase( pathToDb );
// устанавливаем страницу для отображения google maps
QString pathToWeb = QObject::tr( "%1/index.html" ).arg( QApplication::applicationDirPath() );
if ( !QFile::exists( pathToWeb ) )
{
// Если в текущем каталоге БД нет, то ищем в родительских
pathToWeb = QObject::tr( "%1/../../index.html" ).arg( QApplication::applicationDirPath() );
}
QUrl url = QUrl::fromLocalFile( pathToWeb );
this->mapView()->setUrl( url );
fillFiltersList();
installEvents();
slotSetCurrentFilter( DDM_EMPTY_FILTER );
}
ddmWidget::~ddmWidget()
{
delete ui;
delete m_curWidget;
delete m_infoWindow;
}
void ddmWidget::installEvents()
{
connect( this->ui->m_map->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( slotInjectModel() ) );
connect( this->model(), SIGNAL( changedCoords( const QString& ,const QString& ) ), this, SLOT( changedCoords( const QString& ,const QString& ) ) );
connect( ui->m_cmbFilter, SIGNAL( activated ( int ) ), this, SLOT( slotSetCurrentFilter( int ) ));
}
void ddmWidget::slotInjectModel()
{
ui->m_map->page()->mainFrame()->addToJavaScriptWindowObject( "ddm_model", this->model() );
}
void ddmWidget::changedCoords( const QString& lat, const QString& lng )
{
if( lat.isEmpty() || lng.isEmpty() )
return;
emit changedStatusBarCoords( lat, lng );
}
void ddmWidget::slotSetCurrentFilter( int index )
{
if( m_curWidget )
{
ui->m_widgetContainerLayout->removeWidget( m_curWidget );
m_curWidget->hide();
m_curWidget = NULL;
}
if( index == DDM_EMPTY_FILTER )
{
m_curWidget = m_filters.at( DDM_EMPTY_FILTER )->getWidget();
m_curWidget->setParent( this );
m_curWidget->show();
ui->m_widgetContainerLayout->addWidget( m_curWidget );
}
else if( index == DDM_FRICTION_COUNTY_FILTER )
{
m_curWidget = m_filters.at( DDM_FRICTION_COUNTY_FILTER )->getWidget();
m_curWidget->setParent( this );
m_curWidget->show();
ui->m_widgetContainerLayout->addWidget( m_curWidget );
}
else if( index == DDM_MIGRATION_COUNTY_FILTER )
{
m_curWidget = m_filters.at( DDM_MIGRATION_COUNTY_FILTER )->getWidget();
m_curWidget->setParent( this );
m_curWidget->show();
ui->m_widgetContainerLayout->addWidget( m_curWidget );
}
}
void ddmWidget::fillFiltersList()
{
ui->m_cmbFilter->addItem( "Пустой фильтр" );
ui->m_cmbFilter->addItem( "Фильтр трения по графствам" );
ui->m_cmbFilter->addItem( "Фильтр миграций из графства" );
m_filters.append( new ddmEmptyFilter( model(), mapView() ) );
m_filters.append( new ddmFrictionCountyFilter( model(), mapView() ) );
m_filters.append( new ddmMigrationCountyFilter( model(), mapView() ) );
}
void ddmWidget::resizeEvent( QResizeEvent *event )
{
QSize size = event->size();
ui->m_map->resize( size.width(), size.height() );
}
void ddmWidget::setModel( ddmModel* model )
{
this->m_model = model;
}
ddmModel* ddmWidget::model() const
{
return this->m_model;
}
ddmMapView* ddmWidget::mapView() const
{
return this->ui->m_map;
}
void ddmWidget::reload()
{
if( ddmMapView* view = mapView() )
view->reload();
}
void ddmWidget::increaseZoom()
{
if( ddmMapView* view = mapView() )
view->increaseZoomLevel();
}
void ddmWidget::decreaseZoom()
{
if( ddmMapView* view = mapView() )
view->decreaseZoomLevel();
}