testcontainer.cpp 17.4 KB
Newer Older
1 2 3 4
#include "testcontainer.h"
#include "ui_testcontainer.h"
#include <QAxBase>
#include <QDebug>
丁劲犇's avatar
丁劲犇 已提交
5
#include <QMessageBox>
6 7 8 9 10 11 12 13 14
testcontainer::testcontainer(QWidget *parent) :
	QDialog(parent),
	ui(new Ui::testcontainer)
{
	ui->setupUi(this);
	Qt::WindowFlags flg =  this->windowFlags();
	flg |= Qt::WindowMinMaxButtonsHint;
	this->setWindowFlags(flg);

丁劲犇's avatar
丁劲犇 已提交
15
	m_pModel = new QStandardItemModel (0,2,this);
16
	m_pModel->setHeaderData(0,Qt::Horizontal,tr("ctrl"));
丁劲犇's avatar
丁劲犇 已提交
17
	m_pModel->setHeaderData(1,Qt::Horizontal,tr("msg"));
18 19 20 21
	ui->tableView_msg->setModel(m_pModel);

	ui->axWidget_map1->setControl("{8FDF97AD-FEFA-44C9-973B-1B66D4C529DF}");
	ui->axWidget_map2->setControl("{8FDF97AD-FEFA-44C9-973B-1B66D4C529DF}");
丁劲犇's avatar
丁劲犇 已提交
22 23
	connect (ui->axWidget_map1,SIGNAL(evt_Message(QString)),this,SLOT(slot_message(QString)));
	connect (ui->axWidget_map2,SIGNAL(evt_Message(QString)),this,SLOT(slot_message(QString)));
24
	m_nAnTimer = startTimer(150);
25 26 27 28 29 30 31 32 33 34
}

testcontainer::~testcontainer()
{
	delete ui;
}
void testcontainer::closeEvent(QCloseEvent *)
{
	QCoreApplication::quit();
}
丁劲犇's avatar
丁劲犇 已提交
35
void testcontainer::slot_message(QString message)
36
{
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
	if (message.contains("MOUSE_MOVE"))
	{
		ui->label_mouseMove->setText(message);
	}
	else
	{
		QAxBase * base = qobject_cast<QAxBase *>(sender());
		QList<QStandardItem *> list_newrow;
		list_newrow << new QStandardItem(QString("%1").arg((quint64)base));
		list_newrow << new QStandardItem(QString("%1").arg(message));
		m_pModel->appendRow(list_newrow);
		while (m_pModel->rowCount()>1024)
			m_pModel->removeRow(0);
		ui->tableView_msg->scrollToBottom();
	}

53
}
丁劲犇's avatar
丁劲犇 已提交
54 55 56 57

