Skip to content

Commit

Permalink
Implementation for lp://914353 makes the SIMBAD portion of the search…
Browse files Browse the repository at this point in the history
… optional.
  • Loading branch information
treaves committed Jan 10, 2012
1 parent 5ac05e5 commit ee5f5fa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
67 changes: 44 additions & 23 deletions src/gui/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QFrame>
#include <QLabel>
#include <QPushButton>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QTextEdit>
Expand Down Expand Up @@ -148,6 +149,10 @@ SearchDialog::SearchDialog() : simbadReply(NULL)
greekLetters.insert("chi", QString(QChar(0x03C7)));
greekLetters.insert("psi", QString(QChar(0x03C8)));
greekLetters.insert("omega", QString(QChar(0x03C9)));

QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
useSIMBAD = conf->value("search/useSIMBAD", 1.0).toBool();
}

SearchDialog::~SearchDialog()
Expand Down Expand Up @@ -180,7 +185,6 @@ void SearchDialog::createDialogContent()
{
ui->setupUi(dialog);
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(languageChanged()));
// setSimpleStyle();
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->lineEditSearchSkyObject, SIGNAL(textChanged(const QString&)),
this, SLOT(onSearchTextChanged(const QString&)));
Expand Down Expand Up @@ -220,6 +224,21 @@ void SearchDialog::createDialogContent()
connect(ui->chiPushButton, SIGNAL(clicked(bool)), this, SLOT(greekLetterClicked()));
connect(ui->psiPushButton, SIGNAL(clicked(bool)), this, SLOT(greekLetterClicked()));
connect(ui->omegaPushButton, SIGNAL(clicked(bool)), this, SLOT(greekLetterClicked()));

connect(ui->checkBoxUseSIMBAD, SIGNAL(stateChanged(int)), this, SLOT(useSIMBADStateChanged(int)));
if (useSIMBAD){
ui->checkBoxUseSIMBAD->setChecked(true);
}

}

void SearchDialog::useSIMBADStateChanged(int state)
{
useSIMBAD = (state == Qt::Checked);

QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
conf->setValue("search/useSIMBAD", useSIMBAD);
}

void SearchDialog::setVisible(bool v)
Expand Down Expand Up @@ -252,37 +271,39 @@ void SearchDialog::manualPositionChanged()

void SearchDialog::onSearchTextChanged(const QString& text)
{
if (simbadReply)
{
disconnect(simbadReply, SIGNAL(statusChanged()), this, SLOT(onSimbadStatusChanged()));
delete simbadReply;
simbadReply=NULL;
}
simbadResults.clear();
// This block needs to go before the trimmedText.isEmpty() or the SIMBAD result does not
// get properly cleared.
if (useSIMBAD) {
if (simbadReply) {
disconnect(simbadReply,
SIGNAL(statusChanged()),
this,
SLOT(onSimbadStatusChanged()));
delete simbadReply;
simbadReply=NULL;
}
simbadResults.clear();
}

QString trimmedText = text.trimmed().toLower();
if (trimmedText.isEmpty())
{
QString trimmedText = text.trimmed().toLower();
if (trimmedText.isEmpty()) {
ui->completionLabel->clearValues();
ui->completionLabel->selectFirst();
ui->completionLabel->selectFirst();
ui->simbadStatusLabel->setText("");
ui->pushButtonGotoSearchSkyObject->setEnabled(false);
}
else
{
simbadReply = simbadSearcher->lookup(trimmedText, 3);
onSimbadStatusChanged();
connect(simbadReply, SIGNAL(statusChanged()), this, SLOT(onSimbadStatusChanged()));
} else {
if (useSIMBAD) {
simbadReply = simbadSearcher->lookup(trimmedText, 3);
onSimbadStatusChanged();
connect(simbadReply, SIGNAL(statusChanged()), this, SLOT(onSimbadStatusChanged()));
}

QString greekText = substituteGreek(trimmedText);
QStringList matches;
if(greekText != trimmedText)
{
if(greekText != trimmedText) {
matches = objectMgr->listMatchingObjectsI18n(trimmedText, 3);
matches += objectMgr->listMatchingObjectsI18n(greekText, (5 - matches.size()));
}
else
{
} else {
matches = objectMgr->listMatchingObjectsI18n(trimmedText, 5);
}

Expand Down
6 changes: 5 additions & 1 deletion src/gui/SearchDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ private slots:

//! Called when the user edit the manual position controls
void manualPositionChanged();


//! Whether to use SIMBAD for searches or not.
void useSIMBADStateChanged(int state);

private:
class SimbadSearcher* simbadSearcher;
class SimbadLookupReply* simbadReply;
Expand All @@ -104,6 +107,7 @@ private slots:
QString substituteGreek(const QString& keyString);
QString getGreekLetterByName(const QString& potentialGreekLetterName);
QHash<QString, QString> greekLetters;
bool useSIMBAD;
};

#endif // _SEARCHDIALOG_HPP_
Expand Down
12 changes: 11 additions & 1 deletion src/gui/searchDialogGui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QWidget" name="objectTab" native="true">
<widget class="QWidget" name="objectTab">
<attribute name="title">
<string>Object</string>
</attribute>
Expand Down Expand Up @@ -185,6 +185,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUseSIMBAD">
<property name="text">
<string>SIMBAD</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonGotoSearchSkyObject">
<property name="sizePolicy">
Expand Down

0 comments on commit ee5f5fa

Please sign in to comment.