qtvplugin_geomarker.cpp 34.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "qtvplugin_geomarker.h"
#include "ui_qtvplugin_geomarker.h"
#include <QPainter>
#include <QBrush>
#include <QCoreApplication>
#include <QPen>
#include <QDebug>
#include <QLibraryInfo>
#include <QFileInfo>
#include <QMutex>
#include <QGraphicsSceneMouseEvent>
#include <QMap>
13
#include <QTextStream>
14 15 16 17
#include <assert.h>
#include "geographicsellipseitem.h"
#include "geographicsrectitem.h"
#include "geographicslineitem.h"
18
#include "geographicspolygonitem.h"
丁劲犇's avatar
丁劲犇 已提交
19
#include "geographicspixmapitem.h"
20
#include "geographicsmultilineitem.h"
21 22 23 24 25
QMutex mutex_instances;
QMap<viewer_interface *,  qtvplugin_geomarker * > map_instances;
QMap<QString,  int > count_instances;
qtvplugin_geomarker::qtvplugin_geomarker(QWidget *parent) :
	QWidget(parent),
丁劲犇's avatar
丁劲犇 已提交
26 27 28 29
	ui(new Ui::qtvplugin_geomarker),
	m_currentTools(qtvplugin_geomarker::TOOLS_DISPLAY_ONLY),
	m_sel_ptStart_World(0,0),
	m_sel_ptEnd_World(0,0)
