2 ******************************************************************************
3 * @file pathactioneditorgadgetwidget.cpp
4 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
5 * @addtogroup PathAction Editor GCS Plugins
7 * @addtogroup PathActionEditorGadgetPlugin PathAction Editor Gadget Plugin
9 * @brief A gadget to edit a list of pathactions
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "pathactioneditorgadgetwidget.h"
27 #include "ui_pathactioneditor.h"
28 #include "extensionsystem/pluginmanager.h"
29 #include "uavobjectmanager.h"
31 #include "browseritemdelegate.h"
35 #include <QStringList>
38 #include <QVBoxLayout>
39 #include <QPushButton>
41 PathActionEditorGadgetWidget::PathActionEditorGadgetWidget(QWidget
*parent
) : QLabel(parent
)
43 m_pathactioneditor
= new Ui_PathActionEditor();
44 m_pathactioneditor
->setupUi(this);
46 m_model
= new PathActionEditorTreeModel();
47 m_pathactioneditor
->pathactions
->setModel(m_model
);
48 m_pathactioneditor
->pathactions
->setColumnWidth(0, 300);
49 m_pathactioneditor
->pathactions
->setColumnWidth(1, 500);
50 m_pathactioneditor
->pathactions
->expandAll();
51 BrowserItemDelegate
*m_delegate
= new BrowserItemDelegate();
52 m_pathactioneditor
->pathactions
->setItemDelegate(m_delegate
);
53 m_pathactioneditor
->pathactions
->setEditTriggers(QAbstractItemView::AllEditTriggers
);
54 m_pathactioneditor
->pathactions
->setSelectionBehavior(QAbstractItemView::SelectItems
);
56 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
58 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
59 Q_ASSERT(objManager
!= NULL
);
60 pathactionObj
= PathAction::GetInstance(objManager
);
61 Q_ASSERT(pathactionObj
!= NULL
);
62 waypointObj
= Waypoint::GetInstance(objManager
);
63 Q_ASSERT(waypointObj
!= NULL
);
65 // Connect the signals
66 connect(m_pathactioneditor
->buttonNewPathAction
, SIGNAL(clicked()),
67 this, SLOT(addPathActionInstance()));
68 connect(m_pathactioneditor
->buttonNewWaypoint
, SIGNAL(clicked()),
69 this, SLOT(addWaypointInstance()));
72 PathActionEditorGadgetWidget::~PathActionEditorGadgetWidget()
77 void PathActionEditorGadgetWidget::pathactionChanged(UAVObject
*)
80 void PathActionEditorGadgetWidget::addPathActionInstance()
82 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
85 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
86 Q_ASSERT(objManager
!= NULL
);
88 qDebug() << "Instances before: " << objManager
->getNumInstances(pathactionObj
->getObjID());
89 PathAction
*obj
= new PathAction();
90 quint32 newInstId
= objManager
->getNumInstances(pathactionObj
->getObjID());
91 obj
->initialize(newInstId
, obj
->getMetaObject());
92 objManager
->registerObject(obj
);
93 qDebug() << "Instances after: " << objManager
->getNumInstances(pathactionObj
->getObjID());
96 void PathActionEditorGadgetWidget::addWaypointInstance()
98 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
100 Q_ASSERT(pm
!= NULL
);
101 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
102 Q_ASSERT(objManager
!= NULL
);
104 qDebug() << "Instances before: " << objManager
->getNumInstances(waypointObj
->getObjID());
105 Waypoint
*obj
= new Waypoint();
106 quint32 newInstId
= objManager
->getNumInstances(waypointObj
->getObjID());
107 obj
->initialize(newInstId
, obj
->getMetaObject());
108 objManager
->registerObject(obj
);
109 qDebug() << "Instances after: " << objManager
->getNumInstances(waypointObj
->getObjID());