diff --git a/qtvplugin_geomarker/qtvplugin_geomarker.h b/qtvplugin_geomarker/qtvplugin_geomarker.h index cbc86c7dd69d46e7749b09afdf9be3bd6539f9e2..9f5368cf2287f0edff37994eacff35759ea7712f 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker.h +++ b/qtvplugin_geomarker/qtvplugin_geomarker.h @@ -133,6 +133,7 @@ private: QMap func_delete_props (const QMap &); QMap func_mark_names (const QMap &); QMap func_mark (const QMap &); + QMap func_props (const QMap &); //overloaded virtual funtions protected: diff --git a/qtvplugin_geomarker/qtvplugin_geomarker_func.cpp b/qtvplugin_geomarker/qtvplugin_geomarker_func.cpp index 5093260b2bcda32b86c9c9bc3829c9b703d26355..d3f7b9479c83e258ea1d19b00138ce891c2a68ee 100644 --- a/qtvplugin_geomarker/qtvplugin_geomarker_func.cpp +++ b/qtvplugin_geomarker/qtvplugin_geomarker_func.cpp @@ -12,11 +12,16 @@ * * ATTENTION!THIS FUNCTION IS NOT THREAD SAFE! Calls should be made only in main thread, also called "UI Thread" * Supported fucntions: - * 1.function=update_point - * 2.function=update_line - * 3.function=update_polygon - * 4.function=update_props - * 5.function=exists + * 1.update_point Insert or Update a point mark. + * 2.update_line Insert or Update a line mark. + * 3.update_polygon Insert or Update a polygon mark. + * 4.update_props Insert or Update a mark's user-defind properties. + * 5.exists Test whether a special mark is exist. + * 6.delete_marks Delete marks. + * 7.delete_props Delete user-defined properties for a mark. + * 8.mark_names return All mark names owned by this plugin. + * 9.mark return All styles and geo points for a special mark. + * 10.props return All user-defined properties for a special mark. * @param paras the key-value style paraments. * @return QMap the key-value style return values. */ @@ -36,22 +41,36 @@ QMap qtvplugin_geomarker::call_func(const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_update_point (const QMap & paras) { QMap res; + //!name, lat, lon has no default values. user should specify these values or the function calll will fail; if (paras.contains("name")==false || paras.contains("lat")==false || paras.contains("lon")==false) { res["error"] = tr("name, lat, lon must exist in paraments."); @@ -69,7 +88,7 @@ QMap qtvplugin_geomarker::func_update_point (const QMapitem_type()==QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT) @@ -95,6 +114,8 @@ QMap qtvplugin_geomarker::func_update_point (const QMap qtvplugin_geomarker::func_update_point (const QMap0 , stand for the point width of the pen on screen. if ( paras.contains("width_pen")) { int penWidth =paras["width_pen"].toInt(); @@ -125,7 +148,7 @@ QMap qtvplugin_geomarker::func_update_point (const QMap qtvplugin_geomarker::func_update_point (const QMap qtvplugin_geomarker::func_update_point (const QMap 1 || tpn <0) tpn = 0; QTVP_GEOMARKER::geo_item_type tpe = static_cast< QTVP_GEOMARKER::geo_item_type > (tpn); + //update using same function in UI if (tpe==QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT) newitem = update_point(name,lat,lon,width,height,pen,brush); else @@ -181,18 +208,21 @@ QMap qtvplugin_geomarker::func_update_point (const QMaplabelFont(); + //! size_label stands for the text label font pixel size from 1 - 720, with a normal value 9. if ( paras.contains("size_label")) { int fontSz = paras["size_label"].toInt(); if (fontSz==0) fontSz = 9; f.setPointSize(fontSz); } + //! weight_label is the bolder rate for text renderring, from 1 ~ 99, 99 is the heaviest. if ( paras.contains("weight_label")) { int fontWeight = paras["weight_label"].toInt(); f.setWeight(fontWeight); } newitem->setLabelFont(f); + //! color_label has 4 text color band values splitted by comma, r,g,b,a if ( paras.contains("color_label")) { QColor textColor = string2color( paras["color_label"].toString()); @@ -205,9 +235,18 @@ QMap qtvplugin_geomarker::func_update_point (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_update_line (const QMap & paras) { QMap res; + //!name, lat0, lon0, lat1,lon1 has no default values. user should specify these values or the function calll will fail; if (paras.contains("name")==false || paras.contains("lat0")==false || paras.contains("lon0")==false || paras.contains("lat1")==false || paras.contains("lon1")==false) { @@ -223,6 +262,8 @@ QMap qtvplugin_geomarker::func_update_line (const QMapgeoitem_by_name(name); QPen pen(Qt::SolidLine); + + //if the mark is already exist, we will get its orgional style as default . if (base) { if (base->item_type()==QTVP_GEOMARKER::ITEAMTYPE_LINE) @@ -232,6 +273,8 @@ QMap qtvplugin_geomarker::func_update_line (const QMap qtvplugin_geomarker::func_update_line (const QMap0 , stand for the point width of the pen on screen. if ( paras.contains("width_pen")) { int penWidth =paras["width_pen"].toInt(); @@ -264,28 +309,33 @@ QMap qtvplugin_geomarker::func_update_line (const QMaplabelFont(); + //! size_label stands for the text label font pixel size from 1 - 720, with a normal value 9. if ( paras.contains("size_label")) { int fontSz =paras["size_label"].toInt(); if (fontSz==0) fontSz = 9; f.setPointSize(fontSz); } + //! weight_label is the bolder rate for text renderring, from 1 ~ 99, 99 is the heaviest. if ( paras.contains("weight_label")) { int fontWeight = paras["weight_label"].toInt(); f.setWeight(fontWeight); } newitem->setLabelFont(f); + //! color_label has 4 text color band values splitted by comma, r,g,b,a if ( paras.contains("color_label")) { QColor textColor = string2color( paras["color_label"].toString()); @@ -299,10 +349,19 @@ QMap qtvplugin_geomarker::func_update_line (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_update_polygon (const QMap & paras) { QMap res; - + //!name, latn, lonn, has no default values, n>=3. user should specify these values or the function calll will fail; if (paras.contains("name")==false) { res["error"] = tr("name must exist in paraments."); @@ -319,6 +378,8 @@ QMap qtvplugin_geomarker::func_update_polygon (const QMapgeoitem_by_name(name); QPen pen(Qt::SolidLine); QBrush brush(QColor(255,255,255,128)); + + //if the mark is already exist, we will get its orgional style as default . if (base) { if (base->item_type()==QTVP_GEOMARKER::ITEAMTYPE_POLYGON) @@ -332,6 +393,8 @@ QMap qtvplugin_geomarker::func_update_polygon (const QMap qtvplugin_geomarker::func_update_polygon (const QMap0 , stand for the point width of the pen on screen. if ( paras.contains("width_pen")) { int penWidth =paras["width_pen"].toInt(); @@ -362,7 +428,7 @@ QMap qtvplugin_geomarker::func_update_polygon (const QMap qtvplugin_geomarker::func_update_polygon (const QMap qtvplugin_geomarker::func_update_polygon (const QMap qtvplugin_geomarker::func_update_polygon (const QMap2) newitem = update_polygon(name,pl,pen,brush); else @@ -416,18 +486,21 @@ QMap qtvplugin_geomarker::func_update_polygon (const QMaplabelFont(); + //! size_label stands for the text label font pixel size from 1 - 720, with a normal value 9. if ( paras.contains("size_label")) { int fontSz = paras["size_label"].toInt(); if (fontSz==0) fontSz = 9; f.setPointSize(fontSz); } + //! weight_label is the bolder rate for text renderring, from 1 ~ 99, 99 is the heaviest. if ( paras.contains("weight_label")) { int fontWeight = paras["weight_label"].toInt(); f.setWeight(fontWeight); } newitem->setLabelFont(f); + //! color_label has 4 text color band values splitted by comma, r,g,b,a if ( paras.contains("color_label")) { QColor textColor = string2color( paras["color_label"].toString()); @@ -441,16 +514,29 @@ QMap qtvplugin_geomarker::func_update_polygon (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_update_props(const QMap & paras) { QMap res; + //!name: user should specify these values or the function calll will fail; QString name = paras["name"].toString(); if (name.size()==0) { res["error"] = tr("name does not exist in paraments."); return std::move(res); } - + /** the user-defined properties are defined as key-value pairs. + * [prop_name]=[prop_value] + * note that plugin keyword "name" and "function" should not be used. + */ QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name); if (base) { @@ -467,9 +553,19 @@ QMap qtvplugin_geomarker::func_update_props(const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_exists (const QMap & paras) { QMap res; + //!name: user should specify these values or the function calll will fail; QString name = paras["name"].toString(); if (name.size()==0) { @@ -483,12 +579,23 @@ QMap qtvplugin_geomarker::func_exists (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_delete_marks (const QMap & paras) { QMap res; - + //! marknames should stored in parename name0, name1, name2 + //! for example, name0=StarBar;name1=ruijing Hospital;name2=shunfun express; QSet set_names; int ct = 0; do{ @@ -523,10 +630,18 @@ QMap qtvplugin_geomarker::func_delete_marks (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_delete_props (const QMap & paras) { QMap res; + //!name: user should specify these values or the function calll will fail; if (paras.contains("name")==false) { res["error"] = tr("name must exist in paraments."); @@ -538,6 +653,12 @@ QMap qtvplugin_geomarker::func_delete_props (const QMapgeoitem_by_name(name); if (base) { @@ -556,6 +677,14 @@ QMap qtvplugin_geomarker::func_delete_props (const QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_mark_names (const QMap & /*paras*/) { QMap res; @@ -566,11 +695,172 @@ QMap qtvplugin_geomarker::func_mark_names (const QMapitem_name(); } + //! the mark names will be stored in key-value pairs, with + //! name0=??;name1=??;name2=??...namen-1=?? return std::move(res); } - +/** + * @brief func_mark is a internal function for plugin call_func "mark" + * + * the paraments used by paras is listed below. + * function=mark; + * @param paras The key-value style paraments. + * @return QMap if error happens, a property called "error" will store the most possible reason. + */ QMap qtvplugin_geomarker::func_mark (const QMap & paras) { + //!name: user should specify these values or the function calll will fail; + QMap res; + if (paras.contains("name")==false) + { + res["error"] = tr("name must exist in paraments."); + return std::move(res); + } + QString name = paras["name"].toString(); + if (name.size()==0) + { + res["error"] = tr("name could not be empty."); + return std::move(res); + } + QTVP_GEOMARKER::geoItemBase * item = m_pScene->geoitem_by_name(name); + if (item) + { + QTVP_GEOMARKER::geo_item_type x_tp = item->item_type(); + QString x_name = item->item_name(); + + //! in return parament, contains same keys as "func_update_point","func_update_line",and "func_update_polygon": + + res["name"] = x_name; + res["type"] = QString("%1").arg((int)x_tp); + switch (x_tp) + { + case QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT: + { + QTVP_GEOMARKER::geoGraphicsRectItem * pU = dynamic_cast(item); + if (pU) + { + res["lat"] = QString("%1").arg(pU->lat(),0,'f',7); + res["lon"] = QString("%1").arg(pU->lon(),0,'f',7); + res["width"] = QString("%1").arg(pU->width()); + res["height"] = QString("%1").arg(pU->height()); + res["color_pen"] = color2string(pU->pen().color()); + res["style_pen"] = QString("%1").arg(int(pU->pen().style())); + res["width_pen"] = QString("%1").arg(int(pU->pen().width())); + res["color_brush"] = color2string(pU->brush().color()); + res["style_brush"] = QString("%1").arg(int(pU->brush().style())); + + } + } + break; + case QTVP_GEOMARKER::ITEAMTYPE_ELLIPSE_POINT: + { + QTVP_GEOMARKER::geoGraphicsEllipseItem * pU = dynamic_cast(item); + if (pU) + { + res["lat"] = QString("%1").arg(pU->lat(),0,'f',7); + res["lon"] = QString("%1").arg(pU->lon(),0,'f',7); + res["width"] = QString("%1").arg(pU->width()); + res["height"] = QString("%1").arg(pU->height()); + res["color_pen"] = color2string(pU->pen().color()); + res["style_pen"] = QString("%1").arg(int(pU->pen().style())); + res["width_pen"] = QString("%1").arg(int(pU->pen().width())); + res["color_brush"] = color2string(pU->brush().color()); + res["style_brush"] = QString("%1").arg(int(pU->brush().style())); + } + } + break; + case QTVP_GEOMARKER::ITEAMTYPE_LINE: + { + QTVP_GEOMARKER::geoGraphicsLineItem * pU = dynamic_cast(item); + if (pU) + { + res["lat0"] = QString("%1").arg(pU->lat1(),0,'f',7); + res["lon0"] = QString("%1").arg(pU->lon1(),0,'f',7); + res["lat1"] = QString("%1").arg(pU->lat2(),0,'f',7); + res["lon1"] = QString("%1").arg(pU->lon2(),0,'f',7); + res["color_pen"] = color2string(pU->pen().color()); + res["style_pen"] = QString("%1").arg(int(pU->pen().style())); + res["width_pen"] = QString("%1").arg(int(pU->pen().width())); + } + } + break; + case QTVP_GEOMARKER::ITEAMTYPE_POLYGON: + { + QTVP_GEOMARKER::geoGraphicsPolygonItem * pU = dynamic_cast(item); + if (pU) + { + QPolygonF pl = pU->llas(); + int nPl = pl.size(); + for (int in = 0;in < nPl; ++in) + { + QString keyLat = QString("lat%1").arg(in); + QString keyLon = QString("lon%1").arg(in); + res[keyLat] = QString("%1").arg(pl[in].y(),0,'f',7); + res[keyLon] = QString("%1").arg(pl[in].x(),0,'f',7); + } + res["color_pen"] = color2string(pU->pen().color()); + res["style_pen"] = QString("%1").arg(int(pU->pen().style())); + res["width_pen"] = QString("%1").arg(int(pU->pen().width())); + res["color_brush"] = color2string(pU->brush().color()); + res["style_brush"] = QString("%1").arg(int(pU->brush().style())); + } + } + break; + default: + break; + } + + QColor colorText = item->labelColor(); + res["color_label"] = color2string(colorText); + + int fsize = item->labelFont().pointSize(); + res["size_label"] = QString("%1").arg(fsize); + + int weight = item->labelFont().weight(); + res["weight_label"] = QString("%1").arg(weight); + + } + else + res["error"] = tr("the mark name.") + name + tr(" does not exist in current scene."); + return std::move(res); +} +/** + * @brief func_props is a internal function for plugin call_func "props" + * + * the paraments used by paras is listed below. + * function=props; + * @param paras The key-value style paraments. + * @return QMap if error happens, a property called "error" will store the most possible reason. + */ +QMap qtvplugin_geomarker::func_props (const QMap & paras) +{ + //!name: user should specify these values or the function calll will fail; QMap res; + if (paras.contains("name")==false) + { + res["error"] = tr("name must exist in paraments."); + return std::move(res); + } + QString name = paras["name"].toString(); + if (name.size()==0) + { + res["error"] = tr("name could not be empty."); + return std::move(res); + } + QTVP_GEOMARKER::geoItemBase * item = m_pScene->geoitem_by_name(name); + if (item) + { + QString x_name = item->item_name(); + res["name"] = x_name; + int props = item->prop_counts(); + QStringList lstNames = item->prop_names(); + QVariantList lstValues = item->prop_values(); + for (int i=0;iaxWidget_map1->dynamicCall("osm_layer_get_name(int)",i); QString strname = vt_name.toString(); - strLayerNames += strname + ";"; + strLayerNames += strname + ";\n"; } QMessageBox::information(this,"layer count",QString("osm_layer_get_count() returns %1\n%2").arg(n_num).arg(strLayerNames) ); @@ -249,6 +249,8 @@ void testcontainer::on_pushButton_test_grid_getPolygon_clicked() "osm_layer_call_function(QString,QString)", "grid1", "function=get_polygon;").toString(); + res.replace(";",";\n"); + res.replace("=","=\t"); QMessageBox::information(this,"grid1::get_polygon",res); } @@ -374,3 +376,24 @@ void testcontainer::timerEvent(QTimerEvent * e) } } + +void testcontainer::on_pushButton_test_request_clicked() +{ + QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1", + "function=mark_names;").toString(); + res.replace(";",";\n"); + res.replace("=","\t="); + QMessageBox::information(this,"geomarker1::mark_names",res); + + + res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1", + "function=mark;name=ID1").toString(); + res.replace(";",";\n"); + res.replace("=","\t="); + QMessageBox::information(this,"geomarker1::mark",res); + res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1", + "function=props;name=ID1").toString(); + res.replace(";",";\n"); + res.replace("=","\t="); + QMessageBox::information(this,"geomarker1::props",res); +} diff --git a/test_container/testcontainer.h b/test_container/testcontainer.h index 520f9937955c355f557f59e0eea7d9ec8afb75e7..fb5ac074465ba78fcef53d672d5c53c905a351d7 100644 --- a/test_container/testcontainer.h +++ b/test_container/testcontainer.h @@ -35,6 +35,7 @@ protected slots: void on_pushButton_test_mark_clicked(); void on_pushButton_test_line_clicked(); void on_pushButton_test_polygon_clicked(); + void on_pushButton_test_request_clicked(); }; #endif // TESTCONTAINER_H diff --git a/test_container/testcontainer.ui b/test_container/testcontainer.ui index f222112ba1d8ef3585640f0e2e98775f0ff6b62f..d8d0f7910e7a371616a4a7a2202677e4117adb0e 100644 --- a/test_container/testcontainer.ui +++ b/test_container/testcontainer.ui @@ -6,7 +6,7 @@ 0 0 - 800 + 811 600 @@ -149,6 +149,13 @@ + + + + request + + +