30 31 32 33
{
	m_nInstance = 0;
	ui->setupUi(this);
	m_pVi = 0;
34
	m_nDivideTimer = 0;
35 36 37 38 39 40 41 42 43 44 45
	m_bVisible = true;
	m_pScene = new QTVP_GEOMARKER::geoGraphicsScene(this);
	m_pScene->setBackgroundBrush(Qt::NoBrush);
	//senece is 256 * 2^level
	m_pScene->setSceneRect(0,0,256,256);

	m_pGeoItemModel = new QStandardItemModel(this);
	m_pGeoItemModel->setColumnCount(3);
	m_pGeoItemModel->setHeaderData(0,Qt::Horizontal,tr("Name"));
	m_pGeoItemModel->setHeaderData(1,Qt::Horizontal,tr("Type"));
	m_pGeoItemModel->setHeaderData(2,Qt::Horizontal,tr("Props"));
46
	ui->tableView_QTV_marks->setModel(m_pGeoItemModel);
47

丁劲犇's avatar
丁劲犇 已提交
48 49 50
	m_pSelItemNameModel = new QStandardItemModel(this);
	m_pSelItemNameModel->setColumnCount(1);
	m_pSelItemNameModel->setHeaderData(0,Qt::Horizontal,tr("Name"));
51
	ui->tableView_QTV_marks_sel->setModel(m_pSelItemNameModel);
丁劲犇's avatar
丁劲犇 已提交
52 53


54 55 56 57
	m_pGeoPropModel = new QStandardItemModel(this);
	m_pGeoPropModel->setColumnCount(2);
	m_pGeoPropModel->setHeaderData(0,Qt::Horizontal,tr("Name"));
	m_pGeoPropModel->setHeaderData(1,Qt::Horizontal,tr("Value"));
58
	ui->tableView_QTV_props->setModel(m_pGeoPropModel);
59 60 61 62 63 64 65 66 67

	m_pLineStyleModel = new QStandardItemModel(this);
	m_pLineStyleModel->appendRow(new QStandardItem("NoPen"));
	m_pLineStyleModel->appendRow(new QStandardItem("SolidLine"));
	m_pLineStyleModel->appendRow(new QStandardItem("DashLine"));
	m_pLineStyleModel->appendRow(new QStandardItem("DotLine"));
	m_pLineStyleModel->appendRow(new QStandardItem("DashDotLine"));
	m_pLineStyleModel->appendRow(new QStandardItem("DashDotDotLine"));
	m_pLineStyleModel->appendRow(new QStandardItem("CustomDashLine"));
68
	ui->comboBox_QTV_linePad->setModel(m_pLineStyleModel);
69

丁劲犇's avatar
丁劲犇 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	m_pFillStyleModel = new QStandardItemModel(this);
	m_pFillStyleModel->appendRow(new QStandardItem("NoBrush"));
	m_pFillStyleModel->appendRow(new QStandardItem("SolidPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense1Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense2Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense3Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense4Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense5Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense6Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("Dense7Pattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("HorPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("VerPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("CrossPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("BDiagPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("FDiagPattern"));
	m_pFillStyleModel->appendRow(new QStandardItem("DiagCrossPattern"));
86
	ui->comboBox_QTV_fillPad->setModel(m_pFillStyleModel);
丁劲犇's avatar
丁劲犇 已提交
87

88 89 90 91 92 93
	//insert 1 icons
	QTVP_GEOMARKER::tag_icon icon;
	icon.name = "default";
	icon.filename = "://icons/default.png";
	icon.centerx = 8;
	icon.centery = 8;
丁劲犇's avatar
丁劲犇 已提交
94 95 96 97 98 99
	if (icon.icon.load(icon.filename))
		m_map_icons[icon.name] = icon;


	m_pIconsModel = new QStandardItemModel(this);
	refreshIconModel();
100
	ui->comboBox_QTV_icons->setModel(m_pIconsModel);
丁劲犇's avatar
丁劲犇 已提交
101

102
	m_bNeedRefresh = false;
丁劲犇's avatar
丁劲犇 已提交
103
	m_bNeedUpdateView = false;
104
	m_nTimerID_refreshUI = startTimer(2000);
丁劲犇's avatar
丁劲犇 已提交
105
	m_nTimerID_refreshMap = startTimer(100);
106
	m_nTimerID_levelQueue = startTimer(100);
丁劲犇's avatar
丁劲犇 已提交
107

108
	ui->radioButton_QTV_display->setChecked(true);
109 110 111 112 113 114 115 116 117 118
}

qtvplugin_geomarker::~qtvplugin_geomarker()
{
	delete ui;
}
void qtvplugin_geomarker::load_retranslate_UI()
{
	ui->retranslateUi(this);
}
丁劲犇's avatar
丁劲犇 已提交
119 120 121 122 123 124 125 126
/*! load_initial_plugin will be called when this plug in being loaded.
 * Please notice that a global parament "map_instances" is introduced, for multi-instance situation
 * in windows OCX usage. A Brave new instance of "qtvplugin_geomarker" will be created for each different viewer_interface.
 *
 * @param strSLibPath the absolute path of this dll.
 * @param ptrviewer the pointer to main view.
 * @return	return the instance pointer to the instance belong to ptrviewer
*/
127 128
layer_interface * qtvplugin_geomarker::load_initial_plugin(QString strSLibPath,viewer_interface  * ptrviewer)
{
丁劲犇's avatar
丁劲犇 已提交
129
	//!In this instance, we will see how to create a new instance for each ptrviewer
130
	qtvplugin_geomarker * instance = 0;
丁劲犇's avatar
丁劲犇 已提交
131
	//!1.Check whether there is already a instance for ptrviewer( viewer_interface)
132
	mutex_instances.lock();
丁劲犇's avatar
丁劲犇 已提交
133
	//!1.1 situation 1: map_instances is empty, which means no instance exists. We just save this pointer to map_instances
134 135 136 137 138
	if (map_instances.empty()==true)
	{
		map_instances[ptrviewer] = this;
		instance = this;
	}
丁劲犇's avatar
丁劲犇 已提交
139 140 141
	/*! 1.2 situation 2: map_instances dose not contain ptrviewer, which is the normal situation when a second ocx ctrl is initializing.
	 * we just allocate a new  qtvplugin_geomarker, and save key-value in map_instances.
	*/
142 143 144 145 146
	else if (map_instances.contains(ptrviewer)==false)
	{
		instance = new qtvplugin_geomarker;
		map_instances[ptrviewer] = instance;
	}
丁劲犇's avatar
丁劲犇 已提交
147
	//! 1.3 situation 3: a ABNORMAL situation. load_initial_plugin is called again.
148 149 150
	else
		instance = map_instances[ptrviewer];
	mutex_instances.unlock();
丁劲犇's avatar
丁劲犇 已提交
151
	//2. if the instance is just this object, we do real init code.
152 153 154 155 156 157 158 159 160 161 162 163
	if (instance==this)
	{
		QFileInfo info(strSLibPath);
		m_SLLibPath = strSLibPath;
		m_SLLibName = info.completeBaseName();
		m_pVi = ptrviewer;

		mutex_instances.lock();
		m_nInstance = ++count_instances[m_SLLibName];
		mutex_instances.unlock();

		loadTranslations();
164
		ini_load();
165
		style_load();
166
		initialBindPluginFuntions();
167
	}
丁劲犇's avatar
丁劲犇 已提交
168
	//3. elseif, we call the instance's load_initial_plugin method instead
169 170 171 172 173 174
	else
	{
		 layer_interface * ret = instance->load_initial_plugin(strSLibPath,ptrviewer);
		 assert(ret==instance);
		 return ret;
	}
175
	qDebug()<<QFont::substitutions();
176 177
	return instance;
}
丁劲犇's avatar
丁劲犇 已提交
178

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
void qtvplugin_geomarker::loadTranslations()
{
	//Trans
	QCoreApplication * app =  QCoreApplication::instance();
	if (app && m_nInstance==1)
	{
		QString strTransLocalFile =
				QCoreApplication::applicationDirPath()+"/" +
				m_SLLibName+ "_" +
				QLocale::system().name()+".qm";
		if (true==pluginTranslator.load(strTransLocalFile ))
		{
			QTVOSM_DEBUG("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Succeeded.";
			app->installTranslator(&pluginTranslator);
			ui->retranslateUi(this);
		}
		else
			QTVOSM_WARNING("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Not Found.";

	}
}

QWidget * qtvplugin_geomarker::load_prop_window()
{
	return this;
}
205 206 207 208 209 210 211 212 213
bool qtvplugin_geomarker::too_many_items()
{
	bool res = false;
	if (!m_pVi || m_bVisible==false)
		return res;
	int currentLevel = m_pVi->level();
	if (currentLevel <=7)
	{
		//skip painting when there are too many marks on map
214
		int reduce_limit = (1<<currentLevel) * 4096;
215 216 217 218 219
		if (this->m_pScene->total_items()>=reduce_limit)
			res = true;
	}
	return res;
}
220 221 222 223 224 225 226 227 228 229

void qtvplugin_geomarker::cb_paintEvent( QPainter * pImage )
{
	if (!m_pVi || m_bVisible==false)
		return ;
	QRect rect = m_pVi->windowRect();
	// Calc current viewport in world
	double leftcenx, topceny, rightcenx, bottomceny;
	m_pVi->CV_DP2World(0,0,&leftcenx,&topceny);
	m_pVi->CV_DP2World(rect.width()-1,rect.height()-1,&rightcenx,&bottomceny);
230

231
	int winsz = 256 * (1<<m_pVi->level());
丁劲犇's avatar
丁劲犇 已提交
232 233 234 235 236 237 238

	QRectF destin(
				0,
				0,
				rect.width(),
				rect.height()
				);
239
	if (too_many_items()==false)
240
	{
241 242 243 244 245 246 247 248 249 250 251
		//Warpping 180, -180. because longitude +180 and -180 is the same point,
		// but the map is plat, -180 and + 180 is quite different positions, we
		// should draw 3 times, to slove cross 180 drawing problems.
		for (int p = -1; p<=1 ;++p)
		{
			QRectF source(
						leftcenx + p * winsz,
						topceny,
						(rightcenx - leftcenx),
						(bottomceny - topceny)
						);
丁劲犇's avatar
丁劲犇 已提交
252

253
			m_pScene->render(pImage,destin,source);
丁劲犇's avatar
丁劲犇 已提交
254

255
		}
256
	}
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
	else
	{
		QPen pen(QColor(255,0,0,128));
		pen.setWidth(m_pVi->level()/2+1);
		pImage->setPen(pen);
		QList<QTVP_GEOMARKER::geoItemBase *> items
				= m_pScene->geo_items();
		foreach (QTVP_GEOMARKER::geoItemBase * pitem, items)
		{
			QPointF pt = pitem->center_pos();
			qint32 x,y;
			m_pVi->CV_World2DP(pt.x(),pt.y(),&x,&y);
			pImage->drawPoint(x,y);
		}
	}
	//draw progres
	double pc = m_pScene->progress_queue();
	if (pc<0.999)
	{
		QBrush br1(QColor(255,0,0,128));
		QBrush br2(QColor(0,255,0,128));
		pImage->setBrush(br1);
		int left = rect.center().x()-128;
		int top = rect.center().y()-16;
		pImage->drawRect(left,top,256,32);
		pImage->setBrush(br2);
		pImage->drawRect(left,top,256*pc,32);
丁劲犇's avatar
丁劲犇 已提交
284 285
		QString strmsg= tr("Level Re-Coord %1 %%").arg(pc*100);
		pImage->drawText(left+32,top+16,strmsg);
286
	}
丁劲犇's avatar
丁劲犇 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
	//draw current tools
	switch (m_currentTools)
	{
	case qtvplugin_geomarker::TOOLS_RECT_SELECTION:
	{
		QPen pen_sel(QColor(128,64,0,128));
		pen_sel.setWidth(3);
		pen_sel.setStyle(Qt::DashLine);
		pImage->setPen(pen_sel);
		pImage->drawText(32,32,"GEO MARKER Rect-Selection Tools Actived.");
		QRectF wrct = current_sel_RectWorld();
		if (wrct.isValid())
		{
			double x1 = wrct.left();
			double y1 = wrct.top();
			double x2 = wrct.right();
			double y2 = wrct.bottom();
			qint32 nx1,ny1,nx2,ny2;
			m_pVi->CV_World2DP(x1,y1,&nx1,&ny1);
			m_pVi->CV_World2DP(x2,y2,&nx2,&ny2);
			for (int i = -1;i<=1;++i)
			{
				pImage->drawLine(nx1 + i * winsz,ny1,nx1 + i * winsz,ny2);
				pImage->drawLine(nx1 + i * winsz,ny2,nx2 + i * winsz,ny2);
				pImage->drawLine(nx2 + i * winsz,ny2,nx2 + i * winsz,ny1);
				pImage->drawLine(nx2 + i * winsz,ny1,nx1 + i * winsz,ny1);
			}
		}
	}
		break;
	default:
		break;
	}
320 321 322 323
}

void qtvplugin_geomarker::cb_levelChanged(int level)
{
324
	if (!m_pVi)
325
		return ;
丁劲犇's avatar
丁劲犇 已提交
326
	m_sel_ptStart_World = m_sel_ptEnd_World = QPointF();
327 328
	//Adjust new Scene rect
	QRectF rect(0,0,256*(1<<level),256*(1<<level));
329
	this->set_visible(false);
330 331
	m_pScene->adjust_item_coords(level);
	m_pScene->setSceneRect(rect);
332
	this->set_visible(true);
333 334 335 336 337 338 339 340 341 342 343
}

bool qtvplugin_geomarker::is_visible()
{
	return m_bVisible;
}

void qtvplugin_geomarker::set_visible(bool vb)
{
	m_bVisible = vb;
}
丁劲犇's avatar
丁劲犇 已提交
344 345 346 347 348 349
void qtvplugin_geomarker::set_active(bool ab)
{
	if (ab==true)
	{
		if (m_currentTools==qtvplugin_geomarker::TOOLS_DISPLAY_ONLY)
		{
350
			ui->radioButton_QTV_rect_selection->setChecked(true);
丁劲犇's avatar
丁劲犇 已提交
351 352 353 354 355 356
			m_currentTools = qtvplugin_geomarker::TOOLS_RECT_SELECTION;
		}
	}
	else
	{
		m_currentTools = qtvplugin_geomarker::TOOLS_DISPLAY_ONLY;
357
		ui->radioButton_QTV_display->setChecked(true);
丁劲犇's avatar
丁劲犇 已提交
358 359 360
	}

}
361 362 363 364 365 366 367

QString qtvplugin_geomarker::get_name()
{
	QString strName = m_SLLibName.mid(10);
	if (m_SLLibName.left(3)=="lib")
		strName = m_SLLibName.mid(13);
	if (strName.length())
368
		return strName/* + QString("%1").arg(m_nInstance)*/;
369 370 371 372 373 374 375 376 377
	else
		return "geomarker";
}

void qtvplugin_geomarker::set_name(QString /*vb*/)
{
	if (!m_pVi)
		return ;

丁劲犇's avatar
丁劲犇 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
}
QRectF qtvplugin_geomarker::CV_RectWrold2Mkt(QRectF world)
{
	if (!m_pVi)	return QRectF();
	double mx1,my1,mx2,my2;
	m_pVi->CV_World2MK(world.left(),world.top(),&mx1,&my1);
	m_pVi->CV_World2MK(world.right(),world.bottom(),&mx2,&my2);
	return QRectF(QPointF(mx1,my1),QPointF(mx2,my2));
}
QRectF qtvplugin_geomarker::current_sel_RectWorld()
{
	if (!m_pVi)	return QRectF();
	if (m_currentTools!=qtvplugin_geomarker::TOOLS_RECT_SELECTION)
		return QRectF();
	if (m_sel_ptEnd_World.isNull() || m_sel_ptStart_World.isNull())
		return QRectF();
	qint32 wsz = 256*(1<<m_pVi->level());
	int wx1 = m_sel_ptStart_World.x(),wx2 = m_sel_ptEnd_World.x(),
			wy1 = m_sel_ptStart_World.y(), wy2 = m_sel_ptEnd_World.y();
	while (wx2 - wx1 > wsz/2)
		wx1+=wsz;
	while (wx2 - wx1 < -wsz/2)
		wx2+=wsz;
	if (wx1 > wx2)
	{
		float tp = wx1;
		wx1 = wx2;
		wx2 = tp;
	}
	if (wy1 > wy2)
	{
		float tp = wy1;
		wy1 = wy2;
		wy2 = tp;
	}

	return QRectF(QPointF(wx1,wy1),QPointF(wx2,wy2));
}

void qtvplugin_geomarker::clearSelection()
{
419 420 421 422 423 424 425 426 427
	if (!m_pVi)
		return ;
	foreach (QString name, m_set_itemNameSelected)
	{
		QTVP_GEOMARKER::geoItemBase * it = m_pScene->geoitem_by_name(name);
		if (it)
			it->set_selected(false);
	}

丁劲犇's avatar
丁劲犇 已提交
428 429 430 431 432 433 434
	m_set_itemNameSelected.clear();
	refresh_selection_listview();
	m_pVi->UpdateWindow();
}
void qtvplugin_geomarker::addSelection(QRectF rectWorld)
{
	qint32 wsz = 256*(1<<m_pVi->level());
435
	bool changed = false;
丁劲犇's avatar
丁劲犇 已提交
436 437 438 439 440 441 442 443 444 445 446 447 448 449
	for (int i=-1;i<=1;++i)
	{
		double	x1 = rectWorld.left()+i * wsz,
				y1 = rectWorld.top(),
				x2 = rectWorld.right()+i * wsz,
				y2 = rectWorld.bottom();

		QList<QGraphicsItem *> itmesel = m_pScene->items(QRectF(QPointF(x1,y1),QPointF(x2,y2)));
		foreach (QGraphicsItem * it, itmesel)
		{
			QTVP_GEOMARKER::geoItemBase *
					gi = dynamic_cast<QTVP_GEOMARKER::geoItemBase *>(it);
			if (gi)
			{
450 451 452 453 454 455 456 457 458 459 460 461 462
				changed = true;
				QString nm = gi->item_name();
				if (m_set_itemNameSelected.contains(nm))
				{
					m_set_itemNameSelected.remove(nm);
					gi->set_selected(false);
				}
				else
				{
					m_set_itemNameSelected.insert(nm);
					gi->set_selected(true);
				}

丁劲犇's avatar
丁劲犇 已提交
463 464 465
			}
		}
	}
466
	if (changed)
丁劲犇's avatar
丁劲犇 已提交
467 468 469 470 471
	{
		refresh_selection_listview();
		scheduleUpdateMap();
	}

472 473 474 475 476 477 478
}

bool qtvplugin_geomarker::cb_event(const QMap<QString, QVariant> para)
{
	return false;
}

丁劲犇's avatar
丁劲犇 已提交
479 480 481 482 483 484 485 486 487
/*! qtvplugin_geomarker::cb_mouseXXXEvent tranfer mouse events from main view to
 * QGraphicsItem based classes, so that these items will recieve mouse events.
 * For qt's graphics-view framework, this approach is done inside QGraphicsView class.
 * however, our main view is a simple widget, which means mouse events should be dealed manually.
 *
 * @fn qtvplugin_geomarker::cb_mouseDoubleClickEvent(QMouseEvent * e)
 * @param e the mouse event.
 * @return bool event acception.
*/
488 489 490 491
bool		qtvplugin_geomarker::cb_mouseDoubleClickEvent(QMouseEvent * e)
{
	if (!m_pVi)
		return false;
492 493
	if (m_bVisible==false)
		return false;
494 495 496 497 498 499
	QPoint mouse_view_pt = e->pos();
	int winsz = 256 * (1<<m_pVi->level());
	double wx,wy;
	double mlat, mlon;
	m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy);
	m_pVi->CV_DP2LLA(mouse_view_pt.x(),mouse_view_pt.y(),&mlat,&mlon);
500 501
	if (e->button()==Qt::RightButton)
	{
502 503 504 505
		ui->lineEdit_QTV_point_lat->setText(QString("%1").arg(mlat,0,'f',7));
		ui->lineEdit_QTV_point_lon->setText(QString("%1").arg(mlon,0,'f',7));
		ui->lineEdit_QTV_icon_lat->setText(QString("%1").arg(mlat,0,'f',7));
		ui->lineEdit_QTV_icon_lon->setText(QString("%1").arg(mlon,0,'f',7));
506
	}
507 508 509 510 511 512 513 514
	//Warp
	while (wx < 0) wx += winsz;
	while (wx > winsz-1) wx -= winsz;

	QPointF mouse_scene_pt(wx,wy);
	QPoint mouse_screen_pt = e->globalPos();
	Qt::MouseButton mouse_button = e->button();
	QWidget * pwig = dynamic_cast<QWidget *> (m_pVi);
515
	if (m_bVisible && pwig && too_many_items()==false)
516 517
	{
		// Convert and deliver the mouse event to the scene.
518 519
		QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseDoubleClick);
		QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent;
520 521 522 523 524 525 526 527 528 529 530
		mouseEvent.setWidget(pwig);
		mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt);
		mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt);
		mouseEvent.setScenePos(mouse_scene_pt);
		mouseEvent.setScreenPos(mouse_screen_pt);
		mouseEvent.setLastScenePos(mouse_scene_pt);
		mouseEvent.setLastScreenPos(mouse_screen_pt);
		mouseEvent.setButtons(e->buttons());
		mouseEvent.setButton(e->button());
		mouseEvent.setModifiers(e->modifiers());
		mouseEvent.setAccepted(false);
531 532
		QApplication::postEvent(m_pScene, &mouseEvent);
		scheduleUpdateMap();
533 534 535
	}
	return false;
}
丁劲犇's avatar
丁劲犇 已提交
536 537 538 539 540 541 542 543 544
/*! qtvplugin_geomarker::cb_mouseXXXEvent tranfer mouse events from main view to
 * QGraphicsItem based classes, so that these items will recieve mouse events.
 * For qt's graphics-view framework, this approach is done inside QGraphicsView class.
 * however, our main view is a simple widget, which means mouse events should be dealed manually.
 *
 * @fn qtvplugin_geomarker::cb_mousePressEvent(QMouseEvent * e)
 * @param e the mouse event.
 * @return bool event acception.
*/
545 546 547 548
bool qtvplugin_geomarker::cb_mousePressEvent(QMouseEvent * e)
{
	if (!m_pVi)
		return false;
549 550
	if (m_bVisible==false)
		return false;
551 552 553 554 555 556 557 558 559 560 561 562
	QPoint mouse_view_pt = e->pos();
	int winsz = 256 * (1<<m_pVi->level());
	double wx,wy;
	m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy);
	//Warp
	while (wx < 0) wx += winsz;
	while (wx > winsz-1) wx -= winsz;

	QPointF mouse_scene_pt(wx,wy);
	QPoint mouse_screen_pt = e->globalPos();
	Qt::MouseButton mouse_button = e->button();
	QWidget * pwig = dynamic_cast<QWidget *> (m_pVi);
563
	if (m_bVisible && pwig  && too_many_items()==false)
564 565
	{
		// Convert and deliver the mouse event to the scene.
566
		QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress);
567
		QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent;
568 569 570 571 572 573 574 575 576 577 578
		mouseEvent.setWidget(pwig);
		mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt);
		mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt);
		mouseEvent.setScenePos(mouse_scene_pt);
		mouseEvent.setScreenPos(mouse_screen_pt);
		mouseEvent.setLastScenePos(mouse_scene_pt);
		mouseEvent.setLastScreenPos(mouse_screen_pt);
		mouseEvent.setButtons(e->buttons());
		mouseEvent.setButton(e->button());
		mouseEvent.setModifiers(e->modifiers());
		mouseEvent.setAccepted(false);
