Commit d36b326d authored by Akarsh Simha's avatar Akarsh Simha

Experimental testing: using Name Resolver in Find Dialog

Improvements needed (which is why this is not the end of it):

1. Enable the resolver machinery using a flag in the FindDialog
   constructor.

2. Find Dialog should show a phantom entry (eg: "Search the internet")
   to present users that option.

3. We must commit the newly created DeepSkyObject gracefully into some
   SkyComponent so that it appears in objectNearest() searches and
   other such places.

4. Allow commiting the newly created object into the SQLite Database.
parent 39fc1940
......@@ -23,6 +23,7 @@
#include "skyobjects/skyobject.h"
#include "skycomponents/starcomponent.h"
#include "skycomponents/skymapcomposite.h"
#include "tools/nameresolver.h"
#include <KMessageBox>
......@@ -53,7 +54,8 @@ FindDialogUI::FindDialogUI( QWidget *parent ) : QFrame( parent ) {
FindDialog::FindDialog( QWidget* parent ) :
QDialog( parent ),
timer(0)
timer(0),
m_targetObject( 0 )
{
ui = new FindDialogUI( this );
......@@ -105,6 +107,7 @@ void FindDialog::init() {
filterByType();
sortModel->sort( 0 );
initSelection();
m_targetObject = 0;
}
void FindDialog::initSelection() {
......@@ -317,6 +320,21 @@ void FindDialog::slotOk() {
filterList();
}
selObj = selectedObject();
if( ! selObj ) {
// ==== FIXME: What follows is buggy testing code : please improve ====
// This code is expected to cause crashes / memory leaks
// because we don't commit the DSO data to the database, or
// any CatalogComponent.
CatalogEntryData cedata;
cedata = NameResolver::resolveName( processSearchText() );
DeepSkyObject *dso = new DeepSkyObject( cedata );
if( ! std::isnan( cedata.ra ) && ! std::isnan( cedata.dec ) ) {
qDebug() << dso->ra0().toHMSString() << ";" << dso->dec0().toDMSString();
selObj = dso;
}
// ==== END buggy testing code ====
}
m_targetObject = selObj;
if ( selObj == 0 ) {
QString message = i18n( "No object named %1 found.", ui->SearchBox->text() );
KMessageBox::sorry( 0, message, i18n( "Bad object name" ) );
......
......@@ -54,8 +54,12 @@ public:
/** Destructor */
virtual ~FindDialog();
/** @return the currently-selected item from the listbox of named objects */
SkyObject* selectedObject() const;
/**
* @return the target object (need not be the same as currently selected object!)
*
* @note Avoid using selectedObject()
*/
inline SkyObject *targetObject() { return m_targetObject; }
public slots:
/**When Text is entered in the QLineEdit, filter the List of objects
......@@ -90,6 +94,9 @@ protected:
*/
void keyPressEvent( QKeyEvent *e );
/** @return the currently-selected item from the listbox of named objects */
SkyObject* selectedObject() const;
private:
/** @short Do some post processing on the search text to interpret what the user meant
......@@ -108,6 +115,7 @@ private:
QTimer* timer;
bool listFiltered;
QPushButton *okB;
SkyObject *m_targetObject;
};
#endif
......@@ -271,7 +271,7 @@ void Scheduler::selectObject()
QPointer<FindDialog> fd = new FindDialog( this );
if ( fd->exec() == QDialog::Accepted )
{
SkyObject *object = fd->selectedObject();
SkyObject *object = fd->targetObject();
addObject(object);
}
......
......@@ -764,7 +764,7 @@ void KStars::slotFind() {
if ( !m_FindDialog ) qWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
SkyObject *targetObject;
if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->selectedObject() ) ) {
if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->targetObject() ) ) {
map()->setClickedObject( targetObject );
map()->setClickedPoint( map()->clickedObject() );
map()->slotCenter();
......
......@@ -403,7 +403,7 @@ void Execute::slotShowTargets() {
void Execute::slotAddObject() {
QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
if( o != 0 ) {
KStarsData::Instance()->observingList()->slotAddObject( o, true );
init();
......
......@@ -48,7 +48,7 @@ void PWizFovShUI::slotSelectFromList()
QPointer<FindDialog> findDlg( new FindDialog( this ) );
if(findDlg->exec() == QDialog::Accepted && findDlg)
{
SkyObject *obj = findDlg->selectedObject();
SkyObject *obj = findDlg->targetObject();
if(obj)
{
setBeginObject(obj);
......
......@@ -60,7 +60,7 @@ void PWizObjectSelectionUI::slotSelectFromList()
QPointer<FindDialog> findDlg( new FindDialog( this ) );
if(findDlg->exec() == QDialog::Accepted && findDlg)
{
SkyObject *obj = findDlg->selectedObject();
SkyObject *obj = findDlg->targetObject();
if(obj)
{
setSkyObject(obj);
......
......@@ -336,7 +336,7 @@ void AltVsTime::slotAddSource() {
void AltVsTime::slotBrowseObject() {
QPointer<FindDialog> fd = new FindDialog(this);
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
processObject( o );
}
delete fd;
......
......@@ -164,9 +164,9 @@ void ConjunctionsTool::slotFindObject() {
QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
if ( fd->exec() == QDialog::Accepted ) {
delete Object1;
if( !fd->selectedObject() )
if( !fd->targetObject() )
return;
Object1 = fd->selectedObject()->clone();
Object1 = fd->targetObject()->clone();
if( Object1 )
Obj1FindButton->setText( Object1->name() );
}
......
......@@ -87,7 +87,7 @@ void modCalcAltAz::slotObject()
{
FindDialog fd(KStars::Instance());
if ( fd.exec() == QDialog::Accepted ) {
SkyObject *o = fd.selectedObject();
SkyObject *o = fd.targetObject();
RA->showInHours( o->ra() );
Dec->showInDegrees( o->dec() );
slotCompute();
......
......@@ -96,7 +96,7 @@ void modCalcAngDist::slotValidatePositions(){
void modCalcAngDist::slotObjectButton() {
QPointer<FindDialog> fd = new FindDialog( this );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
if ( sender()->objectName() == QString("FirstObjectButton") ) {
FirstRA->showInHours( o->ra() );
FirstDec->showInDegrees( o->dec() );
......
......@@ -83,7 +83,7 @@ void modCalcApCoord::slotCompute(){
void modCalcApCoord::slotObject() {
QPointer<FindDialog> fd = new FindDialog( this );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
RACat->showInHours( o->ra0() );
DecCat->showInDegrees( o->dec0() );
EpochCat->setValue( 2000.0 );
......
......@@ -65,7 +65,7 @@ void modCalcEclCoords::slotNow() {
void modCalcEclCoords::slotObject() {
FindDialog fd(KStars::Instance());
if ( fd.exec() == QDialog::Accepted ) {
SkyObject *o = fd.selectedObject();
SkyObject *o = fd.targetObject();
RA->showInHours( o->ra() );
Dec->showInDegrees( o->dec() );
slotCompute();
......
......@@ -58,7 +58,7 @@ void modCalcGalCoord::slotObject()
{
QPointer<FindDialog> fd = new FindDialog( this );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
RA->showInHours( o->ra() );
Dec->showInDegrees( o->dec() );
slotComputeCoords();
......
......@@ -83,7 +83,7 @@ void modCalcVlsr::slotNow()
void modCalcVlsr::slotFindObject() {
QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
RA->showInHours( o->ra0() );
Dec->showInDegrees( o->dec0() );
}
......
......@@ -675,7 +675,7 @@ void ObservingList::slotAddToSession() {
void ObservingList::slotFind() {
QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
if ( fd->exec() == QDialog::Accepted ) {
SkyObject *o = fd->selectedObject();
SkyObject *o = fd->targetObject();
if( o != 0 ) {
slotAddObject( o, sessionView );
}
......
......@@ -1528,13 +1528,13 @@ void ScriptBuilder::slotFindCity() {
void ScriptBuilder::slotFindObject() {
QPointer<FindDialog> fd = new FindDialog( ks );
if ( fd->exec() == QDialog::Accepted && fd->selectedObject() ) {
if ( fd->exec() == QDialog::Accepted && fd->targetObject() ) {
setUnsavedChanges( true );
if (sender() == argLookToward->FindButton)
argLookToward->FocusEdit->setEditText( fd->selectedObject()->name() );
argLookToward->FocusEdit->setEditText( fd->targetObject()->name() );
else
argFindObject->NameEdit->setText(fd->selectedObject()->name());
argFindObject->NameEdit->setText(fd->targetObject()->name());
}
delete fd;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment