1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-1088 Changes to the Vehicle configuration page. Changed combo box for tab bar and made the tab text translate-able.

This commit is contained in:
m_thread 2014-01-28 22:13:41 +01:00
parent 986f2e3e8e
commit 7d44e38daf
4 changed files with 737 additions and 785 deletions

View File

@ -14,87 +14,33 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QGroupBox" name="vehicleTypeGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Vehicle type:</string>
</property>
</widget>
<widget class="QTabBar" name="aircraftType" native="true"/>
</item>
<item>
<widget class="QComboBox" name="aircraftType">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QFrame" name="vehicleTypeFrame">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Select aircraft type here</string>
<property name="styleSheet">
<string notr="true">#vehicleTypeFrame{
color: rgb(180, 180, 180);
margin-top: -1px;
}</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>2</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
@ -212,8 +158,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>840</width>
<height>439</height>
<width>820</width>
<height>478</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -360,8 +306,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>309</height>
<width>271</width>
<height>307</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
@ -792,6 +738,25 @@ p, li { white-space: pre-wrap; }
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>9</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="bottomLayout">
<property name="spacing">
@ -869,6 +834,14 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QTabBar</class>
<extends>QWidget</extends>
<header>qtabbar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../coreplugin/core.qrc"/>
</resources>

View File