579 580
		QApplication::postEvent(m_pScene, &mouseEvent);
		scheduleUpdateMap();
581
	}
丁劲犇's avatar
丁劲犇 已提交
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
	//tools
	switch (m_currentTools)
	{
	case qtvplugin_geomarker::TOOLS_RECT_SELECTION:
	{
		if (e->button()==Qt::LeftButton)
		{
			m_sel_ptStart_World = m_sel_ptEnd_World = QPointF(wx,wy);
		}
	}
		break;
	default:
		break;
	}


	return false;

}
bool qtvplugin_geomarker::cb_mouseMoveEvent ( QMouseEvent * e )
{
	if (!m_pVi)
		return false;
	if (m_bVisible==false)
		return false;
	QPoint mouse_view_pt = e->pos();
	int winsz = 256 * (1<<m_pVi->level());
	double wx,wy;
	m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy);
	//Warp
	while (wx < 0) wx += winsz;
	while (wx > winsz-1) wx -= winsz;
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
	QPointF mouse_scene_pt(wx,wy);
	QPoint mouse_screen_pt = e->globalPos();
	Qt::MouseButton mouse_button = e->button();
	QWidget * pwig = dynamic_cast<QWidget *> (m_pVi);
	if (m_bVisible && pwig  && too_many_items()==false)
	{
		// Convert and deliver the mouse event to the scene.
		QGraphicsSceneMouseEvent * pmouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove);
		QGraphicsSceneMouseEvent & mouseEvent = * pmouseEvent;
		mouseEvent.setWidget(pwig);
		mouseEvent.setButtonDownScenePos(mouse_button, mouse_scene_pt);
		mouseEvent.setButtonDownScreenPos(mouse_button, mouse_screen_pt);
		mouseEvent.setScenePos(mouse_scene_pt);
		mouseEvent.setScreenPos(mouse_screen_pt);
		mouseEvent.setLastScenePos(mouse_scene_pt);
		mouseEvent.setLastScreenPos(mouse_screen_pt);
		mouseEvent.setButtons(e->buttons());
		mouseEvent.setButton(e->button());
		mouseEvent.setModifiers(e->modifiers());
		mouseEvent.setAccepted(false);
		QApplication::postEvent(m_pScene, &mouseEvent);
	}
丁劲犇's avatar
丁劲犇 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
	//tools
	switch (m_currentTools)
	{
	case qtvplugin_geomarker::TOOLS_RECT_SELECTION:
	{
		if (e->buttons()==Qt::LeftButton)
		{
			m_sel_ptEnd_World = QPointF(wx,wy);
			scheduleUpdateMap();
		}
	}
		break;
	default:
		break;
	}


	return false;

}

bool qtvplugin_geomarker::cb_mouseReleaseEvent ( QMouseEvent * e )
{
	if (!m_pVi)
		return false;
	if (m_bVisible==false)
		return false;
	QPoint mouse_view_pt = e->pos();
	int winsz = 256 * (1<<m_pVi->level());
	double wx,wy;
	m_pVi->CV_DP2World(mouse_view_pt.x(),mouse_view_pt.y(),&wx,&wy);
	//Warp
	while (wx < 0) wx += winsz;
	while (wx > winsz-1) wx -= winsz;

	//tools
	switch (m_currentTools)
	{
	case qtvplugin_geomarker::TOOLS_RECT_SELECTION:
	{
		if (e->button()==Qt::LeftButton)
		{
			m_sel_ptEnd_World = QPointF(wx,wy);
			QRectF rectSel = current_sel_RectWorld();
			m_sel_ptStart_World = m_sel_ptEnd_World = QPointF();
			addSelection(rectSel);
			scheduleUpdateMap();
		}
	}
		break;
	default:
		break;
	}


691 692 693
	return false;

}
丁劲犇's avatar
丁劲犇 已提交
694

