mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-31 16:52:10 +01:00
LP-16 Added code to delete 'local' vehicle templates.
This commit is contained in:
parent
da6b0715f7
commit
72938ec954
@ -19,17 +19,11 @@
|
|||||||
<height>700</height>
|
<height>700</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>610</width>
|
|
||||||
<height>700</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Vehicle Templates</string>
|
<string>Vehicle Templates</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeGripEnabled">
|
<property name="sizeGripEnabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="modal">
|
<property name="modal">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMessageBox>
|
||||||
#include "vehicletemplateexportdialog.h"
|
#include "vehicletemplateexportdialog.h"
|
||||||
#include "utils/pathutils.h"
|
#include "utils/pathutils.h"
|
||||||
|
|
||||||
@ -41,12 +42,13 @@ VehicleTemplateSelectorWidget::VehicleTemplateSelectorWidget(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->templateImage->setScene(new QGraphicsScene());
|
ui->templateImage->setScene(new QGraphicsScene());
|
||||||
connect(ui->templateList, SIGNAL(itemSelectionChanged()), this, SLOT(templateSelectionChanged()));
|
connect(ui->templateList, SIGNAL(itemSelectionChanged()), this, SLOT(templateSelectionChanged()));
|
||||||
|
connect(ui->deleteTemplateButton, SIGNAL(clicked()), this, SLOT(deleteSelectedTemplate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
VehicleTemplateSelectorWidget::~VehicleTemplateSelectorWidget()
|
VehicleTemplateSelectorWidget::~VehicleTemplateSelectorWidget()
|
||||||
{
|
{
|
||||||
ui->templateList->clear();
|
ui->templateList->clear();
|
||||||
foreach(QJsonObject * templ, m_templates.values()) {
|
foreach(VehicleTemplate * templ, m_templates.values()) {
|
||||||
delete templ;
|
delete templ;
|
||||||
}
|
}
|
||||||
m_templates.clear();
|
m_templates.clear();
|
||||||
@ -69,12 +71,47 @@ QJsonObject *VehicleTemplateSelectorWidget::selectedTemplate() const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VehicleTemplateSelectorWidget::selectedTemplateEditable() const
|
||||||
|
{
|
||||||
|
if (ui->templateList->currentRow() >= 0) {
|
||||||
|
return ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 2).value<bool>();
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString VehicleTemplateSelectorWidget::selectedTemplatePath() const
|
||||||
|
{
|
||||||
|
if (ui->templateList->currentRow() >= 0) {
|
||||||
|
return ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 3).value<QString>();
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void VehicleTemplateSelectorWidget::updateTemplates()
|
void VehicleTemplateSelectorWidget::updateTemplates()
|
||||||
{
|
{
|
||||||
loadValidFiles();
|
loadValidFiles();
|
||||||
setupTemplateList();
|
setupTemplateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VehicleTemplateSelectorWidget::deleteSelectedTemplate()
|
||||||
|
{
|
||||||
|
if (selectedTemplateEditable()) {
|
||||||
|
if (QMessageBox::question(this, tr("Delete Vehicle Template"),
|
||||||
|
"Are you sure you want to delete the selected template?",
|
||||||
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||||
|
QFile fileToDelete(selectedTemplatePath());
|
||||||
|
if (fileToDelete.remove()) {
|
||||||
|
QJsonObject* templObj = selectedTemplate();
|
||||||
|
if (templObj) {
|
||||||
|
VehicleTemplate *templ = m_templates[templObj->value("uuid").toString()];
|
||||||
|
m_templates.remove(templObj->value("uuid").toString());
|
||||||
|
delete templ;
|
||||||
|
}
|
||||||
|
delete ui->templateList->item(ui->templateList->currentRow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void VehicleTemplateSelectorWidget::updatePhoto(QJsonObject *templ)
|
void VehicleTemplateSelectorWidget::updatePhoto(QJsonObject *templ)
|
||||||
{
|
{
|
||||||
QPixmap photo;
|
QPixmap photo;
|
||||||
@ -129,6 +166,7 @@ void VehicleTemplateSelectorWidget::templateSelectionChanged()
|
|||||||
QJsonObject *templ = selectedTemplate();
|
QJsonObject *templ = selectedTemplate();
|
||||||
updatePhoto(templ);
|
updatePhoto(templ);
|
||||||
updateDescription(templ);
|
updateDescription(templ);
|
||||||
|
ui->deleteTemplateButton->setEnabled(selectedTemplateEditable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +211,8 @@ void VehicleTemplateSelectorWidget::loadFilesInDir(QString templateBasePath, boo
|
|||||||
templateDir.setSorting(QDir::Name);
|
templateDir.setSorting(QDir::Name);
|
||||||
QStringList files = templateDir.entryList();
|
QStringList files = templateDir.entryList();
|
||||||
foreach(QString fileName, files) {
|
foreach(QString fileName, files) {
|
||||||
QFile file(QString("%1/%2").arg(templateDir.absolutePath()).arg(fileName));
|
QString fullPathName = QString("%1/%2").arg(templateDir.absolutePath()).arg(fileName);
|
||||||
|
QFile file(fullPathName);
|
||||||
|
|
||||||
if (file.open(QFile::ReadOnly)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
QByteArray jsonData = file.readAll();
|
QByteArray jsonData = file.readAll();
|
||||||
@ -184,7 +223,7 @@ void VehicleTemplateSelectorWidget::loadFilesInDir(QString templateBasePath, boo
|
|||||||
if (airframeIsCompatible(json["type"].toInt(), json["subtype"].toInt())) {
|
if (airframeIsCompatible(json["type"].toInt(), json["subtype"].toInt())) {
|
||||||
QString uuid = json["uuid"].toString();
|
QString uuid = json["uuid"].toString();
|
||||||
if (!m_templates.contains(uuid)) {
|
if (!m_templates.contains(uuid)) {
|
||||||
m_templates[json["uuid"].toString()] = new QJsonObject(json);
|
m_templates[json["uuid"].toString()] = new VehicleTemplate(new QJsonObject(json), local, fullPathName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -199,7 +238,7 @@ void VehicleTemplateSelectorWidget::loadFilesInDir(QString templateBasePath, boo
|
|||||||
void VehicleTemplateSelectorWidget::loadValidFiles()
|
void VehicleTemplateSelectorWidget::loadValidFiles()
|
||||||
{
|
{
|
||||||
ui->templateList->clear();
|
ui->templateList->clear();
|
||||||
foreach(QJsonObject * templ, m_templates.values()) {
|
foreach(VehicleTemplate * templ, m_templates.values()) {
|
||||||
delete templ;
|
delete templ;
|
||||||
}
|
}
|
||||||
m_templates.clear();
|
m_templates.clear();
|
||||||
@ -213,10 +252,15 @@ void VehicleTemplateSelectorWidget::setupTemplateList()
|
|||||||
QListWidgetItem *item;
|
QListWidgetItem *item;
|
||||||
|
|
||||||
foreach(QString templ, m_templates.keys()) {
|
foreach(QString templ, m_templates.keys()) {
|
||||||
QJsonObject *json = m_templates[templ];
|
VehicleTemplate *vtemplate = m_templates[templ];
|
||||||
|
|
||||||
item = new QListWidgetItem(json->value("name").toString(), ui->templateList);
|
item = new QListWidgetItem(vtemplate->templateObject()->value("name").toString(), ui->templateList);
|
||||||
item->setData(Qt::UserRole + 1, QVariant::fromValue(json));
|
item->setData(Qt::UserRole + 1, QVariant::fromValue(vtemplate->templateObject()));
|
||||||
|
item->setData(Qt::UserRole + 2, QVariant::fromValue(vtemplate->editable()));
|
||||||
|
if (vtemplate->editable()) {
|
||||||
|
item->setData(Qt::ForegroundRole, QVariant::fromValue(QColor(Qt::darkGreen)));
|
||||||
|
}
|
||||||
|
item->setData(Qt::UserRole + 3, QVariant::fromValue(vtemplate->templatePath()));
|
||||||
}
|
}
|
||||||
ui->templateList->sortItems(Qt::AscendingOrder);
|
ui->templateList->sortItems(Qt::AscendingOrder);
|
||||||
|
|
||||||
|
@ -36,6 +36,36 @@ namespace Ui {
|
|||||||
class VehicleTemplateSelectorWidget;
|
class VehicleTemplateSelectorWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VehicleTemplate {
|
||||||
|
public:
|
||||||
|
VehicleTemplate(QJsonObject *templateObject, bool editable, QString templatePath) :
|
||||||
|
m_templateObject(templateObject), m_editable(editable), m_templatePath(templatePath) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~VehicleTemplate() {
|
||||||
|
if (m_templateObject) {
|
||||||
|
delete m_templateObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject *templateObject() {
|
||||||
|
return m_templateObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool editable() {
|
||||||
|
return m_editable;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString templatePath() {
|
||||||
|
return m_templatePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QJsonObject *m_templateObject;
|
||||||
|
bool m_editable;
|
||||||
|
QString m_templatePath;
|
||||||
|
};
|
||||||
|
|
||||||
class VehicleTemplateSelectorWidget : public QWidget {
|
class VehicleTemplateSelectorWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -44,7 +74,6 @@ public:
|
|||||||
~VehicleTemplateSelectorWidget();
|
~VehicleTemplateSelectorWidget();
|
||||||
void setTemplateInfo(int vehicleType, int vehicleSubType);
|
void setTemplateInfo(int vehicleType, int vehicleSubType);
|
||||||
QJsonObject *selectedTemplate() const;
|
QJsonObject *selectedTemplate() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void templateSelectionChanged();
|
void templateSelectionChanged();
|
||||||
|
|
||||||
@ -57,7 +86,7 @@ private:
|
|||||||
int m_vehicleType;
|
int m_vehicleType;
|
||||||
int m_vehicleSubType;
|
int m_vehicleSubType;
|
||||||
|
|
||||||
QMap<QString, QJsonObject *> m_templates;
|
QMap<QString, VehicleTemplate *> m_templates;
|
||||||
QGraphicsPixmapItem *m_photoItem;
|
QGraphicsPixmapItem *m_photoItem;
|
||||||
|
|
||||||
void loadValidFiles();
|
void loadValidFiles();
|
||||||
@ -68,9 +97,12 @@ private:
|
|||||||
void updateDescription(QJsonObject *templ);
|
void updateDescription(QJsonObject *templ);
|
||||||
bool airframeIsCompatible(int vehicleType, int vehicleSubType);
|
bool airframeIsCompatible(int vehicleType, int vehicleSubType);
|
||||||
QString getTemplatePath();
|
QString getTemplatePath();
|
||||||
|
bool selectedTemplateEditable() const;
|
||||||
|
QString selectedTemplatePath() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateTemplates();
|
void updateTemplates();
|
||||||
|
void deleteSelectedTemplate();
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QJsonObject *)
|
Q_DECLARE_METATYPE(QJsonObject *)
|
||||||
|
@ -13,71 +13,160 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="QSplitter" name="splitter">
|
||||||
<item>
|
<property name="orientation">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="2,0">
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,4">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="templateList">
|
<widget class="QListWidget" name="templateList">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>300</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="verticalScrollBarPolicy">
|
<property name="verticalScrollBarPolicy">
|
||||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGraphicsView" name="templateImage">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="minimumSize">
|
<item>
|
||||||
<size>
|
<widget class="QFrame" name="buttonFrame">
|
||||||
<width>250</width>
|
<property name="frameShape">
|
||||||
<height>250</height>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</size>
|
</property>
|
||||||
</property>
|
<property name="frameShadow">
|
||||||
<property name="styleSheet">
|
<enum>QFrame::Raised</enum>
|
||||||
<string notr="true">background-color: rgba(254, 254, 254, 0);</string>
|
</property>
|
||||||
</property>
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<property name="interactive">
|
<property name="leftMargin">
|
||||||
<bool>false</bool>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="renderHints">
|
<property name="topMargin">
|
||||||
<set>QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing</set>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="addTemplateButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="deleteTemplateButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextEdit" name="templateDescription">
|
<widget class="QGraphicsView" name="templateImage">
|
||||||
<property name="sizePolicy">
|
<property name="minimumSize">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<size>
|
||||||
<horstretch>0</horstretch>
|
<width>200</width>
|
||||||
<verstretch>0</verstretch>
|
<height>200</height>
|
||||||
</sizepolicy>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="styleSheet">
|
||||||
<font>
|
<string notr="true">background-color: rgba(254, 254, 254, 0);</string>
|
||||||
<pointsize>10</pointsize>
|
|
||||||
</font>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="undoRedoEnabled">
|
<property name="interactive">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="readOnly">
|
<property name="renderHints">
|
||||||
<bool>true</bool>
|
<set>QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="placeholderText">
|
<property name="resizeAnchor">
|
||||||
<string>Information about the Vehicle in short.</string>
|
<enum>QGraphicsView::AnchorViewCenter</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</widget>
|
||||||
</layout>
|
<widget class="QTextEdit" name="templateDescription">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="undoRedoEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Information about the Vehicle in short.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user