提交 d9c3eb3a 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

All grid methods been tested

上级 c2829cc8
......@@ -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<QString, QVariant>::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<QString, QVariant> & m)
{
QString s;
for(QMap<QString, QVariant>::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<QString, QVariant> qtaxviewer_planetosm::string_to_map(const QString & s)
{
QMap<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant>::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;
}
......
......@@ -17,6 +17,9 @@
class qtaxviewer_planetosm :public osm_frame_widget, public QAxBindable
{
Q_OBJECT
private:
QString map_to_string(const QMap<QString, QVariant> & m);
QMap<QString, QVariant> string_to_map(const QString & s);
protected:
QTranslator qtTranslator;
QTranslator appTranslator;
......
......@@ -641,6 +641,22 @@ QMap<QString, QVariant> qtvplugin_grid::call_func(const QMap<QString, QVariant>
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);
}
......@@ -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<QString, QVariant> & m)
{
QString s;
for(QMap<QString, QVariant>::const_iterator p = m.begin();p!=m.end();++p)
{
s += p.key();
s += "=";
s += p.value().toString();
s += ";";
}
return std::move(s);
}
QMap<QString, QVariant> testcontainer::string_to_map(const QString & s)
{
QMap<QString, QVariant> 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<QString, QVariant> 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);
}
......@@ -12,6 +12,8 @@ class testcontainer : public QDialog
Q_OBJECT
private:
QStandardItemModel * m_pModel;
QString map_to_string(const QMap<QString, QVariant> & m);
QMap<QString, QVariant> 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
......@@ -101,13 +101,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_test_layer_move">
<property name="text">
<string>test_layer_move</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
......@@ -121,6 +114,20 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_test_grid_enable">
<property name="text">
<string>grid_measure</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_test_grid_getRegion">
<property name="text">
<string>grid_region</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册