1 /***************************************************************************
2  *   Copyright (C) 2008 by Łukasz Jernaś   *
3  *   deejay1@srem.org   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef NAMEFINDERWIDGET_H
21 #define NAMEFINDERWIDGET_H
22 
23 #include <QWidget>
24 #include "httpquery.h"
25 #include <QBuffer>
26 #include "namefindertablemodel.h"
27 
28 namespace Ui {
29     class NameFinderWidgetUi;
30 }
31 
32 class QItemSelectionModel;
33 class QItemSelection;
34 
35 namespace NameFinder {
36 
37 
38     class NameFinderWidget : public QWidget {
39         Q_OBJECT
40         Q_DISABLE_COPY(NameFinderWidget)
41     public:
42                 explicit NameFinderWidget(QWidget *parent = 0);
43         virtual ~NameFinderWidget();
44         /**
45          * Executes the search
46          * @param object Specifies a feature to search for, can be
47          * any string which the service recognizes.
48          * WARNING: this widget currently
49          * doesn't do any data validation on it!
50          */
51         void search(QString object, QPointF coord);
52         //! Returns the coordinates of selected map feature
53         QPointF selectedCoords();
54         //! Returns the bbox of the selected map feature
55         QRectF selectedBbox();
56 
57     signals:
58         void selectionChanged();
59         void doubleClicked();
60         void done();
61 
62     protected:
63         virtual void changeEvent(QEvent *e);
64 
65 
66     private:
67         Ui::NameFinderWidgetUi *m_ui;
68 
69         HttpQuery *query;
70         NameFinderTableModel *model;
71         QList<NameFinderResult> *results;
72         QItemSelectionModel *selection;
73         QPointF theCenter;
74 
75 
76     private slots:
77         void display(QIODevice *reply);
78         void displayError(QNetworkReply::NetworkError);
79         void selection_selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
80         void doubleClick();
81     };
82 }
83 #endif // NAMEFINDERWIDGET_H
84