mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-151 Use PathChooser in all plugins, and update pathutils to behave consistently across platforms by always using "/" as its internal format. Should solve the issues we have been having with windows paths not being removed properly.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1618 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
6cc702b394
commit
1cbd44f564
@ -38,36 +38,46 @@ namespace Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the base path of the share directory
|
||||
Returns the base path of the share directory.
|
||||
|
||||
Path is in Qt/Unix conventions, separated by "/".
|
||||
*/
|
||||
QString PathUtils::GetDataPath()
|
||||
{
|
||||
// Figure out root: Up one from 'bin'
|
||||
QDir rootDir = QApplication::applicationDirPath();
|
||||
rootDir.cdUp();
|
||||
const QString rootDirPath = rootDir.canonicalPath();
|
||||
QString pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String(GCS_DATA_BASENAME);
|
||||
pluginPath += QLatin1Char('/');
|
||||
return pluginPath;
|
||||
// This routine works with "/" as the standard:
|
||||
// Figure out root: Up one from 'bin'
|
||||
QDir rootDir = QApplication::applicationDirPath();
|
||||
rootDir.cdUp();
|
||||
const QString rootDirPath = rootDir.canonicalPath();
|
||||
QString dataPath = rootDirPath;
|
||||
dataPath += QLatin1Char('/');
|
||||
dataPath += QLatin1String(GCS_DATA_BASENAME);
|
||||
dataPath += QLatin1Char('/');
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
/**
|
||||
Cuts the standard data path from the 'path' argument. If path does not start
|
||||
with the standard data path, then do nothing.
|
||||
|
||||
Always returns a path converted to "/".
|
||||
*/
|
||||
QString PathUtils::RemoveDataPath(QString path)
|
||||
{
|
||||
if (path.startsWith(GetDataPath())) {
|
||||
int i = path.length()- GetDataPath().length();
|
||||
return QString("%%DATAPATH%%") + path.right(i);
|
||||
// Depending on the platform, we might get either "/" or "\"
|
||||
// so we need to go to the standard ("/")
|
||||
QString goodPath = QDir::fromNativeSeparators(path);
|
||||
if (goodPath.startsWith(GetDataPath())) {
|
||||
int i = goodPath.length()- GetDataPath().length();
|
||||
return QString("%%DATAPATH%%") + goodPath.right(i);
|
||||
} else
|
||||
return path;
|
||||
return goodPath;
|
||||
}
|
||||
|
||||
/**
|
||||
Inserts the data path (only if the path starts with %%DATAPATH%%)
|
||||
|
||||
Returns a "/" or "\" separated path depending on platform conventions.
|
||||
*/
|
||||
QString PathUtils::InsertDataPath(QString path)
|
||||
{
|
||||
@ -75,9 +85,9 @@ QString PathUtils::InsertDataPath(QString path)
|
||||
{
|
||||
QString newPath = GetDataPath();
|
||||
newPath += path.right(path.length()-12);
|
||||
return newPath;
|
||||
return QDir::toNativeSeparators(newPath);
|
||||
}
|
||||
return path;
|
||||
return QDir::toNativeSeparators(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -80,7 +80,11 @@ QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
options_page->moveNeedle3->addItem("Vertical");
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->svgSourceFile->setText(m_config->dialFile());
|
||||
|
||||
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
|
||||
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
|
||||
options_page->svgSourceFile->setPath(m_config->dialFile());
|
||||
options_page->backgroundID->setText(m_config->dialBackground());
|
||||
options_page->foregroundID->setText(m_config->dialForeground());
|
||||
options_page->needle1ID->setText(m_config->dialNeedle1());
|
||||
@ -143,7 +147,6 @@ QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
}
|
||||
connect(options_page->uavObject3, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject3_currentIndexChanged(QString)));
|
||||
|
||||
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
|
||||
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
|
||||
|
||||
return optionsPageWidget;
|
||||
@ -157,7 +160,7 @@ QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
*/
|
||||
void DialGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
m_config->setDialFile(options_page->svgSourceFile->path());
|
||||
m_config->setDialBackgroundID(options_page->backgroundID->text());
|
||||
m_config->setDialForegroundID(options_page->foregroundID->text());
|
||||
m_config->setDialNeedleID1(options_page->needle1ID->text());
|
||||
@ -242,25 +245,6 @@ void DialGadgetOptionsPage::on_uavObject3_currentIndexChanged(QString val) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Opens an open file dialog.
|
||||
|
||||
*/
|
||||
void DialGadgetOptionsPage::on_loadFile_clicked()
|
||||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||
tr("QFileDialog::getOpenFileName()"),
|
||||
options_page->svgSourceFile->text(),
|
||||
tr("All Files (*);;SVG Files (*.svg)"),
|
||||
&selectedFilter,
|
||||
options);
|
||||
if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DialGadgetOptionsPage::finish()
|
||||
{
|
||||
|
||||
|
@ -64,7 +64,6 @@ private:
|
||||
QFont font;
|
||||
|
||||
private slots:
|
||||
void on_loadFile_clicked();
|
||||
void on_fontPicker_clicked();
|
||||
void on_uavObject1_currentIndexChanged(QString val);
|
||||
void on_uavObject2_currentIndexChanged(QString val);
|
||||
|
@ -45,7 +45,7 @@
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
@ -57,23 +57,35 @@
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dial SVG: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="svgSourceFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadFile">
|
||||
<property name="text">
|
||||
<string>Load file...</string>
|
||||
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_28">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dial font:</string>
|
||||
</property>
|
||||
@ -762,6 +774,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -51,7 +51,10 @@ QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->svgSourceFile->setText(m_config->getDialFile());
|
||||
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->svgSourceFile->setPromptDialogFilter(tr("INI file (*.ini)"));
|
||||
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose configuration file"));
|
||||
options_page->svgSourceFile->setPath(m_config->getDialFile());
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
@ -64,7 +67,7 @@ QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
|
||||
*/
|
||||
void ImportExportGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
m_config->setDialFile(options_page->svgSourceFile->path());
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
@ -63,12 +63,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="svgSourceFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadFile">
|
||||
<property name="text">
|
||||
<string>Load file...</string>
|
||||
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -90,6 +90,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -55,7 +55,10 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->svgSourceFile->setText(m_config->getDialFile());
|
||||
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
|
||||
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
|
||||
options_page->svgSourceFile->setPath(m_config->getDialFile());
|
||||
options_page->minValue->setValue(m_config->getMin());
|
||||
options_page->maxValue->setValue(m_config->getMax());
|
||||
options_page->greenMin->setValue(m_config->getGreenMin());
|
||||
@ -93,7 +96,6 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
}
|
||||
|
||||
connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_objectName_currentIndexChanged(QString)));
|
||||
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
|
||||
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
|
||||
|
||||
return optionsPageWidget;
|
||||
@ -107,7 +109,7 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
|
||||
*/
|
||||
void LineardialGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
m_config->setDialFile(options_page->svgSourceFile->path());
|
||||
m_config->setRange(options_page->minValue->value(),options_page->maxValue->value());
|
||||
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
|
||||
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
|
||||
@ -130,25 +132,6 @@ void LineardialGadgetOptionsPage::on_fontPicker_clicked()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Opens an open file dialog.
|
||||
|
||||
*/
|
||||
void LineardialGadgetOptionsPage::on_loadFile_clicked()
|
||||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||
tr("QFileDialog::getOpenFileName()"),
|
||||
options_page->svgSourceFile->text(),
|
||||
tr("All Files (*);;SVG Files (*.svg)"),
|
||||
&selectedFilter,
|
||||
options);
|
||||
if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Fills in the field1 combo box when value is changed in the
|
||||
object1 field
|
||||
|
@ -62,7 +62,6 @@ private:
|
||||
QFont font;
|
||||
|
||||
private slots:
|
||||
void on_loadFile_clicked();
|
||||
void on_fontPicker_clicked();
|
||||
void on_objectName_currentIndexChanged(QString val);
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
<rect>
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
<width>491</width>
|
||||
<width>533</width>
|
||||
<height>321</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -45,7 +45,7 @@
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
@ -63,12 +63,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="svgSourceFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadFile">
|
||||
<property name="text">
|
||||
<string>Load file...</string>
|
||||
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -512,6 +512,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -56,11 +56,13 @@ QWidget *PFDGadgetOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->svgSourceFile->setText(m_config->dialFile());
|
||||
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
|
||||
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
|
||||
options_page->svgSourceFile->setPath(m_config->dialFile());
|
||||
options_page->useOpenGL->setChecked(m_config->useOpenGL());
|
||||
options_page->hqText->setChecked(m_config->getHqFonts());
|
||||
|
||||
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
@ -72,30 +74,12 @@ QWidget *PFDGadgetOptionsPage::createPage(QWidget *parent)
|
||||
*/
|
||||
void PFDGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
m_config->setDialFile(options_page->svgSourceFile->path());
|
||||
m_config->setUseOpenGL(options_page->useOpenGL->checkState());
|
||||
m_config->setHqFonts(options_page->hqText->checkState());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Opens an open file dialog.
|
||||
|
||||
*/
|
||||
void PFDGadgetOptionsPage::on_loadFile_clicked()
|
||||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||
tr("QFileDialog::getOpenFileName()"),
|
||||
options_page->svgSourceFile->text(),
|
||||
tr("All Files (*);;SVG Files (*.svg)"),
|
||||
&selectedFilter,
|
||||
options);
|
||||
if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PFDGadgetOptionsPage::finish()
|
||||
{
|
||||
|
@ -60,7 +60,6 @@ private:
|
||||
PFDGadgetConfiguration *m_config;
|
||||
|
||||
private slots:
|
||||
void on_loadFile_clicked();
|
||||
};
|
||||
|
||||
#endif // PFDGADGETOPTIONSPAGE_H
|
||||
|
@ -28,7 +28,7 @@
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,1,0">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
@ -45,7 +45,7 @@
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
@ -63,12 +63,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="svgSourceFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadFile">
|
||||
<property name="text">
|
||||
<string>Load file...</string>
|
||||
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -131,6 +131,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user