ソースを参照

change tool_grpcdb_query. complete.

yuchuli 3 年 前
コミット
2a6d39eb67

+ 26 - 0
src/driver/driver_grpc_server/main.cpp

@@ -272,10 +272,36 @@ void Init()
     }
 }
 
+#include <thread>
+std::shared_ptr<char> gstr_ptr;
+void testthread()
+{
+    while(1)
+    {
+        iv::queryReply* reply = new iv::queryReply;
+        std::shared_ptr<char> pstr = std::shared_ptr<char>(new char[1000]);
+        std::this_thread::sleep_for(std::chrono::milliseconds(1));
+        iv::ModuleMsg xmsg;
+        char * strdata = new char[1000];
+        gstr_ptr.reset(strdata);
+        xmsg.set_index(0);
+        xmsg.set_msgname("gvectorquerymsgunit[j].mstrmsgname");
+        xmsg.set_xdata(pstr.get(),1000);
+        xmsg.set_nlen(1000);
+        iv::ModuleMsg * pmsg = reply->add_msg();
+        pmsg->CopyFrom(xmsg);
+        reply->set_nlastindex(1);
+        qDebug("thread run.");
+        delete reply;
+    }
+}
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
+//    std::thread * pt = new std::thread(testthread);
+
     if(argc<2)
     {
         dec_yaml("./driver_grpc_server.yaml");

+ 65 - 0
src/tool/tool_grpcdb_query/dialogsetting.cpp

@@ -0,0 +1,65 @@
+#include "dialogsetting.h"
+#include "ui_dialogsetting.h"
+
+#include <QMessageBox>
+
+DialogSetting::DialogSetting(QString strininame,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogSetting)
+{
+    ui->setupUi(this);
+
+    mstrininame = strininame;
+
+    QSettings * configini = new QSettings(mstrininame,QSettings::IniFormat);
+
+    mstrserverip = configini->value("setting/serverip").toString();
+
+    if(mstrserverip == "")
+    {
+        mstrserverip = "111.33.136.149";
+    }
+
+    mstrserverport = configini->value("setting/serverport").toString();
+
+    if(mstrserverport == "")
+    {
+        mstrserverport = "31011";
+    }
+
+
+    ui->lineEdit_serverip->setText(mstrserverip);
+    ui->lineEdit_serverport->setText(mstrserverport);
+
+    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();
+
+
+    QSettings * configini = new QSettings(mstrininame,QSettings::IniFormat);
+
+    configini->setValue("setting/serverip",mstrserverip);
+    configini->setValue("setting/serverport",mstrserverport);
+
+    delete configini;
+
+    QMessageBox::information(this,"Info","设置成功,重启程序生效.",QMessageBox::YesAll);
+    this->accept();
+}
+
+void DialogSetting::on_pushButton_Close_clicked()
+{
+    this->accept();
+}

+ 33 - 0
src/tool/tool_grpcdb_query/dialogsetting.h

@@ -0,0 +1,33 @@
+#ifndef DIALOGSETTING_H
+#define DIALOGSETTING_H
+
+#include <QDialog>
+#include <QSettings>
+
+namespace Ui {
+class DialogSetting;
+}
+
+class DialogSetting : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogSetting(QString strininame,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 mstrininame;
+};
+
+#endif // DIALOGSETTING_H

+ 91 - 0
src/tool/tool_grpcdb_query/dialogsetting.ui

@@ -0,0 +1,91 @@
+<?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>551</width>
+    <height>282</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Set">
+   <property name="geometry">
+    <rect>
+     <x>70</x>
+     <y>175</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>175</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="QLineEdit" name="lineEdit_serverport">
+   <property name="geometry">
+    <rect>
+     <x>170</x>
+     <y>83</y>
+     <width>113</width>
+     <height>40</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 26 - 1
src/tool/tool_grpcdb_query/grpcdbclient.cpp

@@ -2,7 +2,7 @@
 
 grpcdbclient::grpcdbclient()
 {
-
+    LoadIni();
 }
 
 void grpcdbclient::run()
@@ -192,3 +192,28 @@ int grpcdbclient::getfilereply(iv::db::FiledbReply &xfilereply)
     xfilereply.CopyFrom(mfilereply);
     return 0;
 }
+
+void grpcdbclient::LoadIni()
+{
+    QSettings * configini = new QSettings("tool_grpcdb_query.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 = "31011";
+    }
+
+    mstrserverip = strserverip.toStdString();
+    mstrserverport = strserverport.toStdString();
+
+
+    delete configini;
+}

+ 5 - 0
src/tool/tool_grpcdb_query/grpcdbclient.h

@@ -1,6 +1,8 @@
 #ifndef GRPCDBCLIENT_H
 #define GRPCDBCLIENT_H
 
+#include <QSettings>
+
 #include <QMutex>
 #include <QThread>
 #include <QWaitCondition>
@@ -56,6 +58,9 @@ public:
 
     void requestfiledata(std::string filename,int npos,int nsize);
     int getfilereply(iv::db::FiledbReply & xfilereply);
+
+private:
+    void LoadIni();
 };
 
 #endif // GRPCDBCLIENT_H

+ 2 - 0
src/tool/tool_grpcdb_query/main.cpp

@@ -2,9 +2,11 @@
 
 #include <QApplication>
 
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
+
     MainWindow w;
     w.show();
     return a.exec();

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

@@ -294,3 +294,9 @@ void MainWindow::onfilereqres(int nres)
 
     }
 }
+
+void MainWindow::on_actionSetting_triggered()
+{
+    DialogSetting xdlg("tool_grpcdb_query.ini");
+    xdlg.exec();
+}

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

@@ -9,6 +9,8 @@
 
 #include "grpcdbclient.h"
 
+#include "dialogsetting.h"
+
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
 QT_END_NAMESPACE
@@ -36,6 +38,8 @@ private slots:
 
     void onfilereqres(int nres);
 
+    void on_actionSetting_triggered();
+
 private:
     Ui::MainWindow *ui;
 

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

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

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

@@ -21,6 +21,7 @@ system(protoc -I=./../../include/proto3 --cpp_out=./../../include/msgtype   ./..
 SOURCES += \
     ../../driver/driver_db_grpc_server/grpcdb.grpc.pb.cc \
     ../../include/msgtype/grpcdb.pb.cc \
+    dialogsetting.cpp \
     grpcdbclient.cpp \
     main.cpp \
     mainwindow.cpp
@@ -28,10 +29,12 @@ SOURCES += \
 HEADERS += \
     ../../driver/driver_db_grpc_server/grpcdb.grpc.pb.h \
     ../../include/msgtype/grpcdb.pb.h \
+    dialogsetting.h \
     grpcdbclient.h \
     mainwindow.h
 
 FORMS += \
+    dialogsetting.ui \
     mainwindow.ui
 
 # Default rules for deployment.