LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / opmap / pathplanner.cpp
blobdd02a62587e89c426296084f886a9517182901b7
1 /**
2 ******************************************************************************
4 * @file pathplanner.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
9 * @{
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "pathplanner.h"
29 #include "ui_pathplanner.h"
30 #include "widgetdelegates.h"
31 #include <QAbstractItemModel>
32 #include <QFileDialog>
34 pathPlanner::pathPlanner(QWidget *parent) :
35 QWidget(parent),
36 ui(new Ui::pathPlannerUI), wid(NULL), myModel(NULL)
38 ui->setupUi(this);
41 pathPlanner::~pathPlanner()
43 delete ui;
44 if (wid) {
45 delete wid;
48 void pathPlanner::setModel(flightDataModel *model, QItemSelectionModel *selection)
50 myModel = model;
51 ui->tableView->setModel(model);
52 ui->tableView->setSelectionModel(selection);
53 ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
54 ui->tableView->setItemDelegate(new MapDataDelegate(this));
55 connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
56 wid = new opmap_edit_waypoint_dialog(NULL, model, selection);
57 ui->tableView->resizeColumnsToContents();
60 void pathPlanner::rowsInserted(const QModelIndex & parent, int start, int end)
62 Q_UNUSED(parent);
63 for (int x = start; x < end + 1; x++) {
64 QModelIndex index = ui->tableView->model()->index(x, flightDataModel::MODE);
65 ui->tableView->openPersistentEditor(index);
66 index = ui->tableView->model()->index(x, flightDataModel::CONDITION);
67 ui->tableView->openPersistentEditor(index);
68 index = ui->tableView->model()->index(x, flightDataModel::COMMAND);
69 ui->tableView->openPersistentEditor(index);
70 ui->tableView->size().setHeight(10);
74 void pathPlanner::on_tbAdd_clicked()
76 ui->tableView->model()->insertRow(ui->tableView->model()->rowCount());
79 void pathPlanner::on_tbDelete_clicked()
81 ui->tableView->model()->removeRow(ui->tableView->selectionModel()->currentIndex().row());
84 void pathPlanner::on_tbInsert_clicked()
86 ui->tableView->model()->insertRow(ui->tableView->selectionModel()->currentIndex().row());
89 void pathPlanner::on_tbReadFromFile_clicked()
91 if (!myModel) {
92 return;
94 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"));
95 myModel->readFromFile(fileName);
98 void pathPlanner::on_tbSaveToFile_clicked()
100 if (!myModel) {
101 return;
103 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"));
104 myModel->writeToFile(fileName);
107 void pathPlanner::on_tbDetails_clicked()
109 if (wid) {
110 wid->show();
114 void pathPlanner::on_tbSendToUAV_clicked()
116 emit sendPathPlanToUAV();
119 void pathPlanner::on_tbFetchFromUAV_clicked()
121 emit receivePathPlanFromUAV();