Commit fd6c038e authored by lm's avatar lm

Cleaned up serial link handling, eliminated double menu entries and...

Cleaned up serial link handling, eliminated double menu entries and safeguarded the link list. Did intentionally not improve the object dependency issue, will work on that on a global scope
parent 35898750
......@@ -153,7 +153,7 @@ namespace qmapcontrol
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
tileData.save(&buffer, "PNG");
// FIXME This is weird - why first write in buffer and then in file?
file.write(bytes);
file.close();
return true;
......
......@@ -39,10 +39,10 @@ namespace qmapcontrol
delete mapAdapter;
}
void Layer::setSize(QSize size)
void Layer::setSize(QSize size, QPoint screenmiddle)
{
this->size = size;
screenmiddle = QPoint(size.width()/2, size.height()/2);
this->screenmiddle = screenmiddle;// QPoint(size.width()/2, size.height()/2);
//QMatrix mat;
//mat.translate(480/2, 640/2);
//mat.rotate(45);
......@@ -292,10 +292,12 @@ namespace qmapcontrol
// PREFETCHING
int upper = mapmiddle_tile_y-tiles_above-1;
int right = mapmiddle_tile_x+tiles_right+1;
int left = mapmiddle_tile_x-tiles_right-1;
int lower = mapmiddle_tile_y+tiles_bottom+1;
// FIXME Make prefetching a parameter
int upper = mapmiddle_tile_y-tiles_above-2;
int right = mapmiddle_tile_x+tiles_right+2;
int left = mapmiddle_tile_x-tiles_right-2;
int lower = mapmiddle_tile_y+tiles_bottom+2;
int j = upper;
for (int i=left; i<=right; i++)
......
......@@ -139,7 +139,7 @@ namespace qmapcontrol
void moveWidgets(const QPoint mapmiddle_px) const;
void drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const;
void drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const;
void setSize(QSize size);
void setSize(QSize size, QPoint screenmiddle);
QRect offscreenViewport() const;
bool takesMouseEvents() const;
void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
......
......@@ -47,6 +47,7 @@ namespace qmapcontrol
offFactor = factor;
composedOffscreenImage = QPixmap(offSize);
composedOffscreenImage2 = QPixmap(offSize);
resize(size);
}
float LayerManager::offscreenImageFactor()
......@@ -219,7 +220,7 @@ namespace qmapcontrol
{
mylayers.append(layer);
layer->setSize(size);
layer->setSize(size, screenmiddle);
connect(layer, SIGNAL(updateRequest(QRectF)),
this, SLOT(updateRequest(QRectF)));
......@@ -493,7 +494,7 @@ namespace qmapcontrol
while (it.hasNext())
{
Layer* l = it.next();
l->setSize(newSize);
l->setSize(newSize, screenmiddle);
}
newOffscreenImage();
......
......@@ -66,10 +66,13 @@ LinkManager::~LinkManager()
void LinkManager::add(LinkInterface* link)
{
if(!link) return;
connect(link, SIGNAL(destroyed(QObject*)), this, SLOT(removeLink(QObject*)));
links.append(link);
emit newLink(link);
if (!links.contains(link))
{
if(!link) return;
connect(link, SIGNAL(destroyed(QObject*)), this, SLOT(removeLink(QObject*)));
links.append(link);
emit newLink(link);
}
}
void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol)
......@@ -77,9 +80,18 @@ void LinkManager::addProtocol(LinkInterface* link, ProtocolInterface* protocol)
// Connect link to protocol
// the protocol will receive new bytes from the link
if(!link || !protocol) return;
connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray)));
// Store the connection information in the protocol links map
protocolLinks.insertMulti(protocol, link);
QList<LinkInterface*> linkList = protocolLinks.values(protocol);
// If protocol has not been added before (list length == 0)
// OR if link has not been added to protocol, add
if ((linkList.length() > 0 && !linkList.contains(link)) || linkList.length() == 0)
{
// Protocol is new, add
connect(link, SIGNAL(bytesReceived(LinkInterface*, QByteArray)), protocol, SLOT(receiveBytes(LinkInterface*, QByteArray)));
// Store the connection information in the protocol links map
protocolLinks.insertMulti(protocol, link);
}
//qDebug() << __FILE__ << __LINE__ << "ADDED LINK TO PROTOCOL" << link->getName() << protocol->getName() << "NEW SIZE OF LINK LIST:" << protocolLinks.size();
}
......
......@@ -154,7 +154,7 @@ void MAVLinkSimulationLink::sendMAVLinkMessage(const mavlink_message_t* msg)
// Pack to link buffer
readyBufferMutex.lock();
for (int i = 0; i < bufferlength; i++)
for (unsigned int i = 0; i < bufferlength; i++)
{
readyBuffer.enqueue(*(buf + i));
}
......@@ -954,6 +954,7 @@ bool MAVLinkSimulationLink::connect()
start(LowPriority);
MAVLinkSimulationMAV* mav1 = new MAVLinkSimulationMAV(this, 1);
Q_UNUSED(mav1);
// timer->start(rate);
return true;
}
......
......@@ -87,9 +87,6 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P
#endif
loadSettings();
// Link is setup, register it with link manager
LinkManager::instance()->add(this);
}
SerialLink::~SerialLink()
......
......@@ -68,6 +68,8 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
// Create configuration action for this link
// Connect the current UAS
action = new QAction(QIcon(":/images/devices/network-wireless.svg"), "", link);
LinkManager::instance()->add(link);
action->setData(LinkManager::instance()->getLinks().indexOf(link));
setLinkName(link->getName());
connect(action, SIGNAL(triggered()), this, SLOT(show()));
......@@ -209,11 +211,12 @@ void CommConfigurationWindow::remove()
link->disconnect(); //disconnect port, and also calls terminate() to stop the thread
if (link->isRunning()) link->terminate(); // terminate() the serial thread just in case it is still running
link->wait(); // wait() until thread is stoped before deleting
delete link;
link->deleteLater();
}
link=NULL;
this->window()->close();
this->deleteLater();
}
void CommConfigurationWindow::connectionState(bool connect)
......
......@@ -1205,18 +1205,27 @@ void MainWindow::addLink()
SerialLink* link = new SerialLink();
// TODO This should be only done in the dialog itself
LinkManager::instance()->add(link);
LinkManager::instance()->addProtocol(link, mavlink);
CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
ui.menuNetwork->addAction(commWidget->getAction());
// Go fishing for this link's configuration window
QList<QAction*> actions = ui.menuNetwork->actions();
commWidget->show();
foreach (QAction* act, actions)
{
if (act->data().toInt() == LinkManager::instance()->getLinks().indexOf(link))
{
act->trigger();
break;
}
}
}
void MainWindow::addLink(LinkInterface *link)
{
LinkManager::instance()->add(link);
LinkManager::instance()->addProtocol(link, mavlink);
CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
ui.menuNetwork->addAction(commWidget->getAction());
......
......@@ -42,14 +42,6 @@ MapWidget::MapWidget(QWidget *parent) :
QString buttonStyle("QAbstractButton { background-color: rgba(20, 20, 20, 45%); border-color: rgba(10, 10, 10, 50%)} QDoubleSpinBox { background-color: rgba(20, 20, 20, 45%); border-color: rgba(10, 10, 10, 50%)}");
mc->setPen(QGC::colorCyan.darker(400));
waypointIsDrag = false;
// Accept focus by clicking or keyboard
......@@ -267,6 +259,10 @@ MapWidget::MapWidget(QWidget *parent) :
drawCamBorder = false;
radioCamera = 10;
// mc->setZoom(20);
// //mc->resize(QSize(7025, 4968));
// mc->resize(QSize(3000, 2000));
//mc->setOffscreenImageFactor(15);
}
......
......@@ -320,7 +320,8 @@ userConfigured(false)
}
}
SerialConfigurationWindow::~SerialConfigurationWindow() {
SerialConfigurationWindow::~SerialConfigurationWindow()
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment