mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Cleanup: remove ReverseGeoLookupThread
Fetching the taxonomy from GPS coordinates was implemented in a QThread. But the only access to the main function was a direct call to run(). Thus, the thread was *never* started. The function call was always asynchronous [it was using an event loop though, so the UI doesn't hang]. Notably this means that the signals connected to the thread would never fire. And the spinner would never be activated. Thus: 1) Turn the thread into a simple function. 2) Remove the spinner. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
76e5c5ac67
commit
ce8199cdfd
7 changed files with 8 additions and 70 deletions
|
@ -20,17 +20,7 @@
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
ReverseGeoLookupThread* ReverseGeoLookupThread::instance()
|
void reverseGeoLookup()
|
||||||
{
|
|
||||||
static ReverseGeoLookupThread* self = new ReverseGeoLookupThread();
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReverseGeoLookupThread::ReverseGeoLookupThread(QObject *obj) : QThread(obj)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReverseGeoLookupThread::run()
|
|
||||||
{
|
{
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
QNetworkAccessManager *rgl = new QNetworkAccessManager();
|
QNetworkAccessManager *rgl = new QNetworkAccessManager();
|
||||||
|
@ -41,7 +31,7 @@ void ReverseGeoLookupThread::run()
|
||||||
|
|
||||||
request.setRawHeader("Accept", "text/json");
|
request.setRawHeader("Accept", "text/json");
|
||||||
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
||||||
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
|
|
||||||
struct dive_site *ds = &displayed_dive_site;
|
struct dive_site *ds = &displayed_dive_site;
|
||||||
|
|
||||||
|
@ -50,7 +40,7 @@ void ReverseGeoLookupThread::run()
|
||||||
|
|
||||||
QNetworkReply *reply = rgl->get(request);
|
QNetworkReply *reply = rgl->get(request);
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
timer.start(5000); // 5 secs. timeout
|
timer.start(5000); // 5 secs. timeout
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
@ -119,13 +109,13 @@ void ReverseGeoLookupThread::run()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report_error("timeout accessing geonames.org");
|
report_error("timeout accessing geonames.org");
|
||||||
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
reply->abort();
|
reply->abort();
|
||||||
}
|
}
|
||||||
// next check the oceans API to figure out the body of water
|
// next check the oceans API to figure out the body of water
|
||||||
request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL).section(QRegExp("[-_ ]"), 0, 0)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL).section(QRegExp("[-_ ]"), 0, 0)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
|
||||||
reply = rgl->get(request);
|
reply = rgl->get(request);
|
||||||
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
timer.start(5000); // 5 secs. timeout
|
timer.start(5000); // 5 secs. timeout
|
||||||
loop.exec();
|
loop.exec();
|
||||||
if (timer.isActive()) {
|
if (timer.isActive()) {
|
||||||
|
@ -165,7 +155,7 @@ void ReverseGeoLookupThread::run()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report_error("timeout accessing geonames.org");
|
report_error("timeout accessing geonames.org");
|
||||||
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
reply->abort();
|
reply->abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,6 @@
|
||||||
#ifndef DIVESITEHELPERS_H
|
#ifndef DIVESITEHELPERS_H
|
||||||
#define DIVESITEHELPERS_H
|
#define DIVESITEHELPERS_H
|
||||||
|
|
||||||
#include "units.h"
|
void reverseGeoLookup();
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
class ReverseGeoLookupThread : public QThread {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
static ReverseGeoLookupThread *instance();
|
|
||||||
void lookup(struct dive_site *ds);
|
|
||||||
void run() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ReverseGeoLookupThread(QObject *parent = 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DIVESITEHELPERS_H
|
#endif // DIVESITEHELPERS_H
|
||||||
|
|
|
@ -330,8 +330,7 @@ void LocationInformationWidget::resetPallete()
|
||||||
|
|
||||||
void LocationInformationWidget::reverseGeocode()
|
void LocationInformationWidget::reverseGeocode()
|
||||||
{
|
{
|
||||||
ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
|
reverseGeoLookup();
|
||||||
geoLookup->run();
|
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,9 +266,6 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
redoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z));
|
redoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z));
|
||||||
ui.menu_Edit->addActions({ undoAction, redoAction });
|
ui.menu_Edit->addActions({ undoAction, redoAction });
|
||||||
|
|
||||||
ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
|
|
||||||
connect(geoLookup, SIGNAL(started()),information(), SLOT(disableGeoLookupEdition()));
|
|
||||||
connect(geoLookup, SIGNAL(finished()), information(), SLOT(enableGeoLookupEdition()));
|
|
||||||
#ifndef NO_PRINTING
|
#ifndef NO_PRINTING
|
||||||
// copy the bundled print templates to the user path
|
// copy the bundled print templates to the user path
|
||||||
QStringList templateBackupList;
|
QStringList templateBackupList;
|
||||||
|
|
|
@ -195,21 +195,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||||
ui.cylinders->view()->horizontalHeader()->addAction(action);
|
ui.cylinders->view()->horizontalHeader()->addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.waitingSpinner->setRoundness(70.0);
|
|
||||||
ui.waitingSpinner->setMinimumTrailOpacity(15.0);
|
|
||||||
ui.waitingSpinner->setTrailFadePercentage(70.0);
|
|
||||||
ui.waitingSpinner->setNumberOfLines(8);
|
|
||||||
ui.waitingSpinner->setLineLength(5);
|
|
||||||
ui.waitingSpinner->setLineWidth(3);
|
|
||||||
ui.waitingSpinner->setInnerRadius(5);
|
|
||||||
ui.waitingSpinner->setRevolutionsPerSecond(1);
|
|
||||||
|
|
||||||
connect(ReverseGeoLookupThread::instance(), SIGNAL(finished()),
|
|
||||||
LocationInformationModel::instance(), SLOT(update()));
|
|
||||||
|
|
||||||
connect(ReverseGeoLookupThread::instance(), &QThread::finished,
|
|
||||||
this, &MainTab::setCurrentLocationIndex);
|
|
||||||
|
|
||||||
connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
|
connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
|
||||||
ui.location, &DiveLocationLineEdit::fixPopupPosition);
|
ui.location, &DiveLocationLineEdit::fixPopupPosition);
|
||||||
|
|
||||||
|
@ -245,16 +230,6 @@ void MainTab::setCurrentLocationIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::enableGeoLookupEdition()
|
|
||||||
{
|
|
||||||
ui.waitingSpinner->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainTab::disableGeoLookupEdition()
|
|
||||||
{
|
|
||||||
ui.waitingSpinner->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainTab::toggleTriggeredColumn()
|
void MainTab::toggleTriggeredColumn()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
|
|
@ -98,8 +98,6 @@ slots:
|
||||||
void updateTextLabels(bool showUnits = true);
|
void updateTextLabels(bool showUnits = true);
|
||||||
void escDetected(void);
|
void escDetected(void);
|
||||||
void showLocation();
|
void showLocation();
|
||||||
void enableGeoLookupEdition();
|
|
||||||
void disableGeoLookupEdition();
|
|
||||||
void setCurrentLocationIndex();
|
void setCurrentLocationIndex();
|
||||||
EditMode getEditMode() const;
|
EditMode getEditMode() const;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -230,9 +230,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QtWaitingSpinner" name="waitingSpinner" native="true"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -599,12 +596,6 @@
|
||||||
<extends>QPlainTextEdit</extends>
|
<extends>QPlainTextEdit</extends>
|
||||||
<header>desktop-widgets/tagwidget.h</header>
|
<header>desktop-widgets/tagwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>QtWaitingSpinner</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>desktop-widgets/qtwaitingspinner.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>DiveLocationLineEdit</class>
|
<class>DiveLocationLineEdit</class>
|
||||||
<extends>QLineEdit</extends>
|
<extends>QLineEdit</extends>
|
||||||
|
|
Loading…
Reference in a new issue