浏览代码

change view_group_grpc. add server ip and port setting.

yuchuli 3 年之前
父节点
当前提交
21072147e3

+ 71 - 0
src/tool/view_group_grpc/dialogsetting.cpp

@@ -0,0 +1,71 @@
+#include "dialogsetting.h"
+#include "ui_dialogsetting.h"
+
+#include <QMessageBox>
+
+DialogSetting::DialogSetting(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogSetting)
+{
+    ui->setupUi(this);
+
+    QSettings * configini = new QSettings("view_group_grpc.ini",QSettings::IniFormat);
+
+    mstrserverip = configini->value("setting/serverip").toString();
+
+    if(mstrserverip == "")
+    {
+        mstrserverip = "111.33.136.149";
+    }
+
+    mstrserverport = configini->value("setting/serverport").toString();
+
+    if(mstrserverport == "")
+    {
+        mstrserverport = "31001";
+    }
+
+    mstrinterval = configini->value("setting/interval").toString();
+
+    if(mstrinterval == "")
+    {
+        mstrinterval = "100";
+    }
+
+    ui->lineEdit_serverip->setText(mstrserverip);
+    ui->lineEdit_serverport->setText(mstrserverport);
+    ui->lineEdit_queryinterval->setText(mstrinterval);
+
+    delete configini;
+
+    setWindowTitle("Set Server");
+
+}
+
+DialogSetting::~DialogSetting()
+{
+    delete ui;
+}
+
+void DialogSetting::on_pushButton_Set_clicked()
+{
+    mstrserverip = ui->lineEdit_serverip->text();
+    mstrserverport = ui->lineEdit_serverport->text();
+    mstrinterval = ui->lineEdit_queryinterval->text();
+
+    QSettings * configini = new QSettings("view_group_grpc.ini",QSettings::IniFormat);
+
+    configini->setValue("setting/serverip",mstrserverip);
+    configini->setValue("setting/serverport",mstrserverport);
+    configini->setValue("setting/interval",mstrinterval);
+
+    delete configini;
+
+    QMessageBox::information(this,"Info","设置成功,重启程序生效.",QMessageBox::YesAll);
+    this->accept();
+}
+
+void DialogSetting::on_pushButton_Close_clicked()
+{
+    this->accept();
+}

+ 32 - 0
src/tool/view_group_grpc/dialogsetting.h

@@ -0,0 +1,32 @@
+#ifndef DIALOGSETTING_H
+#define DIALOGSETTING_H
+
+#include <QDialog>
+#include <QSettings>
+
+namespace Ui {
+class DialogSetting;
+}
+
+class DialogSetting : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogSetting(QWidget *parent = nullptr);
+    ~DialogSetting();
+
+private slots:
+    void on_pushButton_Set_clicked();
+
+    void on_pushButton_Close_clicked();
+
+private:
+    Ui::DialogSetting *ui;
+
+    QString mstrserverip;
+    QString mstrserverport;
+    QString mstrinterval;
+};
+
+#endif // DIALOGSETTING_H

+ 114 - 0
src/tool/view_group_grpc/dialogsetting.ui

@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogSetting</class>
+ <widget class="QDialog" name="DialogSetting">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>598</width>
+    <height>328</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Set">
+   <property name="geometry">
+    <rect>
+     <x>70</x>
+     <y>220</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>设置</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Close">
+   <property name="geometry">
+    <rect>
+     <x>340</x>
+     <y>220</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>关闭</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>20</y>
+     <width>101</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>服务器 IP</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_serverip">
+   <property name="geometry">
+    <rect>
+     <x>170</x>
+     <y>24</y>
+     <width>321</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>80</y>
+     <width>101</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>服务器端口</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>140</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>查询间隔(ms)</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_serverport">
+   <property name="geometry">
+    <rect>
+     <x>170</x>
+     <y>83</y>
+     <width>113</width>
+     <height>40</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_queryinterval">
+   <property name="geometry">
+    <rect>
+     <x>170</x>
+     <y>140</y>
+     <width>113</width>
+     <height>40</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 37 - 3
src/tool/view_group_grpc/groupqueryclient.cpp