丁劲犇's avatar
丁劲犇 已提交
695
/*! for convenience, color is stored in plain text in XML and UI.
696
 * the plain text color is 4 sub value , which stands for r,g,b,alpha.
丁劲犇's avatar
丁劲犇 已提交
697 698 699 700 701
 *
 * @fn qtvplugin_geomarker::string2color(const QString & s)
 * @param s the string color.
 * @return QColor is the color object.
*/
702 703 704 705 706 707 708 709 710 711
QColor qtvplugin_geomarker::string2color(const QString & s)
{
	QStringList lst = s.split(",",QString::SkipEmptyParts);
	int r = 255,g = 255, b = 255, a= 128;
	if (lst.empty()==false) {r = lst.first().toInt(); lst.pop_front();}
	if (lst.empty()==false) {g = lst.first().toInt(); lst.pop_front();}
	if (lst.empty()==false) {b = lst.first().toInt(); lst.pop_front();}
	if (lst.empty()==false) {a = lst.first().toInt(); lst.pop_front();}
	return QColor(r,g,b,a);
}
丁劲犇's avatar
丁劲犇 已提交
712
/*! for convenience, color is stored in plain text in XML and UI.
713
 * the plain text color is 4 sub value , which stands for r,g,b,alpha.
丁劲犇's avatar
丁劲犇 已提交
714 715 716 717 718
 *
 * @fn qtvplugin_geomarker::color2string(const QColor & col)
 * @param col the  color object.
 * @return QString is the color string.
*/
719 720
QString qtvplugin_geomarker::color2string(const QColor & col)
{
721
	QString str = QString("%1,%2,%3,%4").arg(col.red()).arg(col.green()).arg(col.blue()).arg(col.alpha());
722 723 724
	return str;
}