void testcontainer::on_pushButton_test_adds_clicked()
{
	//get raw address
58 59 60
	QVariant vt_addr = ui->axWidget_map1->dynamicCall(
				"osm_get_remote_address(QString)",
				"OSM");
丁劲犇's avatar
丁劲犇 已提交
61 62 63 64
	QString str_addr = vt_addr.toString();
	QMessageBox::information(this,"get osm address from LAYER \"OSM\"",str_addr);

	//set address to another value
65 66 67 68
	ui->axWidget_map1->dynamicCall(
				"osm_set_remote_address(QString,QString)",
				"OSM",
				"http://localhost/osmtile.cgi?level=%1&x=%2&y=%3");
丁劲犇's avatar
丁劲犇 已提交
69 70

	//get again
71 72 73
	QVariant vt_addr2 = ui->axWidget_map1->dynamicCall(
				"osm_get_remote_address(QString)",
				"OSM");
丁劲犇's avatar
丁劲犇 已提交
74 75 76 77
	QString str_addr2 = vt_addr2.toString();
	QMessageBox::information(this,"get osm address from LAYER \"OSM\"",str_addr2);

	//set address to another value
78 79 80
	ui->axWidget_map1->dynamicCall(
				"osm_set_remote_address(QString,QString)",
				"OSM", str_addr);
丁劲犇's avatar
丁劲犇 已提交
81 82

	//get again
83 84 85
	QVariant vt_addr3 = ui->axWidget_map1->dynamicCall(
				"osm_get_remote_address(QString)",
				"OSM");
丁劲犇's avatar
丁劲犇 已提交
86 87 88 89 90 91
	QString str_addr3 = vt_addr3.toString();
	QMessageBox::information(this,"get osm address from LAYER \"OSM\"",str_addr3);

}
void testcontainer::on_pushButton_test_autodl_clicked()
{
92 93 94 95
	//get auto download flag
	QVariant vt_addr = ui->axWidget_map1->dynamicCall(
				"osm_get_auto_download(QString)",
				"OSM");
丁劲犇's avatar
丁劲犇 已提交
96 97 98
	int n_status = vt_addr.toInt();
	QMessageBox::information(this,"get auto download from LAYER \"OSM\"",QString("status = %1").arg(n_status) );

99 100 101 102 103 104 105 106 107 108
	//set flag to opposite option
	ui->axWidget_map1->dynamicCall(
				"osm_set_auto_download(QString, int)",
				"OSM" ,
				n_status==0?-1:0);

	//get again
	vt_addr = ui->axWidget_map1->dynamicCall(
				"osm_get_auto_download(QString)",
				"OSM");
丁劲犇's avatar
丁劲犇 已提交
109 110 111 112 113
	n_status = vt_addr.toInt();
	QMessageBox::information(this,"get auto download from LAYER \"OSM\"",QString("status = %1").arg(n_status) );
}
void testcontainer::on_pushButton_test_navigate_clicked()
{
114
	//Get curent Level
丁劲犇's avatar
丁劲犇 已提交
115 116 117 118
	QVariant vt_addr = ui->axWidget_map1->dynamicCall("osm_get_level()");
	int n_level = vt_addr.toInt();
	QMessageBox::information(this,"get_level",QString("level = %1").arg(n_level) );

119 120 121 122
	//Set level to a new value
	ui->axWidget_map1->dynamicCall(
				"osm_set_level(int)",
				n_level<5?++n_level:--n_level);
丁劲犇's avatar
丁劲犇 已提交
123

124
	//Let's see level again
丁劲犇's avatar
丁劲犇 已提交
125 126 127 128
	vt_addr = ui->axWidget_map1->dynamicCall("osm_get_level()");
	n_level = vt_addr.toInt();
	QMessageBox::information(this,"get_level",QString("level = %1").arg(n_level) );

129
	//Get map center position
丁劲犇's avatar
丁劲犇 已提交
130 131 132 133
	double lat = ui->axWidget_map1->dynamicCall("osm_get_center_lat()").toDouble();
	double lon = ui->axWidget_map1->dynamicCall("osm_get_center_lon()").toDouble();
	QMessageBox::information(this,"osm_get_center_latlon",QString("lat = %1, lon=%2").arg(lat).arg(lon) );

134
	//Set a new center position
135
	lat = rand()%1700/10.0-85; lon = rand()%3600/10.0-180;
丁劲犇's avatar
丁劲犇 已提交
136
	ui->axWidget_map1->dynamicCall("osm_set_center_pos(double,double)",lat,lon);
137 138

	//Get map center position
丁劲犇's avatar
丁劲犇 已提交
139 140 141 142 143 144
	lat = ui->axWidget_map1->dynamicCall("osm_get_center_lat()").toDouble();
	lon = ui->axWidget_map1->dynamicCall("osm_get_center_lon()").toDouble();
	QMessageBox::information(this,"osm_get_center_latlon",QString("lat = %1, lon=%2").arg(lat).arg(lon) );
}
void testcontainer::on_pushButton_test_layers_clicked()
{
145
	//Get Total layers
丁劲犇's avatar
丁劲犇 已提交
146 147
	QVariant vt_num = ui->axWidget_map1->dynamicCall("osm_layer_get_count()");
	int n_num = vt_num.toInt();
148 149

	//Get Layer names
丁劲犇's avatar
丁劲犇 已提交
150 151 152 153 154
	QString strLayerNames;
	for (int i=0;i<n_num;++i)
	{
		QVariant vt_name = ui->axWidget_map1->dynamicCall("osm_layer_get_name(int)",i);
		QString strname = vt_name.toString();
155
		strLayerNames += strname + ";\n";
丁劲犇's avatar
丁劲犇 已提交
156 157 158 159 160 161
	}
	QMessageBox::information(this,"layer count",QString("osm_layer_get_count() returns  %1\n%2").arg(n_num).arg(strLayerNames) );

}
void testcontainer::on_pushButton_test_layer_move_clicked()
{
162
	//Move layers up and down
丁劲犇's avatar
丁劲犇 已提交
163 164 165 166 167 168 169 170 171
	ui->axWidget_map1->dynamicCall("osm_layer_move_up(QString)","grid1");
	on_pushButton_test_layers_clicked();
	ui->axWidget_map1->dynamicCall("osm_layer_move_bottom(QString)","grid1");
	on_pushButton_test_layers_clicked();
	ui->axWidget_map1->dynamicCall("osm_layer_move_top(QString)","grid1");
	on_pushButton_test_layers_clicked();
	ui->axWidget_map1->dynamicCall("osm_layer_move_down(QString)","grid1");
	on_pushButton_test_layers_clicked();

172
	//Set layer's visiblity
丁劲犇's avatar
丁劲犇 已提交
173 174 175 176 177 178 179
	int bv = ui->axWidget_map1->dynamicCall("osm_layer_get_visiable(QString)","grid1").toInt();
	QMessageBox::information(this,"visibility",QString("osm_layer_get_visiable(\"grid1\") returns  %1").arg(bv));
	bv = ui->axWidget_map1->dynamicCall("osm_layer_set_visiable(QString, int)","grid1", bv==0?-1:0).toInt();
	QMessageBox::information(this,"visibility",QString("osm_layer_set_visiable(\"grid1\") returns  %1").arg(bv));
	bv = ui->axWidget_map1->dynamicCall("osm_layer_set_visiable(QString, int)","grid1", bv==0?-1:0).toInt();
	QMessageBox::information(this,"visibility",QString("osm_layer_set_visiable(\"grid1\") returns  %1").arg(bv));

180
	//Set layer's activity
丁劲犇's avatar
丁劲犇 已提交
181 182 183 184 185 186 187
	int av = ui->axWidget_map1->dynamicCall("osm_layer_get_active(QString)","OSM").toInt();
	QMessageBox::information(this,"active",QString("osm_layer_get_active(\"OSM\") returns  %1").arg(av));
	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));
	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));
}
丁劲犇's avatar
丁劲犇 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
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()
{
219 220 221 222 223
	//Get the grid plugin's ruler status
	QString res = ui->axWidget_map1->dynamicCall(
				"osm_layer_call_function(QString,QString)",
				"grid1",
				"function=get_ruler_status;").toString();
丁劲犇's avatar
丁劲犇 已提交
224
	QMessageBox::information(this,"grid1::get_ruler_status",res);
225 226

	//Check result
丁劲犇's avatar
丁劲犇 已提交
227 228 229
	QMap<QString, QVariant> mres = string_to_map(res);
	if (mres["status"].toInt())
	{
230 231 232 233
		res = ui->axWidget_map1->dynamicCall(
					"osm_layer_call_function(QString,QString)",
					"grid1",
					"function=set_ruler_status;status=0;").toString();
234
		QMessageBox::information(this,"grid1::set_ruler_status to false, you can call get_polygon to get polygon strings..",res);
丁劲犇's avatar
丁劲犇 已提交
235 236 237
	}
	else
	{
238 239 240
		res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)",
											 "grid1",
											 "function=set_ruler_status;status=-1;").toString();
