1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

OP-107 Add the model connected to the waypoints so that the waypoints show up and

update when connected
This commit is contained in:
James Cotton 2012-05-09 15:51:04 -05:00
parent 15067b010f
commit d42bdacc46
6 changed files with 244 additions and 9 deletions

View File

@ -5,12 +5,14 @@ include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri) include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri) include(../../plugins/uavobjects/uavobjects.pri)
HEADERS += waypointeditorgadget.h HEADERS += waypointeditorgadget.h \
waypointtable.h
HEADERS += waypointeditorgadgetwidget.h HEADERS += waypointeditorgadgetwidget.h
HEADERS += waypointeditorgadgetfactory.h HEADERS += waypointeditorgadgetfactory.h
HEADERS += waypointeditorplugin.h HEADERS += waypointeditorplugin.h
SOURCES += waypointeditorgadget.cpp SOURCES += waypointeditorgadget.cpp \
waypointtable.cpp
SOURCES += waypointeditorgadgetwidget.cpp SOURCES += waypointeditorgadgetwidget.cpp
SOURCES += waypointeditorgadgetfactory.cpp SOURCES += waypointeditorgadgetfactory.cpp
SOURCES += waypointeditorplugin.cpp SOURCES += waypointeditorplugin.cpp
@ -20,3 +22,5 @@ OTHER_FILES += waypointeditor.pluginspec
FORMS += waypointeditor.ui FORMS += waypointeditor.ui
RESOURCES += waypointeditor.qrc RESOURCES += waypointeditor.qrc

View File

@ -21,19 +21,33 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QTableView" name="tableView"> <widget class="QTableView" name="waypoints">
<attribute name="horizontalHeaderCascadingSectionResizes"> <attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="buttonNewWaypoint">
<property name="text"> <property name="text">
<string>New Waypoint</string> <string>New Waypoint</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="buttonSaveFile">
<property name="text">
<string>Save to File</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonLoadFile">
<property name="text">
<string>Load from File</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -34,16 +34,29 @@
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include "uavobject.h"
#include "uavobjectmanager.h"
#include "manualcontrolcommand.h"
#include "extensionsystem/pluginmanager.h"
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
WaypointEditorGadgetWidget::WaypointEditorGadgetWidget(QWidget *parent) : QLabel(parent) WaypointEditorGadgetWidget::WaypointEditorGadgetWidget(QWidget *parent) : QLabel(parent)
{ {
m_waypointeditor = new Ui_WaypointEditor(); m_waypointeditor = new Ui_WaypointEditor();
m_waypointeditor->setupUi(this); m_waypointeditor->setupUi(this);
waypointTable = new WaypointTable(this);
m_waypointeditor->waypoints->setModel(waypointTable);
// Get the objects used here
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager);
Q_ASSERT(waypointActiveObj != NULL);
// Connect the signals
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointActiveChanged(UAVObject*)));
connect(m_waypointeditor->buttonNewWaypoint, SIGNAL(clicked()),
this, SLOT(addInstance()));
} }
WaypointEditorGadgetWidget::~WaypointEditorGadgetWidget() WaypointEditorGadgetWidget::~WaypointEditorGadgetWidget()

View File

@ -28,7 +28,7 @@
#define WaypointEditorGADGETWIDGET_H_ #define WaypointEditorGADGETWIDGET_H_
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <waypoint.h> #include <waypointtable.h>
#include <waypointactive.h> #include <waypointactive.h>
class Ui_WaypointEditor; class Ui_WaypointEditor;
@ -50,6 +50,8 @@ protected slots:
private: private:
Ui_WaypointEditor * m_waypointeditor; Ui_WaypointEditor * m_waypointeditor;
WaypointTable *waypointTable;
WaypointActive *waypointActiveObj;
}; };
#endif /* WaypointEditorGADGETWIDGET_H_ */ #endif /* WaypointEditorGADGETWIDGET_H_ */