725
QString qtvplugin_geomarker::ini_file()
726 727 728 729 730 731
{
	if (m_SLLibPath.size())
		return m_SLLibPath + QString("%1").arg(m_nInstance) + ".ini";
	else
		return QCoreApplication::applicationFilePath() + QString("/geomarker%1.ini").arg(m_nInstance);
}
丁劲犇's avatar
丁劲犇 已提交
732

丁劲犇's avatar
丁劲犇 已提交
733
void qtvplugin_geomarker::scheduleRefreshMarks()
734 735 736
{
	if (!m_pVi || !m_pScene)
		return;
丁劲犇's avatar
丁劲犇 已提交
737 738 739
	//We do not refresh UI immediately after each mark-insert, for these inserts is very dense ,
	//BAD performence will arise if so.
	//We will set a flag and refresh the ui in timerEvent Instead.
740
	m_bNeedRefresh = true;
741
	m_items_to_insert.clear();
742
}
丁劲犇's avatar
丁劲犇 已提交
743 744 745 746 747 748 749 750 751
void qtvplugin_geomarker::scheduleUpdateMap()
{
	if (!m_pVi || !m_pScene)
		return;
	//We do not refresh MAP immediately after each mark-insert, for these inserts is very dense ,
	//BAD performence will arise if so.
	//We will set a flag and refresh the ui in timerEvent Instead.
	m_bNeedUpdateView = true;
}
丁劲犇's avatar
丁劲犇 已提交
752 753 754 755 756 757 758 759 760 761 762
void qtvplugin_geomarker::refresh_selection_listview()
{
	if (!m_pVi || !m_pScene)
		return;
	//refersh
	this->m_pSelItemNameModel->removeRows(0,this->m_pSelItemNameModel->rowCount());
	foreach (QString name, m_set_itemNameSelected)
	{
		m_pSelItemNameModel->appendRow(new QStandardItem(name));
	}
}
763

764
QTVP_GEOMARKER::geoItemBase *  qtvplugin_geomarker::update_line(const QString & name,double lat1, double lon1,double lat2, double lon2, QPen pen)
765
{
766
	QTVP_GEOMARKER::geoItemBase *  res = 0;
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
	//Get raw Item by name
	QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name);
	//Get Props
	QStringList propNames;
	QVariantList propValues;
	if (base)
	{
		propNames = base->prop_names();
		propValues = base->prop_values();
	}
	//type convertion to T
	QTVP_GEOMARKER::geoGraphicsLineItem * pitem = base?dynamic_cast<QTVP_GEOMARKER::geoGraphicsLineItem  *>(base):0;
	if (!pitem)
		pitem	= new QTVP_GEOMARKER::geoGraphicsLineItem(name,
						this->m_pVi,
						lat1,lon1,lat2,lon2);
丁劲犇's avatar
丁劲犇 已提交
783 784

	pitem->setPen(pen);
785

786
	if (base == pitem)
787
	{
788
		pitem->setGeo(lat1,lon1,lat2,lon2);
789 790
		res = pitem;
	}
791
	else if (false==this->m_pScene->addItem(pitem,0))
792 793 794 795 796 797 798 799 800 801 802 803 804
	{
		if (base != pitem)
			delete pitem;
	}
	else
	{
		int cs = propNames.size();
		for (int i=0;i<cs && base != pitem;++i)
		{
			pitem->set_prop_data(propNames.first(), propValues.first());
			propNames.pop_front();
			propValues.pop_front();
		}
805
		res = pitem;
806
	}
807
	return res;
808
}
809 810


811
QTVP_GEOMARKER::geoItemBase *   qtvplugin_geomarker::update_polygon		(const QString & name,const QPolygonF latlons, QPen pen, QBrush brush, bool tp)
812
{
813
	QTVP_GEOMARKER::geoItemBase *  res = 0;
814 815 816 817 818 819 820 821 822 823
	//Get raw Item by name
	QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name);
	//Get Props
	QStringList propNames;
	QVariantList propValues;
	if (base)
	{
		propNames = base->prop_names();
		propValues = base->prop_values();
	}
824
	if (tp==false)