@ -250,7 +250,7 @@ void ConfigGadgetWidget::tabAboutToChange(int i, bool *proceed)
}
if (wid->isDirty()) {
int ans = QMessageBox::warning(this, tr("Unsaved changes"), tr("The tab you are leaving has unsaved changes,"
"if you proceed they will be lost."
"if you proceed they will be lost.\n"
"Do you still want to proceed?"), QMessageBox::Yes, QMessageBox::No);
if (ans == QMessageBox::No) {
*proceed = false;

View File

@ -122,18 +122,18 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi
addUAVObject("MixerSettings");
addUAVObject("ActuatorSettings");
ffTuningInProgress = false;
ffTuningPhase = false;
m_ffTuningInProgress = false;
m_ffTuningPhase = false;
QStringList airframeTypes;
airframeTypes << "Fixed Wing" << "Multirotor" << "Helicopter" << "Ground" << "Custom";
m_aircraft->aircraftType->addItems(airframeTypes);
// Set default vehicle to MultiRotor
// m_aircraft->aircraftType->setCurrentIndex(3);
// The order of the tabs is important since they correspond with the AirframCategory enum
m_aircraft->aircraftType->addTab(tr("Multirotor"));
m_aircraft->aircraftType->addTab(tr("Fixed Wing"));
m_aircraft->aircraftType->addTab(tr("Helicopter"));
m_aircraft->aircraftType->addTab(tr("Ground"));
m_aircraft->aircraftType->addTab(tr("Custom"));
// Connect aircraft type selection dropbox to callback function
connect(m_aircraft->aircraftType, SIGNAL(currentIndexChanged(int)), this, SLOT(switchAirframeType(int)));
connect(m_aircraft->aircraftType, SIGNAL(currentChanged(int)), this, SLOT(switchAirframeType(int)));
// Connect the three feed forward test checkboxes
connect(m_aircraft->ffTestBox1, SIGNAL(clicked(bool)), this, SLOT(enableFFTest()));
@ -145,9 +145,6 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi
refreshWidgetsValues();
// register widgets for dirty state management
addWidget(m_aircraft->aircraftType);
// register FF widgets for dirty state management
addWidget(m_aircraft->feedForwardSlider);
addWidget(m_aircraft->accelTime);
@ -171,10 +168,7 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget()
void ConfigVehicleTypeWidget::switchAirframeType(int index)
{
// TODO not safe w/r to translation!!!
QString frameCategory = m_aircraft->aircraftType->currentText();
m_aircraft->airframesWidget->setCurrentWidget(getVehicleConfigWidget(frameCategory));
m_aircraft->airframesWidget->setCurrentWidget(getVehicleConfigWidget(index));
}
/**
@ -202,10 +196,9 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o)
// At this stage, we will need to have some hardcoded settings in this code, this
// is not ideal, but there you go.
QString frameType = field->getValue().toString();
qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - frame type:" << frameType;
QString category = frameCategory(frameType);
setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText(category));
int category = frameCategory(frameType);
m_aircraft->aircraftType->setCurrentIndex(category);
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
if (vehicleConfig) {
@ -215,8 +208,6 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o)
updateFeedForwardUI();
setDirty(dirty);
qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - end";
}
/**
@ -264,63 +255,61 @@ void ConfigVehicleTypeWidget::updateObjectsFromWidgets()
updateFeedForwardUI();
}
QString ConfigVehicleTypeWidget::frameCategory(QString frameType)
int ConfigVehicleTypeWidget::frameCategory(QString frameType)
{
QString category;
if (frameType == "FixedWing" || frameType == "Elevator aileron rudder" || frameType == "FixedWingElevon"
|| frameType == "Elevon" || frameType == "FixedWingVtail" || frameType == "Vtail") {
category = "Fixed Wing";
return ConfigVehicleTypeWidget::FIXED_WING;
} else if (frameType == "Tri" || frameType == "Tricopter Y" || frameType == "QuadX" || frameType == "Quad X"
|| frameType == "QuadP" || frameType == "Quad +" || frameType == "Hexa" || frameType == "Hexacopter"
|| frameType == "HexaX" || frameType == "Hexacopter X" || frameType == "HexaCoax"
|| frameType == "Hexacopter Y6" || frameType == "Octo" || frameType == "Octocopter" || frameType == "OctoV"
|| frameType == "Octocopter V" || frameType == "OctoCoaxP" || frameType == "Octo Coax +"
|| frameType == "OctoCoaxX" || frameType == "Octo Coax X") {
category = "Multirotor";
return ConfigVehicleTypeWidget::MULTIROTOR;
} else if (frameType == "HeliCP") {
category = "Helicopter";
return ConfigVehicleTypeWidget::HELICOPTER;
} else if (frameType == "GroundVehicleCar" || frameType == "Turnable (car)"
|| frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)"
|| frameType == "GroundVehicleMotorcyle" || frameType == "Motorcycle") {
category = "Ground";
return ConfigVehicleTypeWidget::GROUND;
} else {
category = "Custom";
return ConfigVehicleTypeWidget::CUSTOM;
}
return category;
}
VehicleConfig *ConfigVehicleTypeWidget::getVehicleConfigWidget(QString frameCategory)
VehicleConfig *ConfigVehicleTypeWidget::getVehicleConfigWidget(int frameCategory)
{
VehicleConfig *vehiculeConfig;
if (!vehicleIndexMap.contains(frameCategory)) {
if (!m_vehicleIndexMap.contains(frameCategory)) {
// create config widget
vehiculeConfig = createVehicleConfigWidget(frameCategory);
// bind config widget "field" to this ConfigTaskWodget
// this is necessary to get "dirty" state management
vehiculeConfig->registerWidgets(*this);
// add config widget to UI
int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehiculeConfig);
vehicleIndexMap[frameCategory] = index;
m_vehicleIndexMap[frameCategory] = index;
updateEnableControls();
}
int index = vehicleIndexMap.value(frameCategory);
int index = m_vehicleIndexMap.value(frameCategory);
vehiculeConfig = (VehicleConfig *)m_aircraft->airframesWidget->widget(index);
return vehiculeConfig;
}
VehicleConfig *ConfigVehicleTypeWidget::createVehicleConfigWidget(QString frameCategory)
VehicleConfig *ConfigVehicleTypeWidget::createVehicleConfigWidget(int frameCategory)
{
qDebug() << "ConfigVehicleTypeWidget::createVehicleConfigWidget - creating" << frameCategory;
if (frameCategory == "Fixed Wing") {
if (frameCategory == ConfigVehicleTypeWidget::FIXED_WING) {
return new ConfigFixedWingWidget();
} else if (frameCategory == "Multirotor") {
} else if (frameCategory == ConfigVehicleTypeWidget::MULTIROTOR){
return new ConfigMultiRotorWidget();
} else if (frameCategory == "Helicopter") {
} else if (frameCategory == ConfigVehicleTypeWidget::HELICOPTER) {
return new ConfigCcpmWidget();
} else if (frameCategory == "Ground") {
} else if (frameCategory == ConfigVehicleTypeWidget::GROUND) {
return new ConfigGroundVehicleWidget();
} else if (frameCategory == "Custom") {
} else if (frameCategory ==ConfigVehicleTypeWidget::CUSTOM) {
return new ConfigCustomWidget();
}
return NULL;
@ -337,17 +326,17 @@ void ConfigVehicleTypeWidget::enableFFTest()
// - Every other time event: send FF settings to flight FW
if (m_aircraft->ffTestBox1->isChecked() && m_aircraft->ffTestBox2->isChecked()
&& m_aircraft->ffTestBox3->isChecked()) {
if (!ffTuningInProgress) {
if (!m_ffTuningInProgress) {
// Initiate tuning:
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(
QString("ManualControlCommand")));
UAVObject::Metadata mdata = obj->getMetadata();
accInitialData = mdata;
m_accInitialData = mdata;
UAVObject::SetFlightAccess(mdata, UAVObject::ACCESS_READONLY);
obj->setMetadata(mdata);
}
// Depending on phase, either move actuator or send FF settings:
if (ffTuningPhase) {
if (m_ffTuningPhase) {
// Send FF settings to the board
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
@ -369,18 +358,18 @@ void ConfigVehicleTypeWidget::enableFFTest()
obj->getField("Throttle")->setValue(target);
obj->updated();
}
ffTuningPhase = !ffTuningPhase;
ffTuningInProgress = true;
m_ffTuningPhase = !m_ffTuningPhase;
m_ffTuningInProgress = true;
QTimer::singleShot(1000, this, SLOT(enableFFTest()));
} else {
// - If no: disarm timer, restore actuatorcommand metadata
// Disarm!
if (ffTuningInProgress) {
ffTuningInProgress = false;
if (m_ffTuningInProgress) {
m_ffTuningInProgress = false;
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(
QString("ManualControlCommand")));
UAVObject::Metadata mdata = obj->getMetadata();
mdata = accInitialData; // Restore metadata
mdata = m_accInitialData; // Restore metadata
obj->setMetadata(mdata);
}
}
@ -413,15 +402,3 @@ void ConfigVehicleTypeWidget::openHelp()
{
QDesktopServices::openUrl(QUrl("http://wiki.openpilot.org/x/44Cf", QUrl::StrictMode));
}
/**
Helper function:
Sets the current index on supplied combobox to index
if it is within bounds 0 <= index < combobox.count()
*/
void ConfigVehicleTypeWidget::setComboCurrentIndex(QComboBox *box, int index)
{
if (index >= 0 && index < box->count()) {
box->setCurrentIndex(index);
}
}

View File

@ -64,7 +64,6 @@ class ConfigVehicleTypeWidget : public ConfigTaskWidget {
public:
static QStringList getChannelDescriptions();
static void setComboCurrentIndex(QComboBox *box, int index);
ConfigVehicleTypeWidget(QWidget *parent = 0);
~ConfigVehicleTypeWidget();
@ -76,20 +75,23 @@ protected slots:
private:
Ui_AircraftWidget *m_aircraft;
static enum { MULTIROTOR = 0, FIXED_WING, HELICOPTER, GROUND, CUSTOM } AirframeCategory;
// Maps a frame category to its index in the m_aircraft->airframesWidget QStackedWidget
QMap<QString, int> vehicleIndexMap;
QMap<int, int> m_vehicleIndexMap;
QString frameCategory(QString frameType);
VehicleConfig *getVehicleConfigWidget(QString frameCategory);
VehicleConfig *createVehicleConfigWidget(QString frameCategory);
int frameCategory(QString frameType);
VehicleConfig *getVehicleConfigWidget(int frameCategory);
VehicleConfig *createVehicleConfigWidget(int frameCategory);
// Feed Forward
void updateFeedForwardUI();
bool ffTuningInProgress;
bool ffTuningPhase;
UAVObject::Metadata accInitialData;
bool m_ffTuningInProgress;
bool m_ffTuningPhase;
UAVObject::Metadata m_accInitialData;
private slots:
void switchAirframeType(int index);