View File

@ -0,0 +1,141 @@
/**
******************************************************************************
* @file waypointtable.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup Waypoint Editor GCS Plugins
* @{
* @addtogroup WaypointEditorGadgetPlugin Waypoint Editor Gadget Plugin
* @{
* @brief Table model for listing waypoint
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <QDebug>
#include <QBrush>
#include "waypointtable.h"
#include "extensionsystem/pluginmanager.h"
WaypointTable::WaypointTable(QObject *parent) :
QAbstractTableModel(parent)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
waypointObj = Waypoint::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL);
waypointActiveObj = WaypointActive::GetInstance(objManager);
Q_ASSERT(waypointObj != NULL);
elements = 0;
connect(waypointActiveObj, SIGNAL(objectUpdated(UAVObject*)),
this, SLOT(waypointsUpdated(UAVObject*)));
connect(waypointObj, SIGNAL(),
this, SLOT(waypointsUpdated(UAVObject*)));
headers.clear();
headers.append(QString("North"));
headers.append(QString("East"));
headers.append(QString("Down"));
}
int WaypointTable::rowCount(const QModelIndex &parent) const
{
return elements;
}
int WaypointTable::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return headers.length();
}
QVariant WaypointTable::data(const QModelIndex &index, int role) const
{
if(role == Qt::DisplayRole) {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
Waypoint *obj = Waypoint::GetInstance(objManager, index.row());
Q_ASSERT(obj);
Waypoint::DataFields waypoint = obj->getData();
switch(index.column()) {
case 0:
return waypoint.Position[Waypoint::POSITION_NORTH];
case 1:
return waypoint.Position[Waypoint::POSITION_EAST];
case 2:
return waypoint.Position[Waypoint::POSITION_DOWN];
default:
Q_ASSERT(0);
return 0;
}
} else if (role == Qt::BackgroundRole) {
WaypointActive::DataFields waypointActive = waypointActiveObj->getData();
if(index.row() == waypointActive.Index) {
return QBrush(Qt::lightGray);
} else
return QVariant::Invalid;
}
else {
return QVariant::Invalid;
}
}
QVariant WaypointTable::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if(section < headers.length())
return headers[section];
return QVariant::Invalid;
} else
return QAbstractTableModel::headerData(section, orientation, role);
}
/**
* Called whenever the waypoints are updated to inform
* the view
*/
void WaypointTable::waypointsUpdated(UAVObject *)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Q_ASSERT(pm != NULL);
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager != NULL);
int elementsNow = objManager->getNumInstances(waypointObj->getObjID());
// Currently only support adding instances which is all the UAVO manager
// supports
if (elementsNow > elements) {
beginInsertRows(QModelIndex(), elements, elementsNow);
elements = elementsNow;
endInsertRows();
}
QModelIndex i1 = index(0,0);
QModelIndex i2 = index(elements, columnCount(QModelIndex()));
qDebug() << "Waypoints updated. Found " << rowCount(QModelIndex());
emit dataChanged(i1, i2);
}

View File

@ -0,0 +1,61 @@
/**
******************************************************************************
* @file waypointtable.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup Waypoint Editor GCS Plugins
* @{
* @addtogroup WaypointEditorGadgetPlugin Waypoint Editor Gadget Plugin
* @{
* @brief Table model for listing waypoint
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef WAYPOINTTABLE_H
#define WAYPOINTTABLE_H
#include <QAbstractTableModel>
#include <QList>
#include <QString>
#include <waypoint.h>
#include <waypointactive.h>
class WaypointTable : public QAbstractTableModel
{
Q_OBJECT
public:
explicit WaypointTable(QObject *parent = 0);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
signals:
protected slots:
void waypointsUpdated(UAVObject *);
public slots:
private:
Waypoint *waypointObj;
WaypointActive *waypointActiveObj;
QList <QString> headers;
int elements;
};
#endif // WAYPOINTTABLE_H