825
	{
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
		//type convertion to T
		QTVP_GEOMARKER::geoGraphicsPolygonItem * pitem = base?dynamic_cast<QTVP_GEOMARKER::geoGraphicsPolygonItem  *>(base):0;
		if (!pitem)
			pitem	= new QTVP_GEOMARKER::geoGraphicsPolygonItem(name,
																 this->m_pVi,
																 latlons);
		pitem->setPen(pen);
		pitem->setBrush(brush);
		if (base == pitem)
		{
			pitem->setGeo(latlons);
			res = pitem;
		}
		else if (false==this->m_pScene->addItem(pitem,0))
		{
			if (base != pitem)
				delete pitem;
		}
		else
		{
			int cs = propNames.size();
			for (int i=0;i<cs && base != pitem;++i)
			{
				pitem->set_prop_data(propNames.first(), propValues.first());
				propNames.pop_front();
				propValues.pop_front();
			}
			res = pitem;
		}
855 856 857
	}
	else
	{
858 859 860 861 862 863 864 865 866
		//type convertion to T
		QTVP_GEOMARKER::geoGraphicsMultilineItem * pitem = base?dynamic_cast<QTVP_GEOMARKER::geoGraphicsMultilineItem  *>(base):0;
		if (!pitem)
			pitem	= new QTVP_GEOMARKER::geoGraphicsMultilineItem(name,
																 this->m_pVi,
																 latlons);
		pitem->setPen(pen);
		//pitem->setBrush(QBrush(Qt::NoBrush));
		if (base == pitem)
867
		{
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
			pitem->setGeo(latlons);
			res = pitem;
		}
		else if (false==this->m_pScene->addItem(pitem,0))
		{
			if (base != pitem)
				delete pitem;
		}
		else
		{
			int cs = propNames.size();
			for (int i=0;i<cs && base != pitem;++i)
			{
				pitem->set_prop_data(propNames.first(), propValues.first());
				propNames.pop_front();
				propValues.pop_front();
			}
			res = pitem;
886 887
		}
	}
888 889


890
	return res;
891
}
892
QTVP_GEOMARKER::geoItemBase *	qtvplugin_geomarker::update_icon(const QString & name,double lat, double lon,qreal scale, qreal rotate,int smooth, QString id)
丁劲犇's avatar
丁劲犇 已提交
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
{
	QTVP_GEOMARKER::geoItemBase *  res = 0;
	//Get raw Item by name
	QTVP_GEOMARKER::geoItemBase * base = m_pScene->geoitem_by_name(name);
	//Get Props
	QStringList propNames;
	QVariantList propValues;
	if (base)
	{
		propNames = base->prop_names();
		propValues = base->prop_values();
	}
	//type convertion to T
	QTVP_GEOMARKER::geoGraphicsPixmapItem * pitem = base?dynamic_cast<QTVP_GEOMARKER::geoGraphicsPixmapItem  *>(base):0;
	if (!pitem)
	{
909 910 911 912 913 914
		const QTVP_GEOMARKER::tag_icon * iconp = 0;
		if (m_map_icons.contains(id))
			iconp = &m_map_icons[id];
		else
			iconp = &m_map_icons["default"];

丁劲犇's avatar
丁劲犇 已提交
915
		pitem	= new QTVP_GEOMARKER::geoGraphicsPixmapItem(name,this->m_pVi,
916 917
															iconp,
															lat,lon
丁劲犇's avatar
丁劲犇 已提交
918 919 920 921 922
															);
	}
	if (base == pitem)
	{
		pitem->setGeo(lat,lon);
923 924 925 926
		if (m_map_icons.contains(id))
			pitem->setPixmap(m_map_icons[id]);
		else
			pitem->setPixmap(m_map_icons["default"]);
丁劲犇's avatar
丁劲犇 已提交
927 928 929 930 931
		res = pitem;
	}
	else if (false==this->m_pScene->addItem(pitem,0))
	{
		if (base != pitem)
932
		{
丁劲犇's avatar
丁劲犇 已提交
933
			delete pitem;
934 935
			pitem = 0;
		}
丁劲犇's avatar
丁劲犇 已提交
936 937 938 939 940 941 942 943 944 945 946 947
	}
	else
	{
		int cs = propNames.size();
		for (int i=0;i<cs && base != pitem;++i)
		{
			pitem->set_prop_data(propNames.first(), propValues.first());
			propNames.pop_front();
			propValues.pop_front();
		}
		res = pitem;
	}
948 949 950 951 952 953 954 955
	if (pitem)
	{
		pitem->setScale(scale);
		pitem->setRotation(rotate);
		if (smooth)
			pitem->setTransformationMode(Qt::SmoothTransformation);
		else
			pitem->setTransformationMode(Qt::FastTransformation);
956
		pitem->adjustLabelPos();
957
	}
丁劲犇's avatar
丁劲犇 已提交
958 959
	return res;
}
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
bool qtvplugin_geomarker::cmd_save (QString cmdFile)
{
	QFile fp(cmdFile);
	if (fp.open(QIODevice::WriteOnly)==false)
		return false;
	QTextStream stream_out(&fp);
	//1. for each mark, write a root element
	QList<QTVP_GEOMARKER::geoItemBase *> items = m_pScene->geo_items();
	foreach (QTVP_GEOMARKER::geoItemBase * item, items)
	{
		QString cmd_str;
		QTVP_GEOMARKER::geo_item_type x_tp = item->item_type();
		QString x_name = item->item_name();

		//1.1. Mark
		switch (x_tp)
		{
		case QTVP_GEOMARKER::ITEAMTYPE_RECT_POINT:
		{
			QTVP_GEOMARKER::geoGraphicsRectItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsRectItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp);
				cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7);
				//1.2 style
				cmd_str += "width="+ QString("%1;").arg(pU->width());
				cmd_str += "height="+ QString("%1;").arg(pU->height());
				cmd_str += "color_pen="+ color2string(pU->pen().color())+";";
				cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style()));
				cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width()));
				cmd_str += "color_brush="+ color2string(pU->brush().color())+";";
				cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style()));
			}
		}
			break;
		case QTVP_GEOMARKER::ITEAMTYPE_ELLIPSE_POINT:
		{
			QTVP_GEOMARKER::geoGraphicsEllipseItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsEllipseItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_point;name="+x_name+QString(";type=%1;").arg(x_tp);
				cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7);
				//1.2 style
				cmd_str += "width="+ QString("%1;").arg(pU->width());
				cmd_str += "height="+ QString("%1;").arg(pU->height());
				cmd_str += "color_pen="+ color2string(pU->pen().color())+";";
				cmd_str += "style_pen="+ QString("%1;").arg(int(pU->pen().style()));
				cmd_str += "width_pen="+ QString("%1;").arg(int(pU->pen().width()));
				cmd_str += "color_brush="+ color2string(pU->brush().color())+";";
				cmd_str += "style_brush="+ QString("%1;").arg(int(pU->brush().style()));
				}
		}
			break;
		case QTVP_GEOMARKER::ITEAMTYPE_LINE:
		{
			QTVP_GEOMARKER::geoGraphicsLineItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsLineItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_line;name="+x_name+QString(";type=%1;").arg(x_tp);
				cmd_str += QString("lat0=%1;lon0=%2;").arg(pU->lat1(),0,'f',7).arg(pU->lon1(),0,'f',7);
				cmd_str += QString("lat1=%1;lon1=%2;").arg(pU->lat2(),0,'f',7).arg(pU->lon2(),0,'f',7);
				//1.2 style
				cmd_str += "color_pen=" + color2string(pU->pen().color())+";";
				cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style()));
				cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width()));
			}
		}
			break;
		case QTVP_GEOMARKER::ITEAMTYPE_POLYGON:
		{
			QTVP_GEOMARKER::geoGraphicsPolygonItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsPolygonItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp);
				QPolygonF pl = pU->llas();
				int nPl = pl.size();
				int ct_pg = 0;
				foreach (QPointF pf, pl)
				{
					cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg);
					++ct_pg;
				}
				cmd_str += "color_pen=" + color2string(pU->pen().color())+";";
				cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style()));
				cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width()));
				cmd_str += "color_brush=" + color2string(pU->brush().color())+";";
				cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style()));
			}
		}
			break;
		case QTVP_GEOMARKER::ITEAMTYPE_PIXMAP:
		{
			QTVP_GEOMARKER::geoGraphicsPixmapItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsPixmapItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_icon;name="+x_name+QString(";type=%1;").arg(x_tp);
				//1.2. geo
				cmd_str += QString("lat=%1;lon=%2;").arg(pU->lat(),0,'f',7).arg(pU->lon(),0,'f',7);
				//1.2 style
				cmd_str += "icon=" +QString("%1;").arg(pU->icon()->name);
				cmd_str += "scale=" +QString("%1;").arg(pU->scale());
				cmd_str += "rotate=" +QString("%1;").arg(pU->rotation());
				cmd_str += "smooth=" +QString("%1;").arg(pU->transformationMode()==Qt::SmoothTransformation?1:0);
			}
		}
			break;
		case QTVP_GEOMARKER::ITEAMTYPE_MULTILINE:
		{
			QTVP_GEOMARKER::geoGraphicsMultilineItem * pU = dynamic_cast<QTVP_GEOMARKER::geoGraphicsMultilineItem *>(item);
			if (pU)
			{
				cmd_str += "function=update_polygon;name="+x_name+QString(";type=%1;").arg(x_tp);
				QPolygonF pl = pU->llas();
				int nPl = pl.size();
				int ct_pg = 0;
				foreach (QPointF pf, pl)
				{
					cmd_str += QString("lat%3=%1;lon%3=%2;").arg(pf.y(),0,'f',7).arg(pf.x(),0,'f',7).arg(ct_pg);
					++ct_pg;
				}
				cmd_str += "color_pen=" + color2string(pU->pen().color())+";";
				cmd_str += "style_pen=" + QString("%1;").arg(int(pU->pen().style()));
				cmd_str += "width_pen=" + QString("%1;").arg(int(pU->pen().width()));
				cmd_str += "color_brush=" + color2string(pU->brush().color())+";";
				cmd_str += "style_brush=" + QString("%1;").arg(int(pU->brush().style()));
			}
		}
			break;
		default:
			break;
		}

		QColor colorText = item->labelColor();
		cmd_str += "color_label="+color2string(colorText)+";";

		int fsize = item->labelFont().pointSize();
		cmd_str += "size_label="+QString("%1;").arg(fsize);

		int weight = item->labelFont().weight();
		cmd_str += "weight_label="+QString("%1;").arg(weight);
		cmd_str += "want_hover="+QString("%1;\015\012").arg(item->wantMouseHoverEvent()==true?1:0);

		cmd_str += "function=update_props;name="+x_name+";";
		//1.2 properties
		int props = item->prop_counts();
		QStringList lstNames = item->prop_names();
		QVariantList lstValues = item->prop_values();
		for (int i=0;i<props;++i)
		{
			cmd_str += lstNames[i]+"="+lstValues[i].toString()+";";
		}
		stream_out<<cmd_str<<"\015\012";
	}
	fp.flush();
	fp.close();
	return true;
}
bool qtvplugin_geomarker::cmd_load (QString cmdFile)
{
	bool res = true;
	QString errMessage;
	QFile fp(cmdFile);
	if (fp.open(QIODevice::ReadOnly)==false)
		return false;
	QTextStream sfile(&fp);
	while (sfile.atEnd()==false)
	{
		QString linered = sfile.readLine();
		if (linered.contains("function"))
		{
			QMap<QString, QVariant> res;
			QStringList lst = linered.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;
				}
			}
			this->call_func(res);
		}
	}
	fp.close();
	if (res==false)
	{
		QMap<QString,QVariant> evt_error;
		evt_error["source"] = get_name();
		evt_error["destin"] = "ALL";
		evt_error["name"] = "error";
		evt_error["class"] = "cmd reader";
		evt_error["file"] = cmdFile;
		evt_error["detail"] = errMessage;
		m_pVi->post_event(evt_error);

	}
	return res;
}