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

1.We export osm_frame_widget to DLL as a QWidget extension.Also, a designer...

1.We export osm_frame_widget to DLL as a QWidget extension.Also, a designer plugin is introduced for UI desinger convient.
2.The grid plugin is improved for quickly mark insert, to demo how these 2 layers(grid and geomarker) communicate with each other.
上级 5ee46172
TEMPLATE = subdirs
SUBDIRS += \
qtviewer_planetosm \
qtvplugin_grid \
qtvplugin_geomarker
qtwidget_planetosm \
qtvplugin_grid \
qtvplugin_geomarker \
qtwidget_planetosm_designer
qtwidget_planetosm.file = qtviewer_planetosm/qtwidget_planetosm.pro
win32:{
SUBDIRS +=\
qtaxviewer_planetosm\
......
......@@ -14,7 +14,7 @@
class osm_frame_widget;
class qtaxviewer_planetosm;
class qtwidget_planetosm;
namespace QTVOSM
{
class viewer_interface;
......@@ -25,6 +25,7 @@ namespace QTVOSM
class layer_interface
{
friend class tilesviewer;
friend class ::qtwidget_planetosm;
friend class ::osm_frame_widget;
friend class ::qtaxviewer_planetosm;
public:
......
#include "qtwidget_planetosm.h"
#include "osm_frame_widget.h"
#include <QSettings>
#include <QCoreApplication>
#include <QLibraryInfo>
#include <QDebug>
#include <functional>
#include <assert.h>
#include "osmtiles/tilesviewer.h"
#include "osmtiles/layer_tiles.h"
qtwidget_planetosm::qtwidget_planetosm(QWidget *parent )
:QWidget(parent)
,m_map_widget(0)
{
QCoreApplication * app = QCoreApplication::instance();
if (app)
{
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app->installTranslator(&qtTranslator);
QString strTransLocalFile =
QCoreApplication::applicationDirPath()+"/" +
"qtviewer_planetosm_"+
QLocale::system().name()+".qm";
if (true==appTranslator.load(strTransLocalFile ))
QTVOSM_DEBUG("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Succeeded.";
else
QTVOSM_WARNING("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Not Found.";
app->installTranslator(&appTranslator);
}
//create main widget
m_map_widget =new osm_frame_widget(this);
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
assert(mp!=NULL);
mp->viewer()->listen_event("ACTIVEX", std::bind(&qtwidget_planetosm::evt_listener,this,std::placeholders::_1));
QVector<layer_interface *> vec = mp->viewer()->layers();
foreach(layer_interface * p, vec)
{
p->load_retranslate_UI();
}
QTVOSM_DEBUG("The qtwidget_planetosm class constructed.");
}
qtwidget_planetosm::~qtwidget_planetosm()
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
assert(mp!=NULL);
mp->viewer()->unlisten_event("ACTIVEX") ;
}
void qtwidget_planetosm::resizeEvent(QResizeEvent * e)
{
if (!m_map_widget)
return;
if (e->size().width()>0)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
assert(mp!=NULL);
mp->setGeometry(0,0,e->size().width(),e->size().height());
}
QWidget::resizeEvent(e);
}
viewer_interface * qtwidget_planetosm::viewer()
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
assert(mp!=NULL);
return mp->viewer();
}
/*!
\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
http://192.168.11.27/new/osm.cgi?z=%1&x=%2&y=%3
\fn qtwidget_planetosm::setTileAddress
\param addr QString type address.
*/
void qtwidget_planetosm::osm_set_remote_address (QString layerName, QString addr)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
lt->setServerUrl(addr);
}
}
QString qtwidget_planetosm::osm_get_remote_address(QString layerName) const
{
QString res = "http://c.tile.openstreetmap.org/%1/%2/%3.png";
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
res = lt->serverUrl();
}
return res;
}
QString qtwidget_planetosm::osm_get_local_cache(QString layerName) const
{
QString res = "./OSMCache";
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
res = lt->localCache();
}
return res;
}
void qtwidget_planetosm::osm_set_local_cache (QString layerName, QString addr)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
lt->setLocalCache(addr);
}
}
int qtwidget_planetosm::osm_get_cache_expire_days(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
return lt->cacheExpireDays();
}
return 0;
}
int qtwidget_planetosm::osm_set_cache_expire_days(QString layerName,int days)
{
int res = 0;
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
{
lt->setCacheExpireDays(days);
res = days;
}
}
return res;
}
/*!
\brief This function is equal to check the "auto download" checkbox in UI
when the tile is not exist in local cache, layer will start a
task to download it from tileAddress()
\fn qtwidget_planetosm::ConnectToServer
*/
void qtwidget_planetosm::osm_set_auto_download (QString LayerName, int v)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(LayerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
lt->connectToTilesServer(v==0?false:true);
}
}
/*!
\brief return whether "auto download" checkbox is checked.
notice that even if this box is checked, if the URL of
remote tile server is not valid, this function will still return true.
\fn qtwidget_planetosm::IsConnected
\return int -1 means connected, 0 mean not.
*/
int qtwidget_planetosm::osm_get_auto_download(QString LayerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(LayerName);
if (la)
{
layer_tiles * lt = dynamic_cast<layer_tiles *>(la);
if (lt)
return lt->isConnected()==true?-1:0;
}
return 0;
}
int qtwidget_planetosm::osm_get_level(void)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
return pv->level();
}
int qtwidget_planetosm::osm_set_level(int lv)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
int res = pv->level();
pv->setLevel(lv);
return res;
}
double qtwidget_planetosm::osm_get_center_lat()
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
double lat,lon;
pv->centerLLA(&lat,&lon);
return lat;
}
double qtwidget_planetosm::osm_get_center_lon()
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
double lat,lon;
pv->centerLLA(&lat,&lon);
return lon;
}
int qtwidget_planetosm::osm_set_center_pos(double lat,double lon)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
pv->setCenterLLA(lat,lon);
return 1;
}
/*!
\brief this function does the samething as UI button "SaveImg"
it will call saveToImage() , and save current map view to file.
\fn qtwidget_planetosm::SaveCurrentViewToFile
\param fm filename in QString. ext name can specify the format.
\return int 1 means OK, 0 means failed.
*/
int qtwidget_planetosm::osm_save_view(QString fm)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
bool ok = pv->saveToImage(fm);
return ok==true?1:0;
}
/*!
\brief this protected function is designed to filter events, and fire OCX events when needed.
\fn qtwidget_planetosm::evt_listener
\param QMap<QString
\param e
*/
void qtwidget_planetosm::evt_listener(const QMap<QString, QVariant> e)
{
if (e["destin"]=="ALL" || e["destin"]=="OUTER")
{
emit map_event(e);
}
}
int qtwidget_planetosm::osm_layer_get_count()
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
return mp->viewer()->layerNames().size();
}
QString qtwidget_planetosm::osm_layer_get_name(int n)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
QVector<QString> names = mp->viewer()->layerNames();
if (n>=0 && n<names.size())
return names[n];
return "";
}
int qtwidget_planetosm::osm_layer_set_visiable(QString layerName, int v)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
la->set_visible(v==0?false:true);
pv->updateLayerGridView();
return la->is_visible()==false?0:-1;
}
return 0;
}
int qtwidget_planetosm::osm_layer_get_visiable(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
return la->is_visible()==false?0:-1;
return 0;
}
int qtwidget_planetosm::osm_layer_set_active(QString layerName, int v)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
la->set_active(v==0?false:true);
if (v!=0)
pv->adjust_layers(la);
pv->updateLayerGridView();
return la->is_active()==false?0:-1;
}
return 0;
}
int qtwidget_planetosm::osm_layer_get_active(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
return la->is_active()==false?0:-1;
return 0;
}
int qtwidget_planetosm::osm_layer_move_up(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
pv->moveLayerUp(la);
pv->updateLayerGridView();
return -1;
}
return 0;
}
int qtwidget_planetosm::osm_layer_move_down(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
pv->moveLayerDown(la);
pv->updateLayerGridView();
return -1;
}
return 0;
}
int qtwidget_planetosm::osm_layer_move_top(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
pv->moveLayerTop(la);
pv->updateLayerGridView();
return -1;
}
return 0;
}
int qtwidget_planetosm::osm_layer_move_bottom(QString layerName)
{
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);tilesviewer * pv=mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
{
pv->moveLayerBottom(la);
pv->updateLayerGridView();
return -1;
}
return 0;
}
/**
* @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_polygon;x=38.43834784;y=16.3834754;
* @return QString the result string is also formatted with key-vaslue para strings.
*/
QMap<QString, QVariant> qtwidget_planetosm::osm_layer_call_function(QString layerName, QMap<QString, QVariant> args)
{
QMap<QString, QVariant> p_out;
osm_frame_widget * mp = qobject_cast<osm_frame_widget *>(m_map_widget);
tilesviewer * pv = mp->viewer();
layer_interface * la = pv->layer(layerName);
if (la)
p_out = la->call_func(args);
else
p_out["error"] = QString("Layer name \"%1\" does not exist.").arg(layerName);
return p_out;
}
#ifndef QTWIDGET_PLANETOSM_H
#define QTWIDGET_PLANETOSM_H
#include <QTranslator>
#include <QMap>
#include <QVariant>
#include <QWidget>
#include "osmtiles/viewer_interface.h"
#ifdef PLANETOSM_EXPORT_DLL
#define PLANETOSMDLL Q_DECL_EXPORT
#else
#define PLANETOSMDLL Q_DECL_IMPORT
#endif
/*!
\brief This class inher from osm_frame_widget and QtDesigner,
Provides event systems and function call interface
\author goldenhawking \date 2016-02-14
*/
class PLANETOSMDLL qtwidget_planetosm :public QWidget
{
Q_OBJECT
protected:
QWidget * m_map_widget;
QTranslator qtTranslator;
QTranslator appTranslator;
void evt_listener(const QMap<QString, QVariant> e);
void resizeEvent(QResizeEvent * e);
public:
explicit qtwidget_planetosm(QWidget *parent = 0);
~qtwidget_planetosm();
//! slots below is designed for widget interfaces
public:
QTVOSM::viewer_interface * viewer();
QString osm_get_remote_address(QString layerName) const;
void osm_set_remote_address (QString layerName, QString addr);
QString osm_get_local_cache(QString layerName) const;
void osm_set_local_cache (QString layerName, QString addr);
int osm_get_cache_expire_days(QString layerName);
int osm_set_cache_expire_days(QString layerName,int days);
void osm_set_auto_download (QString layerName, int flag);
int osm_get_auto_download(QString layerName);
//Navigate
int osm_get_level(void);
int osm_set_level(int);
double osm_get_center_lat();
double osm_get_center_lon();
int osm_set_center_pos(double lat,double lon);
//! \brief PrintScreen
int osm_save_view(QString);
//layer methods
int osm_layer_get_count();
QString osm_layer_get_name(int n);
int osm_layer_set_visiable(QString layerName, int v);
int osm_layer_get_visiable(QString layerName);
int osm_layer_set_active(QString layerName, int v);
int osm_layer_get_active(QString layerName);
int osm_layer_move_up(QString layerName);
int osm_layer_move_down(QString layerName);
int osm_layer_move_top(QString layerName);
int osm_layer_move_bottom(QString layerName);
//function Calls
QMap<QString, QVariant> osm_layer_call_function(QString layerName, QMap<QString, QVariant> args);
signals:
void map_event(QMap<QString, QVariant> p);
};
#endif // QTWIDGET_PLANETOSM_H
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-19T17:46:14
#
#-------------------------------------------------
QT += core gui network designer
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
linux:QMAKE_CXXFLAGS += -std=c++11
win32-g++:QMAKE_CXXFLAGS += -std=c++11
TARGET = ../../bin/qtwidget_planetosm
TEMPLATE = lib
DEFINES += PLANETOSM_EXPORT_DLL
SOURCES += \
qtwidget_planetosm.cpp\
osm_frame_widget.cpp \
osmtiles/cProjectionMercator.cpp \
osmtiles/tilesviewer.cpp \
osmtiles/urlDownloader.cpp \
osmtiles/layer_tiles.cpp \
osmtiles/layer_browser.cpp \
osmtiles/layer_tiles_page.cpp
HEADERS += osm_frame_widget.h \
osmtiles/cProjectionMercator.h \
osmtiles/tilesviewer.h \
osmtiles/urlDownloader.h \
osmtiles/layer_tiles.h \
osmtiles/layer_browser.h \
osmtiles/layer_interface.h \
osmtiles/viewer_interface.h \
osmtiles/layer_tiles_page.h \
qtwidget_planetosm.h
FORMS += osm_frame_widget.ui \
osmtiles/layer_tiles_page.ui
win32{
OTHER_FILES += \
qtviewer_planetosm_zh_CN.ts
}
RESOURCES += \
resource/resource.qrc
TRANSLATIONS += qtviewer_planetosm_zh_CN.ts
......@@ -10,6 +10,8 @@
#include <QMutex>
#include <QMap>
#include <assert.h>
#include <QMessageBox>
#include <QSettings>
/*!
* The plugin dynamic library (.dll in windows or .so in linux) will be loaded into memory only once.
* for example, a windows app like test_container will contain 2 qtaxviewer_planetosm OCX ctrls ,
......@@ -33,6 +35,7 @@ qtvplugin_grid::qtvplugin_grid(QWidget *parent) :
m_pt_end = QPointF(-1,-1);
bFinished = true;
m_bActive = false;
m_nMarks = 0;
}
qtvplugin_grid::~qtvplugin_grid()
......@@ -71,6 +74,8 @@ layer_interface * qtvplugin_grid::load_initial_plugin(QString strSLibPath,viewer
{
QFileInfo info(strSLibPath);
m_SLLibName = info.completeBaseName();
m_SLLibPath = strSLibPath;
m_pVi = ptrviewer;
mutex_instances.lock();
......@@ -78,6 +83,7 @@ layer_interface * qtvplugin_grid::load_initial_plugin(QString strSLibPath,viewer
mutex_instances.unlock();
loadTranslation();
load_ini();
}
//!3.if the instance not correspones to this, call the instances' load_initial_plugin instead.
else
......@@ -222,21 +228,35 @@ void qtvplugin_grid::cb_paintEvent( QPainter * pImage )
}
pImage->setPen(pen_area);
int x1,y1,x2,y2;
int sz = m_list_points.size();
QPen pen_text(QColor(0,0,255));
for (int i=0;i<sz-1;++i)
{
m_pVi->CV_LLA2DP(m_list_points[i].x(),m_list_points[i].y(),&x1,&y1);
m_pVi->CV_LLA2DP(m_list_points[i+1].x(),m_list_points[i+1].y(),&x2,&y2);
pImage->setPen(pen_area);
pImage->drawLine(x1,y1,x2,y2);
double sita;
double dis = CalDistance(m_list_points[i].x(),m_list_points[i+1].x(),m_list_points[i].y(),m_list_points[i+1].y(), &sita);
sprintf(str,"%.2lfkm",dis/1000.0);
pImage->setPen(pen_text);
QPointF pos = QLineF(x1,y1,x2,y2).pointAt(i*0.8 / sz+0.1);
pImage->drawText(pos,str);
}
if (bFinished==false && sz>0)
{
m_pVi->CV_LLA2DP(m_list_points.last().x(),m_list_points.last().y(),&x1,&y1);
m_pVi->CV_LLA2DP(m_pt_end.x(),m_pt_end.y(),&x2,&y2);
pImage->setPen(pen_area);
pImage->drawLine(x1,y1,x2,y2);
double sita;
double dis = CalDistance(m_list_points.last().x(),m_pt_end.x(),m_list_points.last().y(),m_pt_end.y(), &sita);
sprintf(str,"%.1lfkm",dis/1000.0);
pImage->setPen(pen_text);
QPointF pos = QLineF(x1,y1,x2,y2).pointAt(1*0.8 / sz+0.1);
pImage->drawText(pos,str);
}
pImage->setPen(oldpen);
}
......@@ -278,6 +298,7 @@ void qtvplugin_grid::set_name(QString /*vb*/)
}
void qtvplugin_grid::on_checkBox_measure_clicked(bool acti)
{
save_ini();
m_bActive = acti;
m_pVi->updateLayerGridView();
}
......@@ -292,7 +313,7 @@ bool qtvplugin_grid::cb_mouseMoveEvent(QMouseEvent * e )
if (m_pVi==0)
return false;
m_mousePos = e->pos();
if (m_bActive==false)
if (m_bVisible==true)
{
double clat,clon;
char buftmp[256];
......@@ -304,8 +325,9 @@ bool qtvplugin_grid::cb_mouseMoveEvent(QMouseEvent * e )
sprintf (buftmp,"Center LAT=%14.9lf, LON=%14.9lf",clat,clon);
strMsg += buftmp;
ui->plainTextEdit_cursor->setPlainText(strMsg);
return false;
}
if (m_bActive==false)
return false;
if (m_list_points.size()>0&&bFinished==false)
{
QPoint pt = e->pos();
......@@ -688,3 +710,142 @@ QMap<QString, QVariant> qtvplugin_grid::call_func(const QMap<QString, QVariant>
res["error"] = "\"function\" keyword not specified, nothing to do.";
return std::move(res);
}
void qtvplugin_grid::on_pushButton_add_mark_clicked()
{
if (!m_pVi)
return;
QString strMarkerName = QString("geomarker%1").arg(m_nInstance);
layer_interface * pif = m_pVi->layer(strMarkerName);
save_ini();
QString strAll = ui->plainTextEdit_markcmd->toPlainText();
QStringList strLines = strAll.split("\n",QString::SkipEmptyParts);
foreach (QString str, strLines)
{
QString strRegWest = QString("([%1])+").arg(ui->lineEdit_west_spliter->text());
QString strRegsout = QString("([%1])+").arg(ui->lineEdit_south_spliter->text());
int latNG = 1, lonNG = 1;
if (str.indexOf(QRegExp(strRegWest))>=0)
lonNG=-1;
if (str.indexOf(QRegExp(strRegsout))>=0)
latNG=-1;
QStringList lst = str.split(QRegExp("([^0123456789.-])+"),QString::SkipEmptyParts);
double lat = 0, lon = 0;
if (lst.size()==6)
{
lat = lst.first().toDouble(); lst.pop_front();
lat += lst.first().toDouble() /60.0; lst.pop_front();
lat += lst.first().toDouble() /3600.0; lst.pop_front();
lon = lst.first().toDouble(); lst.pop_front();
lon += lst.first().toDouble() /60.0; lst.pop_front();
lon += lst.first().toDouble() /3600.0;
}
else if (lst.size()==4)
{
lat = lst.first().toDouble(); lst.pop_front();
lat += lst.first().toDouble() /60.0; lst.pop_front();
lon = lst.first().toDouble(); lst.pop_front();
lon += lst.first().toDouble() /60.0;
}
else if (lst.size()==2)
{
lat = lst.first().toDouble(); lst.pop_front();
lon = lst.first().toDouble();
}
else
{
QMessageBox::warning(
this,
tr("Error LLA formar"),
tr("Lat will be first, lon will be last, lat lon must have same element nums.")
);
break;
}
lat *= latNG;
lon *= lonNG;
if (pif)
{
QMap<QString, QVariant> inPara, outPara;
inPara["function"] = "update_point";
inPara["name"] = QString("%1_%2").arg(get_name()).arg(m_nMarks);
inPara["lat"] = lat;
inPara["lon"] = lon;
inPara["color_pen"] = "0,0,255,128";
inPara["color_brush"] = "0,0,0,64";
inPara["width"] = "7";
inPara["height"] = "7";
inPara["type"] = 1;
outPara = pif->call_func(inPara);
inPara.clear();
inPara["function"] = "update_props";
inPara["name"] = QString("%1_%2").arg(get_name()).arg(m_nMarks);
inPara["LABEL"] = QString("%1,%2").arg(lat).arg(lon);
++m_nMarks;
outPara = pif->call_func(inPara);
}
}
}
void qtvplugin_grid::on_pushButton_clear_clicked()
{
if (!m_pVi || m_nMarks<=0)
return;
save_ini();
QString strMarkerName = QString("geomarker%1").arg(m_nInstance);
layer_interface * pif = m_pVi->layer(strMarkerName);
if (pif)
{
QMap<QString, QVariant> inPara, outPara;
inPara["function"] = "delete_marks";
for (int i=0;i<m_nMarks;++i)
inPara[QString("name%1").arg(i)] = QString("%1_%2").arg(get_name()).arg(i);
outPara = pif->call_func(inPara);
}
m_nMarks = 0;
}
void qtvplugin_grid::on_pushButton_clear_all_clicked()
{
if (!m_pVi)
return;
save_ini();
QString strMarkerName = QString("geomarker%1").arg(m_nInstance);
layer_interface * pif = m_pVi->layer(strMarkerName);
if (pif)
{
QMap<QString, QVariant> inPara, outPara;
inPara["function"] = "delete_marks";
outPara = pif->call_func(inPara);
}
m_nMarks = 0;
}
QString qtvplugin_grid::ini_file()
{
if (m_SLLibPath.size())
return m_SLLibPath + QString("%1").arg(m_nInstance) + ".ini";
else
return QCoreApplication::applicationFilePath() + QString("/grid%1.ini").arg(m_nInstance);
}
void qtvplugin_grid::load_ini()
{
QSettings settings(ini_file(),QSettings::IniFormat);
ui->lineEdit_south_spliter->setText(settings.value("settings/lineEdit_south_spliter","S").toString());
ui->lineEdit_west_spliter->setText(settings.value("settings/lineEdit_west_spliter","W").toString());
ui->plainTextEdit_markcmd->setPlainText(settings.value("settings/plainTextEdit_markcmd","").toString());
}
void qtvplugin_grid::save_ini()
{
QSettings settings(ini_file(),QSettings::IniFormat);
settings.setValue("settings/lineEdit_south_spliter",ui->lineEdit_south_spliter->text());
settings.setValue("settings/lineEdit_west_spliter",ui->lineEdit_west_spliter->text());
settings.setValue("settings/plainTextEdit_markcmd",ui->plainTextEdit_markcmd->toPlainText());
}
......@@ -37,20 +37,24 @@ public:
private:
int m_nInstance;
//International Translator
QTranslator pluginTranslator;
Ui::qtvplugin_grid *ui;
QTranslator pluginTranslator;
Ui::qtvplugin_grid * ui;
//the pointer to main MAP functions
viewer_interface * m_pVi;
viewer_interface * m_pVi;
//Flags
bool m_bVisible;
bool m_bActive;
bool m_bVisible;
bool m_bActive;
//Lib Name
QString m_SLLibName;
QString m_SLLibName;
QString m_SLLibPath;
//Measure
QPointF m_pt_end;
QPoint m_mousePos;
QVector<QPointF> m_list_points;
bool bFinished;
QPointF m_pt_end;
QPoint m_mousePos;
QVector<QPointF> m_list_points;
bool bFinished;
//simple mark
int m_nMarks;
//measure method
void CalArea();
double GetArea(double * PointX,double * PointY,int Count);
......@@ -60,6 +64,9 @@ protected:
layer_interface * load_initial_plugin(QString strSLibPath,viewer_interface * ptrviewer);
QWidget * load_prop_window();
void load_retranslate_UI();
void load_ini();
void save_ini();
QString ini_file();
protected:
//Events
void cb_paintEvent( QPainter * pImage );
......@@ -69,7 +76,9 @@ protected:
bool cb_event(const QMap<QString, QVariant>);
protected slots:
void on_checkBox_measure_clicked(bool);
void on_pushButton_add_mark_clicked();
void on_pushButton_clear_clicked();
void on_pushButton_clear_all_clicked();
};
#endif // QTVPLUGIN_GRID_H
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>394</width>
<height>280</height>
<width>392</width>
<height>384</height>
</rect>
</property>
<property name="windowTitle">
......@@ -17,7 +17,7 @@
<iconset resource="resources.qrc">
<normaloff>:/icons/Brush_Ruler_Alt.png</normaloff>:/icons/Brush_Ruler_Alt.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -46,6 +46,87 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Mark</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit_markcmd">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>64</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>West spliter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_west_spliter"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>South spliter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_south_spliter"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>37</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_add_mark">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_clear">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_clear_all">
<property name="text">
<string>Clear All</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
......@@ -58,7 +139,7 @@
<property name="maximumSize">
<size>
<width>16777215</width>
<height>128</height>
<height>64</height>
</size>
</property>
</widget>
......
#include "osm_designer_plugin.h"
#include "../qtviewer_planetosm/qtwidget_planetosm.h"
osm_designer_plugin::osm_designer_plugin(QObject *parent) :
QObject(parent),
initialized(false)
{
}
bool osm_designer_plugin::isContainer() const
{
return false;
}
bool osm_designer_plugin::isInitialized() const
{
return initialized;
}
QIcon osm_designer_plugin::icon() const
{
return QIcon(":/ui/icons/Blizzard17.png");
}
QString osm_designer_plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"qtwidget_planetosm\" name=\"osmmap\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>640</width>\n"
" <height>480</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>";
}
QString osm_designer_plugin::group() const
{
return "Display Widgets";
}
QString osm_designer_plugin::includeFile() const
{
return "qtwidget_planetosm.h";
}
QString osm_designer_plugin::name() const
{
return "qtwidget_planetosm";
}
QString osm_designer_plugin::toolTip() const
{
return "A widget that provides full access to OSM tiles of planetosm.";
}
QString osm_designer_plugin::whatsThis() const
{
return "A widget that provides full access to OSM tiles of planetosm.";
}
QWidget *osm_designer_plugin::createWidget(QWidget *parent)
{
return new qtwidget_planetosm(parent);
}
void osm_designer_plugin::initialize(QDesignerFormEditorInterface *core)
{
if (initialized)
return;
initialized = true;
}
#ifndef OSM_DESIGNER_PLUGIN_H
#define OSM_DESIGNER_PLUGIN_H
#include <QObject>
#include <QDesignerCustomWidgetCollectionInterface>
#include "qtwidget_planetosm_designer_global.h"
class QTWIDGET_PLANETOSM_DESIGNERSHARED_EXPORT osm_designer_plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit osm_designer_plugin(QObject *parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget *createWidget(QWidget *parent);
void initialize(QDesignerFormEditorInterface *core);
private:
bool initialized;
};
#endif // OSM_DESIGNER_PLUGIN_H
#-------------------------------------------------
#
# Project created by QtCreator 2016-03-03T09:12:05
#
#-------------------------------------------------
QT += widgets network designer
linux:QMAKE_CXXFLAGS += -std=c++11
win32-g++:QMAKE_CXXFLAGS += -std=c++11
TARGET = ../../bin/qtwidget_planetosm_designer
TEMPLATE = lib
LIBS += -L$$OUT_PWD/../bin
LIBS += -lqtwidget_planetosm
DEFINES += QTWIDGET_PLANETOSM_DESIGNER_LIBRARY
SOURCES += osm_designer_plugin.cpp
HEADERS += osm_designer_plugin.h\
qtwidget_planetosm_designer_global.h
#ifndef QTWIDGET_PLANETOSM_DESIGNER_GLOBAL_H
#define QTWIDGET_PLANETOSM_DESIGNER_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(QTWIDGET_PLANETOSM_DESIGNER_LIBRARY)
# define QTWIDGET_PLANETOSM_DESIGNERSHARED_EXPORT Q_DECL_EXPORT
#else
# define QTWIDGET_PLANETOSM_DESIGNERSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // QTWIDGET_PLANETOSM_DESIGNER_GLOBAL_H
......@@ -11,6 +11,9 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ../../bin/test_container
TEMPLATE = app
LIBS += -L$$OUT_PWD/../bin
LIBS += -lqtwidget_planetosm
INCLUDEPATH += $$PWD/../qtviewer_planetosm
SOURCES += main.cpp\
testcontainer.cpp
......
此差异已折叠。
......@@ -23,6 +23,9 @@ protected:
private:
Ui::testcontainer *ui;
int m_nAnTimer;
QString m_str_gridLayerName;
QString m_str_markerLayerName;
void confirmLayerNames();
protected slots:
void slot_message(QString);
void on_pushButton_test_adds_clicked();
......@@ -39,6 +42,7 @@ protected slots:
void on_pushButton_test_request_clicked();
void on_pushButton_test_xml_clicked();
void on_pushButton_test_resource_clicked();
void on_osmmap_map_event(QMap<QString, QVariant> p);
};
#endif // TESTCONTAINER_H
......@@ -193,7 +193,7 @@
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Map1</string>
<string>AxMap1</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
......@@ -203,7 +203,7 @@
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Map2</string>
<string>AxMap2</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
......@@ -218,6 +218,16 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="WidgetMap">
<attribute name="title">
<string>WidgetMap</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="qtwidget_planetosm" name="osmmap" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
......@@ -254,6 +264,11 @@
<extends>QWidget</extends>
<header>qaxwidget.h</header>
</customwidget>
<customwidget>
<class>qtwidget_planetosm</class>
<extends>QWidget</extends>
<header>qtwidget_planetosm.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册