241
		QMessageBox::information(this,"grid1::set_ruler_status to true, you can draw polygons on map using mouse lbutton for begin and rbutton for end.",res);
丁劲犇's avatar
丁劲犇 已提交
242 243 244
	}

}
245
void testcontainer::on_pushButton_test_grid_getPolygon_clicked()
丁劲犇's avatar
丁劲犇 已提交
246
{
247 248 249 250 251
	//Get current ploygon lla.
	QString res = ui->axWidget_map1->dynamicCall(
				"osm_layer_call_function(QString,QString)",
				"grid1",
				"function=get_polygon;").toString();
252 253
	res.replace(";",";\n");
	res.replace("=","=\t");
254
	QMessageBox::information(this,"grid1::get_polygon",res);
丁劲犇's avatar
丁劲犇 已提交
255 256

}
丁劲犇's avatar
丁劲犇 已提交
257 258 259
void testcontainer::on_pushButton_test_mark_clicked()
{
	QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
丁劲犇's avatar
丁劲犇 已提交
260 261 262 263 264
												 "function=delete_marks;name0=ID3;name1=ID4;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::delete_marks",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
265 266
										 QString("function=update_point;name=ID1;type=1;"
												 "lat=%1;lon=%2;"
267 268 269
												 "style_pen=2;color_pen=0,0,255,128;width_pen=3;"
												 "style_brush=1;color_brush=0,255,0,128;"
												 "color_label=0,0,255,96;weight_label=99;size_label=12;"
270 271 272 273
												 "width=16;height=20;")
										 .arg(rand()%1700/10.0-85)
										 .arg(rand()%3600/10.0-180)
										 ).toString();
