diff --git a/qtviewer_planetosm/qtaxviewer_planetosm.cpp b/qtviewer_planetosm/qtaxviewer_planetosm.cpp index 591cb1ca613834f15d56973ff09288b7fa88242c..c7e278d6588f45b2584546c73ef2462a7f2ed4c9 100644 --- a/qtviewer_planetosm/qtaxviewer_planetosm.cpp +++ b/qtviewer_planetosm/qtaxviewer_planetosm.cpp @@ -50,7 +50,7 @@ qtaxviewer_planetosm::~qtaxviewer_planetosm() } /*! - \brief setTileAddress set the address of the OSM layer. + \brief osm_set_remote_address set the address of the OSM layer. a Address is almost like: http://192.168.1.127/osm/%1/%2/%3.png or @@ -220,7 +220,7 @@ void qtaxviewer_planetosm::_next_pending_evts() for(QMap::const_iterator p = e->begin();p!=e->end();++p) { str_props += p.key(); - str_props +=":"; + str_props +="="; str_props +=p.value().toString(); str_props +=";"; } @@ -348,8 +348,48 @@ int qtaxviewer_planetosm::osm_layer_move_bottom(QString layerName) } return 0; } +QString qtaxviewer_planetosm::map_to_string(const QMap & m) +{ + QString s; + for(QMap::const_iterator p = m.begin();p!=m.end();++p) + { + s += p.key(); + s += "="; + s += p.value().toString(); + s += ";"; + } + return std::move(s); +} -//function Calls +QMap qtaxviewer_planetosm::string_to_map(const QString & s) +{ + QMap res; + QStringList lst = s.split(";"); + foreach (QString s, lst) + { + int t = s.indexOf("="); + if (t>0 && t< s.size()) + { + QString name = s.left(t).trimmed(); + QString value = s.mid(t+1).trimmed(); + res[name] = value; + } + } + return std::move(res); +} + +/** + * @brief osm_layer_call_function call layers' call_func method from + * outside the ocx ctrl. Please MAKE SURE that this function is called from UI thread, + * which means the same thread that OCX ctrl stays. Calling "call_func" from another thread is + * NOT SUPPORTED, and will cause strange problems. + * + * @param layerName the layer name to whom this function call will be sent + * @param args args stored in key, value strings, + * key, value is connected with "=", and each pairs splitted by ";" + * eg, function=get_region;x=38.43834784;y=16.3834754; + * @return QString the result string is also formatted with key-vaslue para strings. + */ QString qtaxviewer_planetosm::osm_layer_call_function(QString layerName, QString args) { QString strRes; @@ -358,26 +398,12 @@ QString qtaxviewer_planetosm::osm_layer_call_function(QString layerName, QString if (la) { QMap p_in,p_out; - QStringList lst = args.split(";"); - foreach (QString s, lst) - { - int t = s.indexOf(":"); - if (t>0 && t< s.size()) - { - QString name = s.left(t).trimmed(); - QString value = s.mid(t+1).trimmed(); - p_in[name] = value; - } - } + p_in = string_to_map(args); p_out = la->call_func(p_in); - for(QMap::iterator p = p_out.begin();p!=p_out.end();++p) - { - strRes += p.key(); - strRes += ":"; - strRes += p.value().toString(); - strRes += ";"; - } + strRes = map_to_string(p_out); } + else + strRes = QString("error=Layer name \"%1\" does not exist.;").arg(layerName); return strRes; } diff --git a/qtviewer_planetosm/qtaxviewer_planetosm.h b/qtviewer_planetosm/qtaxviewer_planetosm.h index 793ab7c43bc33e9a6b017283fef3cf2621f200b9..9128badb5b580d85979bba7a4a0862f49ee7271b 100644 --- a/qtviewer_planetosm/qtaxviewer_planetosm.h +++ b/qtviewer_planetosm/qtaxviewer_planetosm.h @@ -17,6 +17,9 @@ class qtaxviewer_planetosm :public osm_frame_widget, public QAxBindable { Q_OBJECT +private: + QString map_to_string(const QMap & m); + QMap string_to_map(const QString & s); protected: QTranslator qtTranslator; QTranslator appTranslator; diff --git a/qtvplugin_grid/qtvplugin_grid.cpp b/qtvplugin_grid/qtvplugin_grid.cpp index aa9b962818fff3bff25580a8466c0f62997c9055..b8284e1871ad1121a5ca02fcf983bd821abe2bf3 100644 --- a/qtvplugin_grid/qtvplugin_grid.cpp +++ b/qtvplugin_grid/qtvplugin_grid.cpp @@ -641,6 +641,22 @@ QMap qtvplugin_grid::call_func(const QMap res[lonkey] = m_list_points[i].y(); } } + else if (funct=="get_ruler_status") + { + res["status"] = m_bActive==false?0:-1; + } + else if (funct=="set_ruler_status") + { + int status = -1; + if (paras.contains("status")) + status = paras["status"].toInt(); + set_active(status==0?false:true); + res["status"] = m_bActive==false?0:-1; + } + else + res["error"] = QString("unknown function \"%1\".").arg(funct); } + else + res["error"] = "\"function\" keyword not specified, nothing to do."; return std::move(res); } diff --git a/test_container/testcontainer.cpp b/test_container/testcontainer.cpp index e9f41a01e05a8caeede07638e3646f0ed4bb1528..b50d743de6b29ca829af57fe4a3b10a0d104a381 100644 --- a/test_container/testcontainer.cpp +++ b/test_container/testcontainer.cpp @@ -140,3 +140,55 @@ void testcontainer::on_pushButton_test_layer_move_clicked() av = ui->axWidget_map1->dynamicCall("osm_layer_set_active(QString,int)","OSM",av==0?-1:0).toInt(); QMessageBox::information(this,"active",QString("osm_layer_set_active(\"OSM\") returns %1").arg(av)); } +QString testcontainer::map_to_string(const QMap & m) +{ + QString s; + for(QMap::const_iterator p = m.begin();p!=m.end();++p) + { + s += p.key(); + s += "="; + s += p.value().toString(); + s += ";"; + } + return std::move(s); +} + +QMap testcontainer::string_to_map(const QString & s) +{ + QMap res; + QStringList lst = s.split(";"); + foreach (QString s, lst) + { + int t = s.indexOf("="); + if (t>0 && t< s.size()) + { + QString name = s.left(t).trimmed(); + QString value = s.mid(t+1).trimmed(); + res[name] = value; + } + } + return std::move(res); +} +void testcontainer::on_pushButton_test_grid_enable_clicked() +{ + QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","grid1","function=get_ruler_status;").toString(); + QMessageBox::information(this,"grid1::get_ruler_status",res); + QMap mres = string_to_map(res); + if (mres["status"].toInt()) + { + res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","grid1","function=set_ruler_status;status=0;").toString(); + QMessageBox::information(this,"grid1::set_ruler_status to false, you can call get_region to get region strings..",res); + } + else + { + res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","grid1","function=set_ruler_status;status=-1;").toString(); + QMessageBox::information(this,"grid1::set_ruler_status to true, you can draw regions on map using mouse lbutton for begin and rbutton for end.",res); + } + +} +void testcontainer::on_pushButton_test_grid_getRegion_clicked() +{ + QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","grid1","function=get_region;").toString(); + QMessageBox::information(this,"grid1::get_region",res); + +} diff --git a/test_container/testcontainer.h b/test_container/testcontainer.h index 3b2a855ed6424794ec45e4c4445614e0fcc3524b..42719816449abc52965b3cb2f2167fce4ac56a9a 100644 --- a/test_container/testcontainer.h +++ b/test_container/testcontainer.h @@ -12,6 +12,8 @@ class testcontainer : public QDialog Q_OBJECT private: QStandardItemModel * m_pModel; + QString map_to_string(const QMap & m); + QMap string_to_map(const QString & s); public: explicit testcontainer(QWidget *parent = 0); ~testcontainer(); @@ -26,6 +28,8 @@ protected slots: void on_pushButton_test_navigate_clicked(); void on_pushButton_test_layers_clicked(); void on_pushButton_test_layer_move_clicked(); + void on_pushButton_test_grid_enable_clicked(); + void on_pushButton_test_grid_getRegion_clicked(); }; #endif // TESTCONTAINER_H diff --git a/test_container/testcontainer.ui b/test_container/testcontainer.ui index 3c73073270386d68a84d90da8fec7c900e88e24a..d219e661136ab9aa39770b17f21ab5d86df45e50 100644 --- a/test_container/testcontainer.ui +++ b/test_container/testcontainer.ui @@ -101,13 +101,6 @@ - - - - test_layer_move - - - @@ -121,6 +114,20 @@ + + + + grid_measure + + + + + + + grid_region + + +