PDA

View Full Version : Qt and Envitia (Tenet) MapLink Pro Accelerator toolkit



martinb0820
12th February 2010, 19:13
Has anyone used Qt with MapLink Pro's Accelerator toolkit? I would like to see a minimal example of its use with Qt.
Thanks!

ibecker
12th April 2012, 17:01
Hi, I know this is an old thread, but I just got this working myself. I found this thread while doing some searching on my own and it was no help.

So, I thought I would reply and show what I did to make MapLink Pro 6.0 work with Qt 4.8.

Firstly, make a custom QWidget class. Then in the widget's constructor, set the following attributes.



setAttribute(Qt::WA_NoBackground, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_PaintOnScreen, true);
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, true);


You will also need to override the paintEngine function like so:


QPaintEngine* paintEngine() const //Works in conjunction with WA_PaintOnScreen
{
return NULL;
}


Override the paintEvent:


void QMapView::paintEvent(QPaintEvent *)
{
if (m_bInitialUpdate) //Set to true in constructor
{
MainWindow* main = static_cast<MainWindow*>(parentWidget()->parentWidget());
if (main)
{
HWND hWnd = (HWND)winId();
m_drawingSurface = new TSLNTSurface(hWnd, false);
m_drawingSurface->setOption( TSLOptionDoubleBuffered, true ) ;
m_drawingSurface->wndResize( 0, 0, rect().width(), rect().height() ) ;

m_drawingSurface->addDataLayer(main->m_dataLayer, "map");
m_drawingSurface->addDataLayer(main->m_stdDataLayer, "overlay"); //Not needed if you don't want an overlay
m_drawingSurface->reset(false);
m_bMapLoaded = true;
m_drawingSurface->setDataLayerProps( "map" , TSLPropertyBuffered , 1 ) ;
}

m_bInitialUpdate = false;
}
if (m_drawingSurface)
m_drawingSurface->drawDU(rect().left(), rect().top(), rect().right(), rect().bottom(), true, true);
}


In our main window:


TSLErrorStack::clear();
TSLDrawingSurface::loadStandardConfig();

QString err(TSLErrorStack::errorString());
if (!err.isNull())
qDebug(qPrintable(err));

m_dataLayer = new TSLMapDataLayer();
QString filename = QFileDialog::getOpenFileName(this, "Open map"); //Get a map to open
m_dataLayer->loadData(filename.toStdString().c_str());

err = TSLErrorStack::errorString("Cannot load map\n");
if (!err.isNull())
{
m_bMapLoaded = false;
qDebug(qPrintable(err));
}
m_stdDataLayer = new TSLStandardDataLayer();


In the .pro file:


LIBS += -L<MapLinkDirHere>/lib -lMapLink
INCLUDEPATH += <MapLinkDirHere>/include
DEPENDPATH += <MapLinkDirHere>/include

When I used -lMapLinkd, there we crashes. Using the non-debug library works fine and there still seems to be debug information available.


This should be all you need to get MapLink to draw a map in your custom QWidget. Override methods for mouse events, resize events, keyboard events as you need.


Make sure to include "MapLink.h" where needed!