274 275
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_point",res);
丁劲犇's avatar
丁劲犇 已提交
276

277 278 279 280 281 282 283

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_props;name=ID1;"
												 "LABEL=Shanghai;EXPRESS=Shunfeng;Pero=IMMEDIATE;"
												 "CheckTime=2014-12-31 23:11:27;"
												 "From=Shanghai;To=Beijing").toString();
	if (res.contains("error"))
284
		QMessageBox::information(this,"geomarker1::update_props",res);
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302


	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_point;name=ID2;type=2;"
												 "lat=40.3737;lon=111.34347;"
												 "style_pen=3;color_pen=0,255,0,128;"
												 "width_pen=2;style_brush=3;color_brush=255,128,0,128;"
												 "width=12;height=12;").toString();

	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_point",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_props;name=ID2;"
												 "LABEL=Neimeng;EXPRESS=YunDa;Pero=NORMAL;"
												 "CheckTime=2014-12-30 07:18:32;"
												 "From=Huhehaote;To=YinChuan").toString();
	if (res.contains("error"))
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
		QMessageBox::information(this,"geomarker1::update_props",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_icon;name=ID7;"
												 "lat=1.233;lon=2.28373;"
												 "scale=2;rotate=0;smooth=1;"
												 "icon=default;").toString();

	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_icon",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_props;name=ID7;"
												 "LABEL=COSCO;EXPRESS=YangChunHe;Pero=IMMD;"
												 "CheckTime=2012-12-30 07:18:32;"
												 "From=PEKING;To=YIKH").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_props",res);

322 323 324 325 326

}
void testcontainer::on_pushButton_test_line_clicked()
{
	QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
丁劲犇's avatar
丁劲犇 已提交
327 328 329 330 331
												 "function=delete_marks;name0=ID1;name1=ID2;name2=ID4;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::delete_marks",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
332 333 334
										 QString("function=update_line;name=ID3;type=3;"
												 "lat0=%1;lon0=%2;"
												 "lat1=%3;lon1=%4;"
335
												 "style_pen=4;color_pen=255,0,0,96;"
336 337 338 339 340 341
												 "width_pen=2;")
										 .arg(rand()%1700/10.0-85)
										 .arg(rand()%3600/10.0-180)
										 .arg(rand()%1700/10.0-85)
										 .arg(rand()%3600/10.0-180)
										 ).toString();
