first blood
This commit is contained in:
1 parent
78b528c0af
commit
91d5cabd26
40 files changed
+3861
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#ifndef CUSTOMBUTTON_H
|
||||
#define CUSTOMBUTTON_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
class TCustomButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit TCustomButton(QWidget *parent=0)
|
||||
: QPushButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
explicit TCustomButton(const QString &text, QWidget *parent=0)
|
||||
: QPushButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//TObserverClientModel* ObserverClientModel;
|
||||
|
||||
boost::function<void()> PressedHandler;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void mouseReleaseEvent ( QMouseEvent * e )
|
||||
{
|
||||
QAbstractButton::mouseReleaseEvent(e);
|
||||
/*
|
||||
if (ObserverClientModel != NULL)
|
||||
{
|
||||
ObserverClientModel->OnConnectButtonPressed();
|
||||
}*/
|
||||
|
||||
PressedHandler();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // CUSTOMBUTTON_H
|
||||
@@ -0,0 +1,42 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-08-22T11:32:24
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
QT += webkit
|
||||
|
||||
CONFIG += no_keywords
|
||||
|
||||
TARGET = K-observer_client
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
../../k_observer/common/UserInfo.cpp \
|
||||
../../k_observer/common/misc.cpp \
|
||||
../../k_observer/common/MessageSender.cpp \
|
||||
observerclientmodel.cpp \
|
||||
../../k_observer/common/ClientSocket.cpp \
|
||||
customtimer.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
../../k_observer/common/UserInfo.h \
|
||||
../../k_observer/common/misc.h \
|
||||
../../k_observer/common/MessageSender.h \
|
||||
observerclientmodel.h \
|
||||
../../k_observer/common/ClientSocket.h \
|
||||
CustomButton.h \
|
||||
customtimer.h
|
||||
|
||||
INCLUDEPATH += C:/Workplace/libs/boost_1_47_0/
|
||||
INCLUDEPATH += ../../k_observer/common/
|
||||
|
||||
LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/debug/
|
||||
LIBS += -LC:/Workplace/libs/boost_1_47_0/boost_windows/libs_engine/release/
|
||||
|
||||
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
#include "customtimer.h"
|
||||
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
CustomTimer::CustomTimer(QObject *parent)
|
||||
: QTimer(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CustomTimer::timerEvent ( QTimerEvent * e )
|
||||
{
|
||||
|
||||
TimerSignal();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef CUSTOMTIMER_H
|
||||
#define CUSTOMTIMER_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTimerEvent>
|
||||
#include "UserInfo.h"
|
||||
class CustomTimer : public QTimer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CustomTimer(QObject *parent = 0);
|
||||
|
||||
boost::signal<void()> TimerSignal;
|
||||
|
||||
protected:
|
||||
virtual void timerEvent ( QTimerEvent * e );
|
||||
|
||||
};
|
||||
|
||||
#endif // CUSTOMTIMER_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "observerclientmodel.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
TObserverClientModel observerClient;
|
||||
|
||||
w.ObserverClientModel = &observerClient;
|
||||
observerClient.MainWindowPtr = &w;
|
||||
|
||||
w.OpenMap();
|
||||
|
||||
w.GetUi()->ConnectButton->PressedHandler = boost::bind(&TObserverClientModel::OnConnectButtonPressed, &observerClient);
|
||||
w.GetUi()->UpdateDataButton->PressedHandler = boost::bind(&TObserverClientModel::OnUpdateInfoButtonPressed, &observerClient);
|
||||
|
||||
|
||||
w.GetUi()->DisconnectButton->PressedHandler = boost::bind(&TObserverClientModel::Finish, &observerClient);
|
||||
|
||||
w.GetUi()->MapTypeButton->PressedHandler = boost::bind(&TObserverClientModel::OnChangeMapTypeButtonPressed, &observerClient);
|
||||
|
||||
w.GetUi()->ChatSendButton->PressedHandler = boost::bind(&TObserverClientModel::OnChatSendClick, &observerClient);
|
||||
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QtWebKit>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
//ObserverClientModel->Finish();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::OpenMap()
|
||||
{
|
||||
QUrl url("C:/Workplace/Projects/Qt/K-observer_client/script.html");
|
||||
//QUrl url("../K-observer_client/script.html");
|
||||
//QUrl url("script.html");
|
||||
|
||||
|
||||
ui->webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
|
||||
ui->webView->load(url);
|
||||
|
||||
ui->webView->page()->setContentEditable(true);
|
||||
|
||||
//ui->webView->page()->mainFrame()->evaluateJavaScript("this.AddMarker(37.443195, 55.888869);");
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class TObserverClientModel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
|
||||
|
||||
Ui::MainWindow* GetUi()
|
||||
{
|
||||
return ui;
|
||||
}
|
||||
|
||||
void OpenMap();
|
||||
|
||||
TObserverClientModel* ObserverClientModel;
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
@@ -0,0 +1,462 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>646</width>
|
||||
<height>543</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="TCustomButton" name="ConnectButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>91</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключиться</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="AddressField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>111</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="LastNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>110</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иванов</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Фамилия:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>140</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Имя:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="FirstNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>160</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иван</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>190</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Отчество:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="MiddleNameField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>210</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Иванович</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>240</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Контактный телефон:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="PhoneNumberField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>260</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1111</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSpinBox" name="UikSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>310</y>
|
||||
<width>111</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>290</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Номер УИК:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="StatusComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>360</y>
|
||||
<width>131</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Наблюдатель</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Мобильная группа</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>340</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Статус:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="UpdateDataButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>390</y>
|
||||
<width>131</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Обновить информацию</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWebView" name="webView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<y>10</y>
|
||||
<width>401</width>
|
||||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QDoubleSpinBox" name="PosXSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>262</x>
|
||||
<y>270</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.001000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>37.443195000000003</double>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QDoubleSpinBox" name="PosYSpinBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>372</x>
|
||||
<y>270</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>55.888869000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>242</x>
|
||||
<y>270</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>352</x>
|
||||
<y>270</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Y:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="MapStateComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>462</x>
|
||||
<y>270</y>
|
||||
<width>151</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Состояние норм</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Состояние тревога</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="AlarmButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>432</x>
|
||||
<y>310</y>
|
||||
<width>181</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Послать сигнал тревоги</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="PortField">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>10</y>
|
||||
<width>61</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1984</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="DisconnectButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>30</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="MapTypeButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>332</x>
|
||||
<y>300</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Выбрать</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="MapTypeComboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>300</y>
|
||||
<width>91</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Общая карта</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Карта тревоги</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="ChatList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>340</y>
|
||||
<width>381</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="ChatTextLine">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>460</y>
|
||||
<width>301</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="TCustomButton" name="ChatSendButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
<y>460</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Отправить</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>646</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>QtWebKit/QWebView</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>TCustomButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>custombutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,328 @@
|
||||
#include "observerclientmodel.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QWebFrame>
|
||||
|
||||
QString
|
||||
ws2qs(const std::wstring& str)
|
||||
{
|
||||
return (QString((const QChar*)str.c_str(), str.length()));
|
||||
}
|
||||
|
||||
// Convert a QString to a wstring
|
||||
std::wstring
|
||||
qs2ws(const QString& str)
|
||||
{
|
||||
return (std::wstring((wchar_t*)str.unicode(), str.length()));
|
||||
}
|
||||
|
||||
|
||||
TObserverClientModel::TObserverClientModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
, MapType(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::Start(std::string address, std::string port)
|
||||
{
|
||||
ClientSocket = boost::shared_ptr<TClientSocket>(new TClientSocket(IoService));
|
||||
|
||||
ClientSocket->Open(address, port);
|
||||
|
||||
RestartHeartbeatTimer();
|
||||
RestartMapHeartbeatTimer();
|
||||
|
||||
IoServiceThread = boost::thread(boost::bind(&boost::asio::io_service::run, &IoService));
|
||||
|
||||
ClientSocket->ReceiveMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveMapUpdate, this, _1));
|
||||
|
||||
ClientSocket->ReceiveAlarmMapSignal.connect(boost::bind(&TObserverClientModel::OnReceiveAlarmMapUpdate, this, _1));
|
||||
|
||||
|
||||
ClientSocket->ReceiveCloseSignal.connect(boost::bind(&TObserverClientModel::OnSocketClosed, this));
|
||||
|
||||
ClientSocket->ReceiveMessageSignal.connect(boost::bind(&TObserverClientModel::OnReceiveChatMessage, this, _1, _2));
|
||||
|
||||
|
||||
|
||||
Timer.TimerSignal.connect(boost::bind(&TObserverClientModel::OnUpdateMapTimer, this));
|
||||
|
||||
Timer.start(1000);
|
||||
}
|
||||
|
||||
void TObserverClientModel::RestartHeartbeatTimer()
|
||||
{
|
||||
HeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3)));
|
||||
|
||||
HeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnHeartbeat, this, boost::asio::placeholders::error));
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::RestartMapHeartbeatTimer()
|
||||
{
|
||||
MapHeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(3)));
|
||||
|
||||
MapHeartbeatTimer->async_wait(boost::bind(&TObserverClientModel::OnMapHeartbeat, this, boost::asio::placeholders::error));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::Finish()
|
||||
{
|
||||
Timer.stop();
|
||||
HeartbeatTimer->cancel();
|
||||
MapHeartbeatTimer->cancel();
|
||||
//HeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>();
|
||||
//MapHeartbeatTimer = boost::shared_ptr<boost::asio::deadline_timer>();
|
||||
|
||||
ClientSocket->CloseImmediate();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnSocketClosed()
|
||||
{
|
||||
ClientSocket = boost::shared_ptr<TClientSocket>();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnUpdateMapTimer()
|
||||
{
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("Clear();");
|
||||
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
|
||||
|
||||
for (std::vector<TUserInfo>::iterator i = UserInfoArr.begin(); i != UserInfoArr.end(); ++i)
|
||||
{
|
||||
QString posX = QString::number( i->PosX );
|
||||
QString posY = QString::number( i->PosY );
|
||||
QString mapState = QString::number(i->MapState);
|
||||
|
||||
if (i->PosX != 0.f && i->PosY != 0.f)
|
||||
{
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarker("+posX+", "+posY+", "+ mapState + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::vector<TUserInfo>::iterator i = AlarmUserInfoArr.begin(); i != AlarmUserInfoArr.end(); ++i)
|
||||
{
|
||||
QString posX = QString::number( i->PosX );
|
||||
QString posY = QString::number( i->PosY );
|
||||
QString mapState = QString::number(i->MapState);
|
||||
|
||||
|
||||
|
||||
std::wstring Uik = L"ÓÈÊ ¹";
|
||||
std::wstring StateHeader = L"Ñîñòîÿíèå: ";
|
||||
|
||||
QString text = ws2qs(Uik);
|
||||
text = text + QString::number(i->Uik)+"\\n";
|
||||
text = text +QString::fromUtf8(i->LastName.c_str());
|
||||
text = text +"\\n" + QString::fromUtf8(i->FirstName.c_str());
|
||||
text = text + "\\n"+QString::fromUtf8(i->MiddleName.c_str());
|
||||
text = text + "\\n"+QString::fromUtf8(i->PhoneNumber.c_str());
|
||||
text = text + "\\n";
|
||||
text = text +ws2qs(StateHeader);
|
||||
|
||||
std::wstring State;
|
||||
|
||||
if (i->MapState == 2)
|
||||
{
|
||||
State = L"Òðåâîãà";
|
||||
}
|
||||
else if (i->MapState == 2)
|
||||
{
|
||||
State = L"Óäàëåíèå ñ ÓÈÊ";
|
||||
}
|
||||
else if (i->MapState == 3)
|
||||
{
|
||||
State = L"Âáðîñ";
|
||||
}
|
||||
else if (i->MapState == 4)
|
||||
{
|
||||
State = L"Êàðóñåëü";
|
||||
}
|
||||
else if (i->MapState == 5)
|
||||
{
|
||||
State = L"Íàïàäåíèå";
|
||||
}
|
||||
|
||||
text += ws2qs(State);
|
||||
|
||||
if (i->PosX != 0.f && i->PosY != 0.f)
|
||||
{
|
||||
MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarkerWithPopup("+posX+", "+posY+", "+ mapState + ", \"" +text+ "\");");
|
||||
|
||||
//MainWindowPtr->GetUi()->webView->page()->mainFrame()->evaluateJavaScript("AddMarker("+posX+", "+posY+", "+ mapState + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer.start(1000);
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnConnectButtonPressed()
|
||||
{
|
||||
std::string address(MainWindowPtr->GetUi()->AddressField->text().toAscii());
|
||||
std::string port(MainWindowPtr->GetUi()->PortField->text().toAscii());
|
||||
|
||||
Start(address, port);
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnUpdateInfoButtonPressed()
|
||||
{
|
||||
|
||||
std::string lastName(MainWindowPtr->GetUi()->LastNameField->text().toUtf8());
|
||||
std::string firstName(MainWindowPtr->GetUi()->FirstNameField->text().toUtf8());
|
||||
std::string middleName(MainWindowPtr->GetUi()->MiddleNameField->text().toUtf8());
|
||||
|
||||
std::string phoneNumber(MainWindowPtr->GetUi()->PhoneNumberField->text().toUtf8());
|
||||
|
||||
int uik = MainWindowPtr->GetUi()->UikSpinBox->value();
|
||||
|
||||
int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex();
|
||||
|
||||
float posX = MainWindowPtr->GetUi()->PosXSpinBox->value();
|
||||
float posY = MainWindowPtr->GetUi()->PosYSpinBox->value();
|
||||
|
||||
int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex();
|
||||
if (status == 1)
|
||||
{
|
||||
mapState = 0;
|
||||
}
|
||||
|
||||
ClientSocket->UserInfo.LastName = lastName;
|
||||
ClientSocket->UserInfo.FirstName = firstName;
|
||||
ClientSocket->UserInfo.MiddleName = middleName;
|
||||
ClientSocket->UserInfo.PhoneNumber = phoneNumber;
|
||||
ClientSocket->UserInfo.Uik = uik;
|
||||
ClientSocket->UserInfo.Status = status;
|
||||
ClientSocket->UserInfo.MapState = mapState;
|
||||
|
||||
ClientSocket->UserInfo.PosX = posX;
|
||||
ClientSocket->UserInfo.PosY = posY;
|
||||
|
||||
ClientSocket->SendUserinfoUpdateThreaded();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnHeartbeat(const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float posX = MainWindowPtr->GetUi()->PosXSpinBox->value();
|
||||
float posY = MainWindowPtr->GetUi()->PosYSpinBox->value();
|
||||
|
||||
int uik = MainWindowPtr->GetUi()->UikSpinBox->value();
|
||||
int status = MainWindowPtr->GetUi()->StatusComboBox->currentIndex();
|
||||
int mapState = MainWindowPtr->GetUi()->MapStateComboBox->currentIndex() + 1;
|
||||
if (status == 1)
|
||||
{
|
||||
mapState = 0;
|
||||
}
|
||||
|
||||
ClientSocket->UserInfo.Uik = uik;
|
||||
ClientSocket->UserInfo.MapState = mapState;
|
||||
|
||||
ClientSocket->UserInfo.PosX = posX;
|
||||
ClientSocket->UserInfo.PosY = posY;
|
||||
|
||||
ClientSocket->SendHeartbeatThreaded();
|
||||
|
||||
RestartHeartbeatTimer();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnMapHeartbeat(const boost::system::error_code& e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
ClientSocket->SendMapQueryThreaded();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientSocket->SendAlarmMapQueryThreaded();
|
||||
}
|
||||
|
||||
RestartMapHeartbeatTimer();
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveMapUpdate(std::vector<TUserInfo> userInfoArr)
|
||||
{
|
||||
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
UserInfoArr = userInfoArr;
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveAlarmMapUpdate(std::vector<TUserInfo> userInfoArr)
|
||||
{
|
||||
UpdatingMapMutex.lock();
|
||||
|
||||
AlarmUserInfoArr = userInfoArr;
|
||||
|
||||
UpdatingMapMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void TObserverClientModel::OnChangeMapTypeButtonPressed()
|
||||
{
|
||||
MapType = MainWindowPtr->GetUi()->MapTypeComboBox->currentIndex();
|
||||
|
||||
if (MapType == 0)
|
||||
{
|
||||
ClientSocket->SendMapQueryThreaded();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientSocket->SendAlarmMapQueryThreaded();
|
||||
}
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnChatSendClick()
|
||||
{
|
||||
QString msg = MainWindowPtr->GetUi()->ChatTextLine->text();
|
||||
|
||||
ClientSocket->SendMessageThreaded(std::string(msg.toUtf8()));
|
||||
}
|
||||
|
||||
void TObserverClientModel::OnReceiveChatMessage(TUserInfo userInfo, std::string msg)
|
||||
{
|
||||
QString qmsg;
|
||||
|
||||
qmsg += QString::fromUtf8(userInfo.LastName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.FirstName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.MiddleName.c_str()) + " ";
|
||||
qmsg += QString::fromUtf8(userInfo.PhoneNumber.c_str()) + " ";
|
||||
qmsg += QString(ws2qs(L"ÓÈÊ ¹")) + QString::number(userInfo.Uik) + ": ";
|
||||
|
||||
|
||||
qmsg += QString::fromUtf8(msg.c_str()) + "\n";
|
||||
|
||||
|
||||
MainWindowPtr->GetUi()->ChatList->insertPlainText(qmsg);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef OBSERVERCLIENTMODEL_H
|
||||
#define OBSERVERCLIENTMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "UserInfo.h"
|
||||
#include "misc.h"
|
||||
#include "ClientSocket.h"
|
||||
#include "customtimer.h"
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class TObserverClientModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TObserverClientModel(QObject *parent = 0);
|
||||
|
||||
MainWindow* MainWindowPtr;
|
||||
|
||||
boost::shared_ptr<TClientSocket> ClientSocket;
|
||||
|
||||
boost::asio::io_service IoService;
|
||||
|
||||
boost::thread IoServiceThread;
|
||||
|
||||
boost::mutex UpdatingMapMutex;
|
||||
|
||||
std::vector<TUserInfo> UserInfoArr;
|
||||
std::vector<TUserInfo> AlarmUserInfoArr;
|
||||
|
||||
CustomTimer Timer;
|
||||
|
||||
int MapType;
|
||||
|
||||
void Start(std::string address, std::string port);
|
||||
void Finish();
|
||||
|
||||
void OnSocketClosed();
|
||||
|
||||
void RestartHeartbeatTimer();
|
||||
void RestartMapHeartbeatTimer();
|
||||
|
||||
void OnConnectButtonPressed();
|
||||
|
||||
|
||||
|
||||
void OnUpdateInfoButtonPressed();
|
||||
|
||||
void OnChangeMapTypeButtonPressed();
|
||||
|
||||
void OnHeartbeat(const boost::system::error_code& e);
|
||||
void OnMapHeartbeat(const boost::system::error_code& e);
|
||||
|
||||
void OnUpdateMapTimer();
|
||||
void OnReceiveMapUpdate(std::vector<TUserInfo> userInfoArr);
|
||||
void OnReceiveAlarmMapUpdate(std::vector<TUserInfo> userInfoArr);
|
||||
|
||||
void OnChatSendClick();
|
||||
|
||||
void OnReceiveChatMessage(TUserInfo userInfo, std::string msg);
|
||||
|
||||
|
||||
boost::shared_ptr<boost::asio::deadline_timer> HeartbeatTimer;
|
||||
boost::shared_ptr<boost::asio::deadline_timer> MapHeartbeatTimer;
|
||||
|
||||
//signals:
|
||||
|
||||
//public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // OBSERVERCLIENTMODEL_H
|
||||
@@ -0,0 +1,91 @@
|
||||
<!DOCTYPE HTML>
|
||||
<title>OpenLayers Simplest Example</title>
|
||||
<div id="demoMap" style="height:220px"></div>
|
||||
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
map = new OpenLayers.Map("demoMap");
|
||||
var mapnik = new OpenLayers.Layer.OSM();
|
||||
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
|
||||
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
|
||||
var position = new OpenLayers.LonLat(37.443195, 55.888869).transform( fromProjection, toProjection);;
|
||||
var zoom = 12;
|
||||
|
||||
map.addLayer(mapnik);
|
||||
map.setCenter(position, zoom);
|
||||
|
||||
var markers = new OpenLayers.Layer.Markers( "Markers" );
|
||||
map.addLayer(markers);
|
||||
|
||||
function AddMarker(x, y, state)
|
||||
{
|
||||
if (state == 0)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_mobile.png";
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_alarm.png";
|
||||
}
|
||||
|
||||
var size = new OpenLayers.Size(21,25);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon(marker_addr, size, offset);
|
||||
|
||||
var lon_Lat = new OpenLayers.LonLat(x, y).transform(fromProjection, toProjection);
|
||||
markers.addMarker(new OpenLayers.Marker(lon_Lat, icon));
|
||||
}
|
||||
|
||||
function Clear()
|
||||
{
|
||||
markers.clearMarkers();
|
||||
}
|
||||
|
||||
//AddMarker(37.443195, 55.888869);
|
||||
|
||||
|
||||
function AddMarkerWithPopup(x, y, state, text)
|
||||
{
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_mobile.png";
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
marker_addr = "http://mephi1984.jino.ru/osm/marker_alarm.png";
|
||||
}
|
||||
|
||||
var size = new OpenLayers.Size(21,25);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon(marker_addr, size, offset);
|
||||
|
||||
var lon_Lat = new OpenLayers.LonLat(x, y).transform(fromProjection, toProjection);
|
||||
|
||||
var marker = new OpenLayers.Marker(lon_Lat, icon);
|
||||
|
||||
marker.events.register('mousedown', marker, function(evt) { alert(text); OpenLayers.Event.stop(evt); });
|
||||
|
||||
markers.addMarker(marker);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
Reference in new issue
Block a user