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