@@ -2,13 +2,13 @@
 
 groupqueryclient::groupqueryclient()
 {
-
+    LoadIni();
 }
 
 void groupqueryclient::run()
 {
-    int ninterval = 100;
- //   if(ninterval<=0)ninterval = 1000;
+    int ninterval = mnInterval;
+    if(ninterval<=0)ninterval = 1000;
 
     QTime xTime;
     xTime.start();
@@ -166,3 +166,37 @@ std::vector<iv::vehinfo> groupqueryclient::GetVehinfo()
     mMutexInfo.unlock();
     return xrtn;
 }
+
+void groupqueryclient::LoadIni()
+{
+    QSettings * configini = new QSettings("view_group_grpc.ini",QSettings::IniFormat);
+
+    QString strserverip = configini->value("setting/serverip").toString();
+
+    if(strserverip == "")
+    {
+        strserverip = "111.33.136.149";
+    }
+
+    QString strserverport = configini->value("setting/serverport").toString();
+
+    if(strserverport == "")
+    {
+        strserverport = "31001";
+    }
+
+    QString strserverinterval = configini->value("setting/interval").toString();
+
+    if(strserverinterval == "")
+    {
+        strserverinterval = "100";
+    }
+
+    QString strserver = strserverip + ":"+ strserverport;
+    mstrserver = strserver.toStdString();
+
+    mnInterval = strserverinterval.toInt();
+
+
+    delete configini;
+}

+ 7 - 1
src/tool/view_group_grpc/groupqueryclient.h

@@ -4,6 +4,8 @@
 
 #include <QDateTime>
 
+#include <QSettings>
+
 #include <iostream>
 
 #include <vector>
@@ -56,13 +58,17 @@ private:
     void run();
 
 private:
-    std::string mstrserver = "101.201.57.67:31001";// "111.33.136.149:31001";
+    std::string mstrserver ="111.33.136.149:31001";// "101.201.57.67:31001";//
+    int mnInterval;
 
     std::vector<iv::vehinfo> mvectorvehinfo;
     QMutex mMutexInfo;
 
 public:
     std::vector<iv::vehinfo> GetVehinfo();
+
+private:
+    void LoadIni();
 };
 
 #endif // GROUPQUERYCLIENT_H

+ 6 - 0
src/tool/view_group_grpc/mainwindow.cpp

@@ -161,3 +161,9 @@ void MainWindow::connectstateupdate(int nstate)
     else setWindowTitle("View Group Message");
 }
 
+
+void MainWindow::on_actionSetting_triggered()
+{
+    DialogSetting dlg(this);
+    dlg.exec();
+}

+ 4 - 0
src/tool/view_group_grpc/mainwindow.h

@@ -3,6 +3,8 @@
 
 #include <QMainWindow>
 
+#include "dialogsetting.h"
+
 #include "groupqueryclient.h"
 
 QT_BEGIN_NAMESPACE
@@ -23,6 +25,8 @@ private slots:
 
     void connectstateupdate(int nstate);
 
+    void on_actionSetting_triggered();
+
 private:
     Ui::MainWindow *ui;
 

+ 12 - 0
src/tool/view_group_grpc/mainwindow.ui

@@ -195,8 +195,20 @@
      <height>28</height>
     </rect>
    </property>
+   <widget class="QMenu" name="menuHelp">
+    <property name="title">
+     <string>File</string>
+    </property>
+    <addaction name="actionSetting"/>
+   </widget>
+   <addaction name="menuHelp"/>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionSetting">
+   <property name="text">
+    <string>Setting</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections/>

+ 3 - 0
src/tool/view_group_grpc/view_group_grpc.pro

@@ -26,6 +26,7 @@ SOURCES += \
     ../../include/msgtype/gpsimu.pb.cc \
     ../../include/msgtype/groupmsg.pb.cc \
     ../../include/msgtype/grpcgroup.pb.cc \
+    dialogsetting.cpp \
     groupqueryclient.cpp \
     main.cpp \
     mainwindow.cpp
@@ -38,10 +39,12 @@ HEADERS += \
     ../../include/msgtype/gpsimu.pb.h \
     ../../include/msgtype/groupmsg.pb.h \
     ../../include/msgtype/grpcgroup.pb.h \
+    dialogsetting.h \
     groupqueryclient.h \
     mainwindow.h
 
 FORMS += \
+    dialogsetting.ui \
     mainwindow.ui
 
 # Default rules for deployment.