342 343
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_line",res);
丁劲犇's avatar
丁劲犇 已提交
344 345 346 347 348 349 350


	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_props;name=ID3;"
												 "LABEL=HighWay;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_point",res);
351 352 353 354 355
}

void testcontainer::on_pushButton_test_polygon_clicked()
{
	QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
丁劲犇's avatar
丁劲犇 已提交
356 357 358 359 360
												 "function=delete_marks;name0=ID1;name1=ID2;name2=ID3;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::delete_marks",res);

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
361 362 363 364 365 366 367 368 369 370
												 "function=update_polygon;name=ID4;type=4;"
												 "lat0=12.2;lon0=67.3;"
												 "lat1=14.3;lon1=62.8;"
												 "lat2=22.7;lon2=66.5;"
												 "lat3=11.5;lon3=72.2;"
												 "lat4=10.8;lon4=69.4;"
												 "style_pen=2;color_pen=0,0,255,128;"
												 "width_pen=3;style_brush=1;color_brush=0,255,0,128;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_polygon",res);
丁劲犇's avatar
丁劲犇 已提交
371 372 373 374 375 376

	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=update_props;name=ID4;"
												 "LABEL=Region;").toString();
	if (res.contains("error"))
		QMessageBox::information(this,"geomarker1::update_point",res);
377 378 379 380 381 382
}

void testcontainer::timerEvent(QTimerEvent * e)
{
	if (e->timerId()==m_nAnTimer)
	{
383
		static double tposlat = rand()%1700/10.0-85 , tposlon= rand()%3600/10.0-180;
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
		tposlat += sin(tposlon * 3.14/180.0)/5+0.1;
		tposlon -= cos(tposlat * 3.14/180.0)/5+0.1;
		if (tposlat > 85 ) tposlat = -85;
		if (tposlat < -85 ) tposlat = 85;
		if (tposlon < -180 ) tposlon = 180;
		if (tposlon > 180 ) tposlon = -180;
		QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
													 "function=exists;name=ID1;").toString();
		QMap<QString, QVariant> mres = string_to_map(res);
		if (mres["return"].toInt())
		{
			ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
										   QString("function=update_point;name=ID1;type=1;lat=%1;lon=%2;")
										   .arg(tposlat)
										   .arg(tposlon)
										   ).toString();

		}

	}
丁劲犇's avatar
丁劲犇 已提交
404
}
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425

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);
}
426 427 428 429 430 431 432 433 434 435 436
void testcontainer::on_pushButton_test_cache_clicked()
{
	QString res = ui->axWidget_map1->dynamicCall("osm_get_local_cache(QString)","OSM").toString();
	QMessageBox::information(this,"geomarker1::osm_get_local_cache",res);
	res = ui->axWidget_map1->dynamicCall("osm_set_local_cache(QString, QString)","OSM","/OSMCache").toString();
	QMessageBox::information(this,"geomarker1::osm_set_local_cache",res);
	res = ui->axWidget_map1->dynamicCall("osm_get_cache_expire_days(QString)","OSM").toString();
	QMessageBox::information(this,"geomarker1::osm_get_cache_expire_days",res);
	res = ui->axWidget_map1->dynamicCall("osm_set_cache_expire_days(QString,int)","OSM",res.toInt()+1).toString();
	QMessageBox::information(this,"geomarker1::osm_get_cache_expire_days",res);
}
437 438 439 440 441 442 443 444 445 446
void testcontainer::on_pushButton_test_xml_clicked()
{
	QString res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=load_xml;xml=.//test.xml;").toString();
	QMessageBox::information(this,"geomarker1::load_xml",res);
	res = ui->axWidget_map1->dynamicCall("osm_layer_call_function(QString,QString)","geomarker1",
												 "function=save_xml;xml=.//test.xml;").toString();
	QMessageBox::information(this,"geomarker1::save_xml",res);

}