1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

OP-1222 Re-factored and renamed selection page.

This commit is contained in:
m_thread 2014-09-02 00:10:31 +02:00
parent 5586b5b85c
commit c56980e54e
5 changed files with 194 additions and 231 deletions

View File

@ -0,0 +1,119 @@
/**
******************************************************************************
*
* @file multipage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup
* @{
* @addtogroup MultiPage
* @{
* @brief
*****************************************************************************/
/*
* 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 "selectionpage.h"
#include "ui_selectionpage.h"
#include "setupwizard.h"
SelectionPage::SelectionPage(SetupWizard *wizard, QString shapeFile, QWidget *parent) :
AbstractWizardPage(wizard, parent),
ui(new Ui::SelectionPage)
{
ui->setupUi(this);
QSvgRenderer *renderer = new QSvgRenderer();
renderer->load(shapeFile);
m_shape = new QGraphicsSvgItem();
m_shape->setSharedRenderer(renderer);
QGraphicsScene *scene = new QGraphicsScene(this);
scene->addItem(m_shape);
ui->typeGraphicsView->setScene(scene);
connect(ui->typeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionChanged(int)));
}
SelectionPage::~SelectionPage()
{
while (!m_selectionItems.empty()) {
delete m_selectionItems.takeFirst();
}
delete ui;
}
void SelectionPage::initializePage()
{
//lazy init
if (m_selectionItems.isEmpty()) {
setupSelection(this);
foreach (SelectionItem * item, m_selectionItems) {
ui->typeCombo->addItem(item->name());
}
// Default to first item if any
if (ui->typeCombo->count() > 0) {
ui->typeCombo->setCurrentIndex(1);
}
}
}
bool SelectionPage::validatePage()
{
return validatePage(m_selectionItems.at(ui->typeCombo->currentIndex()));
}
void SelectionPage::fitImage()
{
if (m_shape) {
ui->typeGraphicsView->setSceneRect(m_shape->boundingRect());
ui->typeGraphicsView->fitInView(m_shape, Qt::KeepAspectRatio);
}
}
void SelectionPage::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitImage();
}
void SelectionPage::showEvent(QShowEvent *event)
{
Q_UNUSED(event);
fitImage();
}
void SelectionPage::selectionChanged(int index)
{
SelectionItem *item = m_selectionItems.at(index);
m_shape->setElementId(item->shapeId());
ui->typeDescription->setText(item->description());
fitImage();
}
void SelectionPage::addItem(QString name, QString description, QString shapeId, int id)
{
m_selectionItems << new SelectionItem(name, description, shapeId, id);
}
void SelectionPage::setTitleLabel(QString text)
{
ui->label->setText(text);
}
SelectionItem::SelectionItem(QString name, QString description, QString shapeId, int id) :
m_name(name), m_description(description), m_shapeId(shapeId), m_id(id)
{
}

View File

@ -35,32 +35,62 @@
#include "abstractwizardpage.h"
namespace Ui {
class SubVehiclePage;
class SelectionPage;
}
class SubVehiclePage : public AbstractWizardPage {
class SelectionItem : public QObject {
Q_OBJECT
public:
SelectionItem(QString name, QString description, QString shapeId, int id);
~SelectionItem();
QString name() { return m_name; }
QString description() { return m_description; }
QString shapeId() { return m_shapeId; }
int id() { return m_id; }
private:
QString m_name;
QString m_description;
QString m_shapeId;
int m_id;
};
class Selection {
public:
virtual void addItem(QString name, QString description, QString shapeId, int id) = 0;
virtual void setTitleLabel(QString text) = 0;
};
class SelectionPage : public AbstractWizardPage, Selection {
Q_OBJECT
public:
explicit SubVehiclePage(SetupWizard *wizard, QWidget *parent = 0);
~SubVehiclePage();
explicit SelectionPage(SetupWizard *wizard, QString shapeFile, QWidget *parent = 0);
~SelectionPage();
void initializePage();
bool validatePage();
void addItem(QString name, QString description, QString shapeId, int id);
void setTitleLabel(QString text);
virtual void setupSelection(Selection *selection) = 0;
virtual bool validatePage(SelectionItem *selectedItem) = 0;
protected:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent * event);
private:
Ui::SubVehiclePage *ui;
void setupMultiTypesCombo();
QSvgRenderer* m_renderer;
QGraphicsSvgItem *m_multiPic;
void updateAvailableTypes();
QList<QString> m_descriptions;
Ui::SelectionPage *ui;
QGraphicsSvgItem *m_shape;
QList<SelectionItem*> m_selectionItems;
private slots:
void updateImageAndDescription();
void selectionChanged(int index);
void fitImage();
};
#endif // SUBVEHICLEPAGEPAGE_H

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SubVehiclePage</class>
<widget class="QWizardPage" name="SubVehiclePage">
<class>SelectionPage</class>
<widget class="QWizardPage" name="SelectionPage">
<property name="geometry">
<rect>
<x>0</x>
@ -17,15 +17,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;OpenPilot Multirotor Configuration&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;This part of the wizard will set up the OpenPilot controller for use with a flying platform utilizing multiple rotors. The wizard supports the most common types of multirotors. Other variants of multirotors can be configured by using custom configuration options in the Configuration plugin in the GCS.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Please select the type of multirotor you want to create a configuration for below:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>placeholder_text</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@ -37,23 +29,32 @@ p, li { white-space: pre-wrap; }
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>9</number>
</property>
<property name="topMargin">
<number>4</number>
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>9</number>
</property>
<property name="rightMargin">
<number>4</number>
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>125</width>
<height>36</height>
</size>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
@ -63,17 +64,17 @@ p, li { white-space: pre-wrap; }
</font>
</property>
<property name="text">
<string>Multirotor type:</string>
<string>Select:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="typeCombo">
<property name="minimumSize">
<size>
<width>125</width>
<height>20</height>
</size>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
@ -82,13 +83,13 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QTextEdit" name="typeDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
@ -118,7 +119,10 @@ p, li { white-space: pre-wrap; }
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>

View File

@ -1,190 +0,0 @@
/**
******************************************************************************
*
* @file multipage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup
* @{
* @addtogroup MultiPage
* @{
* @brief
*****************************************************************************/
/*
* 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 "subvehiclepage.h"
#include "ui_subvehiclepage.h"
#include "setupwizard.h"
SubVehiclePage::SubVehiclePage(SetupWizard *wizard, QWidget *parent) :
AbstractWizardPage(wizard, parent),
ui(new Ui::SubVehiclePage)
{
ui->setupUi(this);
m_renderer = new QSvgRenderer();
m_renderer->load(QString(":/configgadget/images/multirotor-shapes.svg"));
m_multiPic = new QGraphicsSvgItem();
m_multiPic->setSharedRenderer(m_renderer);
QGraphicsScene *scene = new QGraphicsScene(this);
scene->addItem(m_multiPic);
ui->typeGraphicsView->setScene(scene);
setupMultiTypesCombo();
// Default to Quad X since it is the most common setup
ui->typeCombo->setCurrentIndex(1);
connect(ui->typeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateImageAndDescription()));
ui->typeGraphicsView->setSceneRect(m_multiPic->boundingRect());
ui->typeGraphicsView->fitInView(m_multiPic, Qt::KeepAspectRatio);
}
SubVehiclePage::~SubVehiclePage()
{
delete ui;
}
void SubVehiclePage::initializePage()
{
updateAvailableTypes();
updateImageAndDescription();
}
bool SubVehiclePage::validatePage()
{
SetupWizard::VEHICLE_SUB_TYPE type = (SetupWizard::VEHICLE_SUB_TYPE)ui->typeCombo->itemData(ui->typeCombo->currentIndex()).toInt();
getWizard()->setVehicleSubType(type);
return true;
}
void SubVehiclePage::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
if (m_multiPic) {
ui->typeGraphicsView->setSceneRect(m_multiPic->boundingRect());
ui->typeGraphicsView->fitInView(m_multiPic, Qt::KeepAspectRatio);
}
}
void SubVehiclePage::setupMultiTypesCombo()
{
ui->typeCombo->addItem(tr("Tricopter"), SetupWizard::MULTI_ROTOR_TRI_Y);
m_descriptions << tr("The Tricopter uses three motors and one servo. The servo is used to give yaw authority to the rear motor. "
"The front motors are rotating in opposite directions. The Tricopter is known for its sweeping yaw movement and "
"it is very well suited for FPV since the front rotors are spread wide apart.");
ui->typeCombo->addItem(tr("Quadcopter X"), SetupWizard::MULTI_ROTOR_QUAD_X);
m_descriptions << tr("The X Quadcopter uses four motors and is the most common multi rotor configuration. Two of the motors rotate clockwise "
"and two counter clockwise. The motors positioned diagonal to each other rotate in the same direction. "
"This setup is perfect for sport flying and is also commonly used for FPV platforms.");
ui->typeCombo->addItem(tr("Quadcopter +"), SetupWizard::MULTI_ROTOR_QUAD_PLUS);
m_descriptions << tr("The Plus(+) Quadcopter uses four motors and is similar to the X Quadcopter but the forward direction is offset by 45 degrees. "
"The motors front and rear rotate in clockwise and the motors right and left rotate counter-clockwise. "
"This setup was one of the first to be used and is still used for sport flying. This configuration is not that well suited "
"for FPV since the fore rotor tend to be in the way of the camera.");
ui->typeCombo->addItem(tr("Hexacopter"), SetupWizard::MULTI_ROTOR_HEXA);
m_descriptions << tr("Hexacopter");
ui->typeCombo->addItem(tr("Hexacopter X"), SetupWizard::MULTI_ROTOR_HEXA_X);
m_descriptions << tr("Hexacopter X");
ui->typeCombo->addItem(tr("Hexacopter H"), SetupWizard::MULTI_ROTOR_HEXA_H);
m_descriptions << tr("Hexacopter H");
ui->typeCombo->addItem(tr("Hexacopter Coax (Y6)"), SetupWizard::MULTI_ROTOR_HEXA_COAX_Y);
m_descriptions << tr("Hexacopter Coax (Y6)");
// Fredrik Arvidsson(m_thread) 2012-08-26 Disable Octos until further notice
/*
ui->typeCombo->addItem(tr("Octocopter"), SetupWizard::MULTI_ROTOR_OCTO);
m_descriptions << tr("Octocopter");
ui->typeCombo->addItem(tr("Octocopter Coax X"), SetupWizard::MULTI_ROTOR_OCTO_COAX_X);
m_descriptions << tr("Octocopter Coax X");
ui->typeCombo->addItem(tr("Octocopter Coax +"), SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS);
m_descriptions << tr("Octocopter Coax +");
ui->typeCombo->addItem(tr("Octocopter V"), SetupWizard::MULTI_ROTOR_OCTO_V);
m_descriptions << tr("Octocopter V");
*/
}
void SubVehiclePage::updateAvailableTypes()
{
/*
QVariant enable = (getWizard()->getInputType() == SetupWizard::INPUT_PWM) ? QVariant(0) : QVariant(1 | 32);
ui->typeCombo->model()->setData(ui->typeCombo->model()->index(6, 0), enable, Qt::UserRole - 1);
ui->typeCombo->model()->setData(ui->typeCombo->model()->index(7, 0), enable, Qt::UserRole - 1);
ui->typeCombo->model()->setData(ui->typeCombo->model()->index(8, 0), enable, Qt::UserRole - 1);
ui->typeCombo->model()->setData(ui->typeCombo->model()->index(9, 0), enable, Qt::UserRole - 1);
*/
}
void SubVehiclePage::updateImageAndDescription()
{
SetupWizard::VEHICLE_SUB_TYPE type = (SetupWizard::VEHICLE_SUB_TYPE)ui->typeCombo->itemData(ui->typeCombo->currentIndex()).toInt();
QString elementId = "";
QString description = m_descriptions.at(ui->typeCombo->currentIndex());
switch (type) {
case SetupWizard::MULTI_ROTOR_TRI_Y:
elementId = "tri";
break;
case SetupWizard::MULTI_ROTOR_QUAD_X:
elementId = "quad-x";
break;
case SetupWizard::MULTI_ROTOR_QUAD_PLUS:
elementId = "quad-plus";
break;
case SetupWizard::MULTI_ROTOR_HEXA:
elementId = "quad-hexa";
break;
case SetupWizard::MULTI_ROTOR_HEXA_COAX_Y:
elementId = "hexa-coax";
break;
case SetupWizard::MULTI_ROTOR_HEXA_H:
elementId = "quad-hexa-H";
break;
case SetupWizard::MULTI_ROTOR_HEXA_X:
elementId = "quad-hexa-X";
break;
case SetupWizard::MULTI_ROTOR_OCTO:
elementId = "quad-octo";
break;
case SetupWizard::MULTI_ROTOR_OCTO_COAX_X:
elementId = "octo-coax-X";
break;
case SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS:
elementId = "octo-coax-P";
break;
case SetupWizard::MULTI_ROTOR_OCTO_V:
elementId = "quad-octo-v";
break;
default:
elementId = "";
break;
}
m_multiPic->setElementId(elementId);
ui->typeGraphicsView->setSceneRect(m_multiPic->boundingRect());
ui->typeGraphicsView->fitInView(m_multiPic, Qt::KeepAspectRatio);
ui->typeDescription->setText(description);
}

View File

@ -38,7 +38,7 @@ HEADERS += setupwizardplugin.h \
pages/airframestabfixedwingpage.h \
pages/escpage.h \
pages/servopage.h \
pages/subvehiclepage.h
pages/selectionpage.h
SOURCES += setupwizardplugin.cpp \
setupwizard.cpp \
@ -68,7 +68,7 @@ SOURCES += setupwizardplugin.cpp \
pages/airframestabfixedwingpage.cpp \
pages/escpage.cpp \
pages/servopage.cpp \
pages/subvehiclepage.cpp
pages/selectionpage.cpp
OTHER_FILES += SetupWizard.pluginspec
@ -94,7 +94,7 @@ FORMS += \
pages/airframestabfixedwingpage.ui \
pages/escpage.ui \
pages/servopage.ui \
pages/subvehiclepage.ui
pages/selectionpage.ui
RESOURCES += \
wizardResources.qrc