diff options
author | Olli Werwolff <qt-info@nokia.com> | 2010-07-14 10:46:28 +0200 |
---|---|---|
committer | Olli Werwolff <qt-info@nokia.com> | 2010-07-14 10:46:28 +0200 |
commit | 9e3db930b9a390dd4c5b4d35e4c04cc6ea6c7c1c (patch) | |
tree | ffbbd574434df97741100bf91edec162f78d27c7 | |
parent | 78cc3cb32d142d0d543690f8865aaee6e9b7924a (diff) |
Added satellite gui to location entry
Task-number: QTSIM-42
Reviewed-by: ckamm
-rw-r--r-- | library/components/locationui.cpp | 332 | ||||
-rw-r--r-- | library/components/locationui.h | 59 | ||||
-rw-r--r-- | library/scriptadapter.h | 1 |
3 files changed, 391 insertions, 1 deletions
diff --git a/library/components/locationui.cpp b/library/components/locationui.cpp index 263aa06..d92dc67 100644 --- a/library/components/locationui.cpp +++ b/library/components/locationui.cpp @@ -33,10 +33,17 @@ #include "toolbox.h" #include <QtGui/QLineEdit> +#include <QtGui/QLabel> #include <QtGui/QDoubleValidator> #include <QtGui/QRadioButton> +#include <QtGui/QPushButton> #include <QtGui/QBoxLayout> #include <QtGui/QDateTimeEdit> +#include <QtGui/QComboBox> +#include <QtGui/QGroupBox> +#include <QtGui/QFormLayout> +#include <QtGui/QInputDialog> +#include <QtGui/QCheckBox> LocationUi::LocationUi(QWidget *parent) : ToolBoxPage(parent) @@ -94,8 +101,57 @@ LocationUi::LocationUi(QWidget *parent) connect(mCurrentRadio, SIGNAL(toggled(bool)), SLOT(updateTimeEditDisabled())); connect(mTimeEdit, SIGNAL(dateTimeChanged(const QDateTime &)), SLOT(emitLocationChange())); + QHBoxLayout *hLayout = new QHBoxLayout(); + QLabel *prnLabel = new QLabel(tr("PRN")); + satellitePrns = new QComboBox(); + hLayout->addWidget(prnLabel); + hLayout->addWidget(satellitePrns); + vLayout = new QVBoxLayout(); + vLayout->addLayout(hLayout); + QPushButton *satelliteChangePrn = new QPushButton(tr("Change PRN")); + QPushButton *removeSatellite = new QPushButton(tr("Remove")); + QPushButton *addSatellite = new QPushButton(tr("Add")); + hLayout = new QHBoxLayout(); + hLayout->addWidget(satelliteChangePrn); + hLayout->addWidget(removeSatellite); + hLayout->addWidget(addSatellite); + vLayout->addLayout(hLayout); + QRegExp rx("\\d*"); + satelliteAzimuth = new QLineEdit(); + satelliteAzimuth->setValidator(new QRegExpValidator(rx, this)); + satelliteElevation = new QLineEdit(); + satelliteElevation->setValidator(new QRegExpValidator(rx, this)); + satelliteSignalStrength = new QLineEdit(); + satelliteSignalStrength->setValidator(new QRegExpValidator(rx, this)); + satelliteInUse = new QCheckBox(); + QFormLayout *satelliteLayout = new QFormLayout(); + satelliteLayout->addRow(tr("Azimuth"), satelliteAzimuth); + satelliteLayout->addRow(tr("Elevation"), satelliteElevation); + satelliteLayout->addRow(tr("Signal strength"), satelliteSignalStrength); + satelliteLayout->addRow(tr("In use"), satelliteInUse); + QGroupBox *satellitePropertyGroupBox = new QGroupBox(tr("Satellite properties")); + satellitePropertyGroupBox->setLayout(satelliteLayout); + vLayout->addWidget(satellitePropertyGroupBox); + QGroupBox *satellites = new QGroupBox(tr("Satellites")); + satellites->setLayout(vLayout); + connect(satellitePrns, SIGNAL(activated(int)), SLOT(showSatelliteInfo())); + connect(addSatellite, SIGNAL(clicked()), SLOT(addSatelliteClicked())); + connect(removeSatellite, SIGNAL(clicked()), SLOT(removeSatelliteClicked())); + connect(satelliteChangePrn, SIGNAL(clicked()), SLOT(changeSatellitePrnClicked())); + connect(satelliteAzimuth, SIGNAL(editingFinished()), SLOT(editSatelliteInfo())); + connect(satelliteElevation, SIGNAL(editingFinished()), SLOT(editSatelliteInfo())); + connect(satelliteSignalStrength, SIGNAL(editingFinished()), SLOT(editSatelliteInfo())); + connect(satelliteInUse, SIGNAL(toggled(bool)), SLOT(editSatelliteInfo())); + item = new OptionsItem("", satellites, true); + item->setTags(tags << tr("prn") << tr("signal") << tr("strength") << tr("azimuth") << tr("elevation") << tr("use") << tr("satellite")); + item->setAdvanced(); + optionsList << item; + + setOptions(optionsList); setTitle(tr("Location")); + + connect(this, SIGNAL(satelliteDataChanged(LocationUi::SatelliteData)), SLOT(showSatelliteInfo())); } LocationUi::~LocationUi() @@ -118,6 +174,11 @@ LocationUi::LocationData LocationUi::locationData() const return location; } +LocationUi::SatelliteData LocationUi::satelliteData() const +{ + return mSatelliteData; +} + void LocationUi::updateLocationTime() { mTimeEdit->setDateTime(QDateTime::currentDateTime()); @@ -138,11 +199,151 @@ void LocationUi::setDisplayedLocation(const LocationData &location) mCurrentRadio->setChecked(location.useCurrentTime); } +void LocationUi::setSatelliteData(const LocationUi::SatelliteData &data) +{ + setDisplayedSatelliteData(data); + emit satelliteDataChanged(data); +} + +void LocationUi::setDisplayedSatelliteData(const LocationUi::SatelliteData &data) +{ + mSatelliteData = data; + updateSatelliteList(); +} + + void LocationUi::emitLocationChange() const { emit locationChanged(locationData()); } +void LocationUi::emitSatelliteDataChange() const +{ + emit satelliteDataChanged(satelliteData()); +} + +void LocationUi::showSatelliteInfo() +{ + bool editingEnabled = satellitePrns->count() != 0; + satelliteAzimuth->setEnabled(editingEnabled); + satelliteElevation->setEnabled(editingEnabled); + satelliteSignalStrength->setEnabled(editingEnabled); + satelliteInUse->setEnabled(editingEnabled); + + if (!editingEnabled) + return; + + int currentSatellite = satellitePrns->currentText().toInt(); + satelliteAzimuth->setText(QString::number(mScriptInterface->azimuth(currentSatellite))); + satelliteElevation->setText(QString::number(mScriptInterface->elevation(currentSatellite))); + satelliteSignalStrength->setText(QString::number(mScriptInterface->signalStrength(currentSatellite))); + satelliteInUse->setChecked(mScriptInterface->inUse(currentSatellite)); +} + +void LocationUi::editSatelliteInfo() +{ + if (satellitePrns->count() == 0) + return; + + int currentSatellite = satellitePrns->currentText().toInt(); + for (int i = 0; i < mSatelliteData.satellites.count(); i++) { + SatelliteData::SatelliteInfo info = mSatelliteData.satellites[i]; + if (info.prn == currentSatellite) { + info.azimuth = satelliteAzimuth->text().toDouble(); + info.elevation = satelliteElevation->text().toDouble(); + info.signalStrength = satelliteSignalStrength->text().toInt(); + info.inUse = satelliteInUse->isChecked(); + mSatelliteData.satellites[i] = info; + emitSatelliteDataChange(); + break; + } + } +} + +void LocationUi::updateSatelliteList(int satelliteToShow) +{ + satellitePrns->clear(); + for (int i = 0; i < mSatelliteData.satellites.count(); i++) { + SatelliteData::SatelliteInfo satelliteInfo = mSatelliteData.satellites.at(i); + satellitePrns->addItem(QString::number(satelliteInfo.prn)); + + if (satelliteInfo.prn == satelliteToShow) + satellitePrns->setCurrentIndex(i); + } + showSatelliteInfo(); +} + +bool LocationUi::renumberDisplayedSatellite(int oldPrn, int newPrn) +{ + bool needsUpdate = false; + for (int i = 0; i < mSatelliteData.satellites.count(); i++) { + SatelliteData::SatelliteInfo info = mSatelliteData.satellites.at(i); + if (info.prn == oldPrn) { + mSatelliteData.satellites[i].prn = newPrn; + needsUpdate = true; + } + } + if (needsUpdate) + updateSatelliteList(newPrn); + return needsUpdate; +} + +void LocationUi::changeSatellitePrnClicked() +{ + if (satellitePrns->count() == 0) + return; + + int oldPrn = satellitePrns->currentText().toInt(); + int newPrn = QInputDialog::getInt(0, + "Change Satellite's PRN", "Enter the new PRN:", + oldPrn, 0); + + if (oldPrn != newPrn) { + renumberDisplayedSatellite(oldPrn, newPrn); + emitSatelliteDataChange(); + } +} + +void LocationUi::addDisplayedSatellite(int prn) +{ + SatelliteData::SatelliteInfo info; + info.prn = prn; + mSatelliteData.satellites.append(info); + updateSatelliteList(prn); +} + +void LocationUi::addSatelliteClicked() +{ + int newPrn = QInputDialog::getInt(0, + "Add New Satellite", "Enter the new PRN:"); + + addDisplayedSatellite(newPrn); + emitSatelliteDataChange(); +} + +bool LocationUi::removeDisplayedSatellite(int prn) +{ + bool needsUpdate = false; + for (int i = mSatelliteData.satellites.count() - 1; i >= 0; i--) { + if (mSatelliteData.satellites.at(i).prn == prn) { + mSatelliteData.satellites.removeAt(i); + needsUpdate = true; + } + } + if (needsUpdate) + updateSatelliteList(); + return needsUpdate; +} + +void LocationUi::removeSatelliteClicked() +{ + if (satellitePrns->count() == 0) + return; + + removeDisplayedSatellite(satellitePrns->currentText().toInt()); + emitSatelliteDataChange(); +} + void LocationUi::updateTimeEditDisabled() { mTimeEdit->setDisabled(mCurrentRadio->isChecked()); @@ -159,6 +360,46 @@ LocationScriptInterface::~LocationScriptInterface() { } +QList<int> LocationScriptInterface::satellites() const +{ + QList<int> prns; + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) + prns.append(ui->mSatelliteData.satellites.at(i).prn); + return prns; +} + +qreal LocationScriptInterface::elevation(int satellite) const +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) + if (ui->mSatelliteData.satellites.at(i).prn == satellite) + return ui->mSatelliteData.satellites.at(i).elevation; + return -1; +} + +qreal LocationScriptInterface::azimuth(int satellite) const +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) + if (ui->mSatelliteData.satellites.at(i).prn == satellite) + return ui->mSatelliteData.satellites.at(i).azimuth; + return -1; +} + +int LocationScriptInterface::signalStrength(int satellite) const +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) + if (ui->mSatelliteData.satellites.at(i).prn == satellite) + return ui->mSatelliteData.satellites.at(i).signalStrength; + return -1; +} + +bool LocationScriptInterface::inUse(int satellite) const +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) + if (ui->mSatelliteData.satellites.at(i).prn == satellite) + return ui->mSatelliteData.satellites.at(i).inUse; + return false; +} + double LocationScriptInterface::latitude() const { return ui->mLatitudeEdit->text().toDouble(); @@ -223,3 +464,94 @@ QDateTime LocationScriptInterface::timestamp() const { return ui->mTimeEdit->dateTime(); } + +bool LocationScriptInterface::addSatellite(int prn) +{ + ui->addDisplayedSatellite(prn); + ui->emitSatelliteDataChange(); + return true; +} + +bool LocationScriptInterface::addSatellite(int prn, qreal elevation, qreal azimuth, int signalStrength, bool inUse) +{ + ui->addDisplayedSatellite(prn); + LocationUi::SatelliteData::SatelliteInfo &si = ui->mSatelliteData.satellites[prn]; + si.azimuth = azimuth; + si.elevation = elevation; + si.signalStrength = signalStrength; + si.inUse = inUse; + ui->emitSatelliteDataChange(); + return true; +} + +bool LocationScriptInterface::removeSatellite(int prn) +{ + bool removed = ui->removeDisplayedSatellite(prn); + if (removed) + ui->emitSatelliteDataChange(); + return removed; +} + +bool LocationScriptInterface::setPrn(int oldPrn, int newPrn) +{ + bool dataChanged = ui->renumberDisplayedSatellite(oldPrn, newPrn); + if (dataChanged) + ui->emitSatelliteDataChange(); + return dataChanged; +} + +bool LocationScriptInterface::setElevation(int prn, qreal elevation) +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) { + if (ui->mSatelliteData.satellites[i].prn == prn) { + if (ui->mSatelliteData.satellites[i].elevation != elevation) { + ui->mSatelliteData.satellites[i].elevation = elevation; + ui->emitSatelliteDataChange(); + return true; + } + } + } + return false; +} + +bool LocationScriptInterface::setAzimuth(int prn, qreal azimuth) +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) { + if (ui->mSatelliteData.satellites[i].prn == prn) { + if (ui->mSatelliteData.satellites[i].azimuth != azimuth) { + ui->mSatelliteData.satellites[i].azimuth = azimuth; + ui->emitSatelliteDataChange(); + return true; + } + } + } + return false; +} + +bool LocationScriptInterface::setSignalStrength(int prn, int signalStrength) +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) { + if (ui->mSatelliteData.satellites[i].prn == prn) { + if (ui->mSatelliteData.satellites[i].signalStrength != signalStrength) { + ui->mSatelliteData.satellites[i].signalStrength = signalStrength; + ui->emitSatelliteDataChange(); + return true; + } + } + } + return false; +} + +bool LocationScriptInterface::setInUse(int prn, bool inUse) +{ + for (int i = 0; i < ui->mSatelliteData.satellites.count(); i++) { + if (ui->mSatelliteData.satellites[i].prn == prn) { + if (ui->mSatelliteData.satellites[i].inUse != inUse) { + ui->mSatelliteData.satellites[i].inUse = inUse; + ui->emitSatelliteDataChange(); + return true; + } + } + } + return false; +} diff --git a/library/components/locationui.h b/library/components/locationui.h index 2423f45..1c0440c 100644 --- a/library/components/locationui.h +++ b/library/components/locationui.h @@ -34,11 +34,14 @@ #include "toolbox.h" #include <QtCore/QDateTime> +#include <QtCore/QHash> class LocationScriptInterface; class QLineEdit; class QDateTimeEdit; class QRadioButton; +class QComboBox; +class QCheckBox; class REMOTECONTROLWIDGETSHARED_EXPORT LocationUi : public ToolBoxPage { @@ -53,6 +56,20 @@ public: bool useCurrentTime; }; + struct SatelliteData { + struct SatelliteInfo + { + SatelliteInfo() : elevation(0), azimuth(0), signalStrength(0), inUse(false){} + int prn; + qreal elevation; + qreal azimuth; + int signalStrength; + bool inUse; + }; + + QList<SatelliteInfo> satellites; + }; + public: explicit LocationUi(QWidget *parent = 0); virtual ~LocationUi(); @@ -60,19 +77,37 @@ public: LocationScriptInterface *scriptInterface() const; LocationData locationData() const; + SatelliteData satelliteData() const; public slots: void setLocation(const LocationUi::LocationData &location); void setDisplayedLocation(const LocationUi::LocationData &location); + void setSatelliteData(const LocationUi::SatelliteData &data); + void setDisplayedSatelliteData(const LocationUi::SatelliteData &data); + signals: void locationChanged(const LocationUi::LocationData &location) const; + void satelliteDataChanged(const LocationUi::SatelliteData &data) const; private slots: void updateLocationTime(); void updateTimeEditDisabled(); void emitLocationChange() const; + void emitSatelliteDataChange() const; + void showSatelliteInfo(); + void editSatelliteInfo(); + void updateSatelliteList(int satelliteToShow = 0); + + void addDisplayedSatellite(int prn); + bool removeDisplayedSatellite(int prn); + bool renumberDisplayedSatellite(int oldPrn, int newPrn); + + void changeSatellitePrnClicked(); + void addSatelliteClicked(); + void removeSatelliteClicked(); + private: QLineEdit *mLatitudeEdit; QLineEdit *mLongitudeEdit; @@ -81,8 +116,16 @@ private: QRadioButton *mOverrideRadio; QDateTimeEdit *mTimeEdit; + QComboBox *satellitePrns; + QLineEdit *satelliteElevation; + QLineEdit *satelliteAzimuth; + QLineEdit *satelliteSignalStrength; + QCheckBox *satelliteInUse; + friend class LocationScriptInterface; LocationScriptInterface *mScriptInterface; + + SatelliteData mSatelliteData; }; class LocationScriptInterface : public QObject @@ -98,6 +141,12 @@ public: Q_PROPERTY(bool useCurrentTimestamp READ useCurrentTimestamp WRITE setUseCurrentTimestamp) Q_PROPERTY(QDateTime timestamp READ timestamp WRITE setTimestamp) + Q_INVOKABLE QList<int> satellites() const; + Q_INVOKABLE qreal elevation(int satellite) const; + Q_INVOKABLE qreal azimuth(int satellite) const; + Q_INVOKABLE int signalStrength(int satellite) const; + Q_INVOKABLE bool inUse(int satellite) const; + double latitude() const; void setLatitude(double); @@ -113,6 +162,16 @@ public: QDateTime timestamp() const; void setTimestamp(const QDateTime &dt); +public slots: + bool addSatellite(int prn); + bool addSatellite(int prn, qreal elevation, qreal azimuth, int signalStrength, bool inUse); + bool removeSatellite(int prn); + bool setPrn(int oldPrn, int newPrn); + bool setElevation(int prn, qreal elevation); + bool setAzimuth(int prn, qreal azimuth); + bool setSignalStrength(int prn, int signalStrength); + bool setInUse(int prn, bool inUse); + private: LocationUi *ui; }; diff --git a/library/scriptadapter.h b/library/scriptadapter.h index 847280e..fcbaea3 100644 --- a/library/scriptadapter.h +++ b/library/scriptadapter.h @@ -35,7 +35,6 @@ #include <QtCore/QObject> #include <QtCore/QTimer> #include <QtCore/QStringList> -#include <QtCore/QHash> #include <QtCore/QThread> #include <QtCore/QMutex> #include <QtCore/QWaitCondition> |