diff --git a/ground/src/libs/utils/pathutils.cpp b/ground/src/libs/utils/pathutils.cpp index d788a3a7e..ce6322fd0 100644 --- a/ground/src/libs/utils/pathutils.cpp +++ b/ground/src/libs/utils/pathutils.cpp @@ -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); } } diff --git a/ground/src/plugins/dial/dialgadgetoptionspage.cpp b/ground/src/plugins/dial/dialgadgetoptionspage.cpp index fdfff6819..1a5e3e127 100644 --- a/ground/src/plugins/dial/dialgadgetoptionspage.cpp +++ b/ground/src/plugins/dial/dialgadgetoptionspage.cpp @@ -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(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() { diff --git a/ground/src/plugins/dial/dialgadgetoptionspage.h b/ground/src/plugins/dial/dialgadgetoptionspage.h index 32c432211..b9ca273ef 100644 --- a/ground/src/plugins/dial/dialgadgetoptionspage.h +++ b/ground/src/plugins/dial/dialgadgetoptionspage.h @@ -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); diff --git a/ground/src/plugins/dial/dialgadgetoptionspage.ui b/ground/src/plugins/dial/dialgadgetoptionspage.ui index 3e7693a77..318289e6e 100644 --- a/ground/src/plugins/dial/dialgadgetoptionspage.ui +++ b/ground/src/plugins/dial/dialgadgetoptionspage.ui @@ -45,7 +45,7 @@ 10 - + 10 @@ -57,23 +57,35 @@ + + + 0 + 0 + + Dial SVG: - - - - - - Load file... + + + + 0 + 0 + + + + 0 + 0 + + Dial font: @@ -762,6 +774,14 @@ + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
diff --git a/ground/src/plugins/importexport/importexportgadgetoptionspage.cpp b/ground/src/plugins/importexport/importexportgadgetoptionspage.cpp index de088ce3f..d369b02ba 100644 --- a/ground/src/plugins/importexport/importexportgadgetoptionspage.cpp +++ b/ground/src/plugins/importexport/importexportgadgetoptionspage.cpp @@ -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()); } diff --git a/ground/src/plugins/importexport/importexportgadgetoptionspage.ui b/ground/src/plugins/importexport/importexportgadgetoptionspage.ui index b7713cddf..da01146ab 100644 --- a/ground/src/plugins/importexport/importexportgadgetoptionspage.ui +++ b/ground/src/plugins/importexport/importexportgadgetoptionspage.ui @@ -45,7 +45,7 @@ 10 - + 10 @@ -63,12 +63,12 @@ - - - - - - Load file... + + + + 0 + 0 + @@ -90,6 +90,14 @@
+ + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp index 803fc89a6..1136eaa95 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp @@ -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(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 diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h index 19a6dfc4c..17311cb2f 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h @@ -62,7 +62,6 @@ private: QFont font; private slots: - void on_loadFile_clicked(); void on_fontPicker_clicked(); void on_objectName_currentIndexChanged(QString val); diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui index 43e0f0b01..1e2617627 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui @@ -24,7 +24,7 @@ -1 -1 - 491 + 533 321 @@ -45,7 +45,7 @@ 10 - + 10 @@ -63,12 +63,12 @@ - - - - - - Load file... + + + + 0 + 0 + @@ -512,6 +512,14 @@ + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
diff --git a/ground/src/plugins/pfd/pfdgadgetoptionspage.cpp b/ground/src/plugins/pfd/pfdgadgetoptionspage.cpp index 5486304fc..0f0584b21 100644 --- a/ground/src/plugins/pfd/pfdgadgetoptionspage.cpp +++ b/ground/src/plugins/pfd/pfdgadgetoptionspage.cpp @@ -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(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() { diff --git a/ground/src/plugins/pfd/pfdgadgetoptionspage.h b/ground/src/plugins/pfd/pfdgadgetoptionspage.h index 5c48d1d5b..df30f0d6d 100644 --- a/ground/src/plugins/pfd/pfdgadgetoptionspage.h +++ b/ground/src/plugins/pfd/pfdgadgetoptionspage.h @@ -60,7 +60,6 @@ private: PFDGadgetConfiguration *m_config; private slots: - void on_loadFile_clicked(); }; #endif // PFDGADGETOPTIONSPAGE_H diff --git a/ground/src/plugins/pfd/pfdgadgetoptionspage.ui b/ground/src/plugins/pfd/pfdgadgetoptionspage.ui index 54ff9d332..44ef78ff5 100644 --- a/ground/src/plugins/pfd/pfdgadgetoptionspage.ui +++ b/ground/src/plugins/pfd/pfdgadgetoptionspage.ui @@ -28,7 +28,7 @@ 331 - + QLayout::SetMinimumSize @@ -45,7 +45,7 @@ 10 - + 10 @@ -63,12 +63,12 @@ - - - - - - Load file... + + + + 0 + 0 + @@ -131,6 +131,14 @@ + + + Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+