From cc9b6e077086d09cae2088efd21c54f7c1840a97 Mon Sep 17 00:00:00 2001 From: akashihi Date: Wed, 31 Mar 2010 11:52:01 +0000 Subject: [PATCH] Fix:gui/qml:Code rearrangement git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3108 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/Makefile.am | 4 +- navit/navit/gui/qml/bookmarksProxy.h | 168 ++++++++++ navit/navit/gui/qml/guiProxy.h | 164 ++++++++++ navit/navit/gui/qml/gui_qml.cpp | 617 +---------------------------------- navit/navit/gui/qml/navitProxy.h | 93 ++++++ navit/navit/gui/qml/searchProxy.h | 193 +++++++++++ navit/navit/gui/qml/vehicleProxy.h | 24 ++ 7 files changed, 649 insertions(+), 614 deletions(-) create mode 100644 navit/navit/gui/qml/bookmarksProxy.h create mode 100644 navit/navit/gui/qml/guiProxy.h create mode 100644 navit/navit/gui/qml/navitProxy.h create mode 100644 navit/navit/gui/qml/searchProxy.h create mode 100644 navit/navit/gui/qml/vehicleProxy.h diff --git a/navit/navit/gui/qml/Makefile.am b/navit/navit/gui/qml/Makefile.am index af2a56c..893cb5b 100644 --- a/navit/navit/gui/qml/Makefile.am +++ b/navit/navit/gui/qml/Makefile.am @@ -1,9 +1,9 @@ include $(top_srcdir)/Makefile.inc AM_CPPFLAGS = @QT_DECLARATIVE_CFLAGS@ @QT_GUI_CFLAGS@ @NAVIT_CFLAGS@ -I$(top_srcdir) -I$(top_srcdir)/navit -DMODULE=gui_qml modulegui_LTLIBRARIES = libgui_qml.la -libgui_qml_la_SOURCES = gui_qml.moc gui_qml.cpp proxy.moc proxy.h ngqpoint.moc ngqpoint.h +libgui_qml_la_SOURCES = proxy.moc proxy.h ngqpoint.moc ngqpoint.h searchProxy.moc searchProxy.h bookmarksProxy.moc bookmarksProxy.h vehicleProxy.moc vehicleProxy.h navitProxy.moc navitProxy.h guiProxy.moc guiProxy.h gui_qml.moc gui_qml.cpp libgui_qml_la_LDFLAGS = @QT_DECLARATIVE_LIBS@ @QT_GUI_LIBS@ -module -avoid-version -BUILT_SOURCES = gui_qml.moc proxy.moc ngqpoint.moc +BUILT_SOURCES = gui_qml.moc proxy.moc ngqpoint.moc searchProxy.moc bookmarksProxy.moc vehicleProxy.moc navitProxy.moc guiProxy.moc %.moc: %.h @MOC@ $(srcdir)/$< > $@ || touch $@ %.moc: %.cpp diff --git a/navit/navit/gui/qml/bookmarksProxy.h b/navit/navit/gui/qml/bookmarksProxy.h new file mode 100644 index 0000000..3e09826 --- /dev/null +++ b/navit/navit/gui/qml/bookmarksProxy.h @@ -0,0 +1,168 @@ +#ifndef NAVIT_GUI_QML_BOOKMARKSPROXY_H +#define NAVIT_GUI_QML_BOOKMARKSPROXY_H + +class NGQProxyBookmarks : public NGQProxy { + Q_OBJECT; + + + Q_PROPERTY(QString currentPath READ currentPath WRITE setCurrentPath); +public: + NGQProxyBookmarks(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; + +public slots: + QString currentPath() { + return this->current_path; + } + void setCurrentPath(QString currentPath) { + this->current_path=currentPath; + } + QString getAttrList(const QString &attr_name) { + NGQStandardItemModel* ret=new NGQStandardItemModel(this); + struct attr attr; + struct item* item; + struct map_rect *mr=NULL; + QHash seenMap; + + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL); + if (!mr) { + return QString(); + } + + if (!this->current_path.isEmpty()) { + QStandardItem* curItem=new QStandardItem(); + QStringList returnPath=this->current_path.split("/",QString::SkipEmptyParts); + + curItem->setData("..",NGQStandardItemModel::ItemName); + curItem->setData("yes",NGQStandardItemModel::ItemIcon); + + if (returnPath.size()>1) { + returnPath.removeLast(); + curItem->setData(returnPath.join("/"),NGQStandardItemModel::ItemPath); + } else { + //Fast way + curItem->setData(QString(),NGQStandardItemModel::ItemPath); + } + + ret->appendRow(curItem); + } + while ((item=map_rect_get_item(mr))) { + QStandardItem* curItem=new QStandardItem(); + QString label; + QStringList labelList; + + if (item->type != type_bookmark) continue; + if (!item_attr_get(item, attr_label, &attr)) continue; + //We need to treeize output + label=QString::fromLocal8Bit(attr.u.str); + curItem->setData(label,NGQStandardItemModel::ItemId); + if (!label.startsWith(this->current_path)) continue; + label=label.right(label.length()-this->current_path.length()); + labelList=label.split("/",QString::SkipEmptyParts); + if (seenMap[labelList[0]]==labelList[0]) continue; + seenMap[labelList[0]]=labelList[0]; + curItem->setData(labelList[0],NGQStandardItemModel::ItemName); + curItem->setData(QString(this->current_path).append(labelList[0]).append("/"),NGQStandardItemModel::ItemPath); + if (labelList.size()>1) { + curItem->setData("yes",NGQStandardItemModel::ItemIcon); + } else { + curItem->setData("no",NGQStandardItemModel::ItemIcon); + } + + ret->appendRow(curItem); + } + + this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); + + return QString(); + } + QString AddBookmark(QString description) { + struct attr attr; + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + if (!bookmarks_add_bookmark(attr.u.bookmarks, this->object->currentPoint->pc(), description.toLocal8Bit().constData()) ) { + return "Failed!"; + } else { + return "Success"; + } + } + QString Cut(QString description) { + struct attr attr; + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + if (!bookmarks_cut_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) { + return "Failed!"; + } else { + return "Success"; + } + } + QString Copy(QString description) { + struct attr attr; + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + if (!bookmarks_copy_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) { + return "Failed!"; + } else { + return "Success"; + } + } + QString Paste(QString location) { + struct attr attr; + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + if (!bookmarks_paste_bookmark(attr.u.bookmarks, location.toLocal8Bit().constData()) ) { + return "Failed!"; + } else { + return "Success"; + } + } + QString Delete(QString bookmark) { + struct attr attr; + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + if (!bookmarks_del_bookmark(attr.u.bookmarks, bookmark.toLocal8Bit().constData()) ) { + return "Failed!"; + } else { + return "Success"; + } + } + void setPoint(QString bookmark) { + struct attr attr; + struct item* item; + struct coord c; + struct map_rect *mr=NULL; + + navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); + mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL); + if (!mr) { + return; + } + + while ((item=map_rect_get_item(mr))) { + QString label; + + if (item->type != type_bookmark) continue; + if (!item_attr_get(item, attr_label, &attr)) continue; + + label=QString::fromLocal8Bit(attr.u.str); + dbg(0,"Bookmark is %s\n",bookmark.toStdString().c_str()); + if (label.compare(bookmark)) continue; + item_coord_get(item, &c, 1); + if (this->object->currentPoint!=NULL) { + delete this->object->currentPoint; + } + this->object->currentPoint=new NGQPoint(this->object,&c,bookmark,Bookmark,NULL); + this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); + } + + return; + } + +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return 0; } + int setAttrFunc(struct attr* attr) {return 0; } + struct attr_iter* getIterFunc() { return NULL; }; + void dropIterFunc(struct attr_iter* iter) { return; }; + +private: + QString current_path; +}; + +#include "bookmarksProxy.moc" + +#endif /* NAVIT_GUI_QML_BOOKMARKSPROXY_H */ diff --git a/navit/navit/gui/qml/guiProxy.h b/navit/navit/gui/qml/guiProxy.h new file mode 100644 index 0000000..1b51134 --- /dev/null +++ b/navit/navit/gui/qml/guiProxy.h @@ -0,0 +1,164 @@ +#ifndef NAVIT_GUI_QML_GUIPROXY_H +#define NAVIT_GUI_QML_GUIPROXY_H + +class NGQProxyGui : public NGQProxy { + Q_OBJECT; + + Q_PROPERTY(QString iconPath READ iconPath CONSTANT); + Q_PROPERTY(QString returnSource READ returnSource WRITE setReturnSource); + + Q_PROPERTY(QString commandFunction READ commandFunction CONSTANT); + + Q_PROPERTY(QString localeName READ localeName CONSTANT); + Q_PROPERTY(QString langName READ langName CONSTANT); + Q_PROPERTY(QString ctryName READ ctryName CONSTANT); + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false); + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false); + +public: + NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) { + this->source=QString(""); + } + + void setNewPoint(struct point* p,NGQPointTypes type) { + if (this->object->currentPoint!=NULL) { + delete this->object->currentPoint; + } + this->object->currentPoint = new NGQPoint(this->object,p,type,NULL); + this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); + } + void processCommand(QString function) { + this->function=function; + this->setPage("command.qml",true); + } +signals: + void widthSignal(int); + void heightSignal(int); +public slots: + void setPage(QString page,bool hidden=false) { + dbg(0,"Page is: %s\n",page.toStdString().c_str()); + this->source+="/"+page; + + //Reload widget + if (this->object->guiWidget) { + this->object->switcherWidget->removeWidget(this->object->guiWidget); + if (this->object->prevGuiWidget) { + delete this->object->prevGuiWidget; + } + this->object->prevGuiWidget=this->object->guiWidget; + } +#if QT_VERSION < 0x040700 + this->object->guiWidget = new QmlView(NULL); + this->object->guiWidget->setContentResizable(true); +#else + this->object->guiWidget = new QDeclarativeView(NULL); + this->object->guiWidget->setResizeMode(QDeclarativeView::SizeRootObjectToView); +#endif + + this->object->guiWidget->rootContext()->setContextProperty("gui",this->object->guiProxy); + this->object->guiWidget->rootContext()->setContextProperty("navit",this->object->navitProxy); + this->object->guiWidget->rootContext()->setContextProperty("vehicle",this->object->vehicleProxy); + this->object->guiWidget->rootContext()->setContextProperty("search",this->object->searchProxy); + this->object->guiWidget->rootContext()->setContextProperty("bookmarks",this->object->bookmarksProxy); + this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); + +#if QT_VERSION < 0x040700 + this->object->guiWidget->setUrl(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); + this->object->guiWidget->execute(); +#else + this->object->guiWidget->setSource(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); +#endif + if (!hidden) { + //we render commands page hidden, so the screen doesn't flicks. + this->object->guiWidget->show(); + this->object->switcherWidget->addWidget(this->object->guiWidget); + this->object->switcherWidget->setCurrentWidget(this->object->guiWidget); + } + } + void backToMap() { + if (this->object->graphicsWidget) { + this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason); + this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget); + this->object->graphicsWidget->show(); + } + } + void backToPrevPage() { + QStringList returnList=this->source.split(QString("/"), QString::SkipEmptyParts); + QString returnPage; + if (returnList.size()>1) { + returnList.takeLast();//Remove current element + returnPage=returnList.takeLast(); //Set previous element as return page and remove it from the list + } + this->source=returnList.join(QString("/")); + this->source.prepend(QString("/")); + this->setPage(returnPage); + } + + //Properties + QString iconPath() { + return QString(this->object->icon_src); + } + QString returnSource() { + return this->source; + } + void setReturnSource(QString returnSource) { + this->source=returnSource; + } + int width() { + return this->object->w; + } + void setWidth(int w) { + this->object->w=w; + this->widthSignal(w); + } + int height() { + return this->object->h; + } + void setHeight(int h) { + this->object->h=h; + this->heightSignal(h); + } + QString commandFunction() { + return this->function; + } + + //Locale properties + QString localeName() { + return QString()+"LANG="+getenv("LANG"); + } + QString langName() { +#ifdef HAVE_API_WIN32_BASE + wchar_t wstr[32]; + char str[32]; + + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wstr, sizeof(wstr)); + WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); + return QString()+"LOCALE_SABBREVLANGNAME="+str; +#else + return QString(); +#endif + } + QString ctryName() { +#ifdef HAVE_API_WIN32_BASE + wchar_t wstr[32]; + char str[32]; + + GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wstr, sizeof(wstr)); + WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); + return QString()+"LOCALE_SABBREVCTRYNAME="+str; +#else + return QString(); +#endif + } +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return gui_get_attr(this->object->gui, type, attr, iter); } + int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); } +private: + QString source; + QString function; +}; + +#include "guiProxy.moc" + +#endif /* NAVIT_GUI_QML_GUIPROXY_H */ diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 0930862..3ee5ef5 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -85,618 +85,11 @@ struct gui_priv { #include "proxy.h" #include "ngqpoint.h" - -//Proxy classes -class NGQProxySearch : public NGQProxy { - Q_OBJECT; - - Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal); - Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal); - Q_PROPERTY(QString townName READ townName WRITE setTownName NOTIFY townNameSignal); - - Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext); - -public: - NGQProxySearch(struct gui_priv* this_,QObject* parent) : NGQProxy(this_,parent) { - struct attr search_attr, country_name, country_iso2, *country_attr; - struct item *item; - struct country_search *cs; - struct tracking *tracking; - struct search_list_result *res; - - this->sl=search_list_new(navit_get_mapset(this->object->nav)); - this->search_context="country"; - this->town_name="Select a town"; - - country_attr=country_default(); - tracking=navit_get_tracking(this->object->nav); - if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL)) - country_attr=&search_attr; - if (country_attr) { - cs=country_search_new(country_attr, 0); - item=country_search_get_item(cs); - if (item && item_attr_get(item, attr_country_name, &country_name)) { - search_attr.type=attr_country_all; - dbg(0,"country %s\n", country_name.u.str); - this->country_name=QString::fromLocal8Bit(country_name.u.str); - search_attr.u.str=country_name.u.str; - search_list_search(this->sl, &search_attr, 0); - while((res=search_list_get_result(this->sl))); - if (item_attr_get(item, attr_country_iso2, &country_iso2)) { - this->country_iso2=QString::fromLocal8Bit(country_iso2.u.str); - } - } - country_search_destroy(cs); - } else { - dbg(0,"warning: no default country found\n"); - if (!this->country_iso2.isEmpty()) { - dbg(0,"attempting to use country '%s'\n",this->country_iso2.toStdString().c_str()); - search_attr.type=attr_country_iso2; - search_attr.u.str=(char*)this->country_iso2.toStdString().c_str(); - search_list_search(this->sl, &search_attr, 0); - while((res=search_list_get_result(this->sl))); - } - } - } - ~NGQProxySearch() { - search_list_destroy(this->sl); - } - -signals: - void countryNameSignal(QString); - void countryISO2Signal(QString); - void townNameSignal(QString); - -public slots: - QString getAttrList(const QString &attr_name) { - NGQStandardItemModel* ret=new NGQStandardItemModel(this); - struct attr attr; - struct search_list_result *res; - int counter=0; - QString currentValue, retId; - - if (this->search_context=="country") { - currentValue=this->country_name; - attr.type=attr_country_name; - attr.u.str=""; - } - if (this->search_context=="town") { - currentValue=this->town_name; - attr.type=attr_town_or_district_name; - attr.u.str=""; - } - if (this->search_context=="street") { - currentValue=this->street_name; - attr.type=attr_street_name; - attr.u.str=""; - } - - search_list_search(this->sl,&attr,1); - - while ((res=search_list_get_result(this->sl))) { - QStandardItem* curItem=new QStandardItem(); - //Result processing depends on search type - if (this->search_context=="country") { - curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); - curItem->setData(QString::fromLocal8Bit(res->country->name),NGQStandardItemModel::ItemName); - curItem->setData(QString("country_%1%2").arg(res->country->iso2).arg(".svgz"),NGQStandardItemModel::ItemIcon); - if (this->country_name==QString::fromLocal8Bit(res->country->name)) { - retId.setNum(counter); - } - } - if (this->search_context=="town") { - curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); - if (res->town->common.town_name) { - curItem->setData(QString::fromLocal8Bit(res->town->common.town_name),NGQStandardItemModel::ItemName); - } - if (res->town->common.district_name) { - curItem->setData(QString::fromLocal8Bit(res->town->common.district_name),NGQStandardItemModel::ItemName); - } - if (this->town_name==QString::fromLocal8Bit(res->town->common.town_name) || this->town_name==QString::fromLocal8Bit(res->town->common.district_name)) { - retId.setNum(counter); - } - } - if (this->search_context=="street") { - curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); - curItem->setData(QString::fromLocal8Bit(res->street->name),NGQStandardItemModel::ItemName); - if (this->street_name==QString::fromLocal8Bit(res->street->name)) { - retId.setNum(counter); - } - } - counter++; - ret->appendRow(curItem); - } - - this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); - - return retId; - } - QString countryName() { - return this->country_name; - } - void setCountryName(QString countryName) { - this->country_name=countryName; - struct attr attr; - struct search_list_result *res; - - //We need to update ISO2 - attr.type=attr_country_name; - attr.u.str=countryName.toLocal8Bit().data(); - search_list_search(this->sl,&attr,0); - while ((res=search_list_get_result(this->sl))) { - this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2)); - } - //...and current town - this->town_name="Select a town"; - - countryNameSignal(countryName); - } - QString countryISO2() { - return this->country_iso2; - } - void setCountryISO2(QString countryISO2) { - this->country_iso2=countryISO2; - countryISO2Signal(countryISO2); - } - QString townName() { - return this->town_name; - } - void setTownName(QString townName) { - struct attr attr; - struct search_list_result *res; - - this->town_name=townName; - - //Specialize search - attr.type=attr_town_or_district_name; - attr.u.str=townName.toLocal8Bit().data(); - search_list_search(this->sl,&attr,0); - - townNameSignal(townName); - } - QString searchContext() { - return this->search_context; - } - void setSearchContext(QString searchContext) { - this->search_context=searchContext; - } - -protected: - virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) { - return 0; - } - virtual int setAttrFunc(struct attr *attr) { - return 0; - } -private: - struct search_list *sl; - QString search_context; - QString country_iso2,country_name,town_name,street_name; -}; - -class NGQProxyBookmarks : public NGQProxy { - Q_OBJECT; - - - Q_PROPERTY(QString currentPath READ currentPath WRITE setCurrentPath); -public: - NGQProxyBookmarks(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; - -public slots: - QString currentPath() { - return this->current_path; - } - void setCurrentPath(QString currentPath) { - this->current_path=currentPath; - } - QString getAttrList(const QString &attr_name) { - NGQStandardItemModel* ret=new NGQStandardItemModel(this); - struct attr attr; - struct item* item; - struct map_rect *mr=NULL; - QHash seenMap; - - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL); - if (!mr) { - return QString(); - } - - if (!this->current_path.isEmpty()) { - QStandardItem* curItem=new QStandardItem(); - QStringList returnPath=this->current_path.split("/",QString::SkipEmptyParts); - - curItem->setData("..",NGQStandardItemModel::ItemName); - curItem->setData("yes",NGQStandardItemModel::ItemIcon); - - if (returnPath.size()>1) { - returnPath.removeLast(); - curItem->setData(returnPath.join("/"),NGQStandardItemModel::ItemPath); - } else { - //Fast way - curItem->setData(QString(),NGQStandardItemModel::ItemPath); - } - - ret->appendRow(curItem); - } - while ((item=map_rect_get_item(mr))) { - QStandardItem* curItem=new QStandardItem(); - QString label; - QStringList labelList; - - if (item->type != type_bookmark) continue; - if (!item_attr_get(item, attr_label, &attr)) continue; - //We need to treeize output - label=QString::fromLocal8Bit(attr.u.str); - curItem->setData(label,NGQStandardItemModel::ItemId); - if (!label.startsWith(this->current_path)) continue; - label=label.right(label.length()-this->current_path.length()); - labelList=label.split("/",QString::SkipEmptyParts); - if (seenMap[labelList[0]]==labelList[0]) continue; - seenMap[labelList[0]]=labelList[0]; - curItem->setData(labelList[0],NGQStandardItemModel::ItemName); - curItem->setData(QString(this->current_path).append(labelList[0]).append("/"),NGQStandardItemModel::ItemPath); - if (labelList.size()>1) { - curItem->setData("yes",NGQStandardItemModel::ItemIcon); - } else { - curItem->setData("no",NGQStandardItemModel::ItemIcon); - } - - ret->appendRow(curItem); - } - - this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); - - return QString(); - } - QString AddBookmark(QString description) { - struct attr attr; - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - if (!bookmarks_add_bookmark(attr.u.bookmarks, this->object->currentPoint->pc(), description.toLocal8Bit().constData()) ) { - return "Failed!"; - } else { - return "Success"; - } - } - QString Cut(QString description) { - struct attr attr; - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - if (!bookmarks_cut_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) { - return "Failed!"; - } else { - return "Success"; - } - } - QString Copy(QString description) { - struct attr attr; - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - if (!bookmarks_copy_bookmark(attr.u.bookmarks, description.toLocal8Bit().constData()) ) { - return "Failed!"; - } else { - return "Success"; - } - } - QString Paste(QString location) { - struct attr attr; - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - if (!bookmarks_paste_bookmark(attr.u.bookmarks, location.toLocal8Bit().constData()) ) { - return "Failed!"; - } else { - return "Success"; - } - } - QString Delete(QString bookmark) { - struct attr attr; - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - if (!bookmarks_del_bookmark(attr.u.bookmarks, bookmark.toLocal8Bit().constData()) ) { - return "Failed!"; - } else { - return "Success"; - } - } - void setPoint(QString bookmark) { - struct attr attr; - struct item* item; - struct coord c; - struct map_rect *mr=NULL; - - navit_get_attr(this->object->nav, attr_bookmarks, &attr, NULL); - mr=map_rect_new(bookmarks_get_map(attr.u.bookmarks), NULL); - if (!mr) { - return; - } - - while ((item=map_rect_get_item(mr))) { - QString label; - - if (item->type != type_bookmark) continue; - if (!item_attr_get(item, attr_label, &attr)) continue; - - label=QString::fromLocal8Bit(attr.u.str); - dbg(0,"Bookmark is %s\n",bookmark.toStdString().c_str()); - if (label.compare(bookmark)) continue; - item_coord_get(item, &c, 1); - if (this->object->currentPoint!=NULL) { - delete this->object->currentPoint; - } - this->object->currentPoint=new NGQPoint(this->object,&c,bookmark,Bookmark,NULL); - this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); - } - - return; - } - -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return 0; } - int setAttrFunc(struct attr* attr) {return 0; } - struct attr_iter* getIterFunc() { return NULL; }; - void dropIterFunc(struct attr_iter* iter) { return; }; - -private: - QString current_path; -}; -class NGQProxyVehicle : public NGQProxy { - Q_OBJECT; - -public: - NGQProxyVehicle(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; - -public slots: - -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return vehicle_get_attr(this->object->currVehicle, type, attr, iter); } - int setAttrFunc(struct attr* attr) {return vehicle_set_attr(this->object->currVehicle,attr); } - struct attr_iter* getIterFunc() { return vehicle_attr_iter_new(); }; - void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); }; - -private: - -}; - -class NGQProxyNavit : public NGQProxy { - Q_OBJECT; - -public: - NGQProxyNavit(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; - -public slots: - void quit() { - struct attr navit; - navit.type=attr_navit; - navit.u.navit=this->object->nav; - navit_destroy(navit.u.navit); - event_main_loop_quit(); - this->object->mainWindow->close(); - } - void setObjectByName(const QString& attr_name,const QString& attr_value) { - if (attr_name=="layout") { - navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str()); - } - if (attr_name=="vehicle") { - navit_set_vehicle_by_name(this->object->nav,attr_value.toStdString().c_str()); - } - return; - } - QString getAttrList(const QString &attr_name) { - NGQStandardItemModel* ret=new NGQStandardItemModel(this); - struct attr attr; - struct attr_iter *iter; - int counter=0; - QString currentValue, retId; - - //Find current value - getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ; - if (attr.type==attr_layout) { - currentValue=attr.u.layout->name; - } - - //Fill da list - iter=getIterFunc(); - if (iter == NULL) { - return retId; - } - - while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) { - QStandardItem* curItem=new QStandardItem(); - //Listed attributes are usualy have very complex structure - if (attr.type==attr_layout) { - curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); - curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName); - if (currentValue==attr.u.layout->name) { - retId.setNum(counter); - } - } - if (attr.type==attr_vehicle) { - this->object->currVehicle=attr.u.vehicle; - curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); - curItem->setData(QVariant(this->object->vehicleProxy->getAttr("name")),NGQStandardItemModel::ItemName); - retId.setNum(0); - } - counter++; - ret->appendRow(curItem); - } - - dropIterFunc(iter); - - this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); - - dbg(0,"retId %s \n",retId.toStdString().c_str()); - - return retId; - } - void setDestination() { - navit_set_destination(this->object->nav,this->object->currentPoint->pc(),this->object->currentPoint->coordString().toStdString().c_str(),1); - } - void setPosition() { - navit_set_position(this->object->nav,this->object->currentPoint->pc()); - } -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); } - int setAttrFunc(struct attr* attr) {return navit_set_attr(this->object->nav,attr); } - struct attr_iter* getIterFunc() { return navit_attr_iter_new(); }; - void dropIterFunc(struct attr_iter* iter) { navit_attr_iter_destroy(iter); }; - -private: - -}; - -class NGQProxyGui : public NGQProxy { - Q_OBJECT; - - Q_PROPERTY(QString iconPath READ iconPath CONSTANT); - Q_PROPERTY(QString returnSource READ returnSource WRITE setReturnSource); - - Q_PROPERTY(QString commandFunction READ commandFunction CONSTANT); - - Q_PROPERTY(QString localeName READ localeName CONSTANT); - Q_PROPERTY(QString langName READ langName CONSTANT); - Q_PROPERTY(QString ctryName READ ctryName CONSTANT); - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthSignal STORED false); - Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightSignal STORED false); - -public: - NGQProxyGui(struct gui_priv* this_,QObject *parent) : NGQProxy(this_, parent) { - this->source=QString(""); - } - - void setNewPoint(struct point* p,NGQPointTypes type) { - if (this->object->currentPoint!=NULL) { - delete this->object->currentPoint; - } - this->object->currentPoint = new NGQPoint(this->object,p,type,NULL); - this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); - } - void processCommand(QString function) { - this->function=function; - this->setPage("command.qml",true); - } -signals: - void widthSignal(int); - void heightSignal(int); -public slots: - void setPage(QString page,bool hidden=false) { - dbg(0,"Page is: %s\n",page.toStdString().c_str()); - this->source+="/"+page; - - //Reload widget - if (this->object->guiWidget) { - this->object->switcherWidget->removeWidget(this->object->guiWidget); - if (this->object->prevGuiWidget) { - delete this->object->prevGuiWidget; - } - this->object->prevGuiWidget=this->object->guiWidget; - } -#if QT_VERSION < 0x040700 - this->object->guiWidget = new QmlView(NULL); - this->object->guiWidget->setContentResizable(true); -#else - this->object->guiWidget = new QDeclarativeView(NULL); - this->object->guiWidget->setResizeMode(QDeclarativeView::SizeRootObjectToView); -#endif - - this->object->guiWidget->rootContext()->setContextProperty("gui",this->object->guiProxy); - this->object->guiWidget->rootContext()->setContextProperty("navit",this->object->navitProxy); - this->object->guiWidget->rootContext()->setContextProperty("vehicle",this->object->vehicleProxy); - this->object->guiWidget->rootContext()->setContextProperty("search",this->object->searchProxy); - this->object->guiWidget->rootContext()->setContextProperty("bookmarks",this->object->bookmarksProxy); - this->object->guiWidget->rootContext()->setContextProperty("point",this->object->currentPoint); - -#if QT_VERSION < 0x040700 - this->object->guiWidget->setUrl(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); - this->object->guiWidget->execute(); -#else - this->object->guiWidget->setSource(QUrl::fromLocalFile(QString(this->object->source)+"/"+this->object->skin+"/"+page)); -#endif - if (!hidden) { - //we render commands page hidden, so the screen doesn't flicks. - this->object->guiWidget->show(); - this->object->switcherWidget->addWidget(this->object->guiWidget); - this->object->switcherWidget->setCurrentWidget(this->object->guiWidget); - } - } - void backToMap() { - if (this->object->graphicsWidget) { - this->object->graphicsWidget->setFocus(Qt::ActiveWindowFocusReason); - this->object->switcherWidget->setCurrentWidget(this->object->graphicsWidget); - this->object->graphicsWidget->show(); - } - } - void backToPrevPage() { - QStringList returnList=this->source.split(QString("/"), QString::SkipEmptyParts); - QString returnPage; - if (returnList.size()>1) { - returnList.takeLast();//Remove current element - returnPage=returnList.takeLast(); //Set previous element as return page and remove it from the list - } - this->source=returnList.join(QString("/")); - this->source.prepend(QString("/")); - this->setPage(returnPage); - } - - //Properties - QString iconPath() { - return QString(this->object->icon_src); - } - QString returnSource() { - return this->source; - } - void setReturnSource(QString returnSource) { - this->source=returnSource; - } - int width() { - return this->object->w; - } - void setWidth(int w) { - this->object->w=w; - this->widthSignal(w); - } - int height() { - return this->object->h; - } - void setHeight(int h) { - this->object->h=h; - this->heightSignal(h); - } - QString commandFunction() { - return this->function; - } - - //Locale properties - QString localeName() { - return QString()+"LANG="+getenv("LANG"); - } - QString langName() { -#ifdef HAVE_API_WIN32_BASE - wchar_t wstr[32]; - char str[32]; - - GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, wstr, sizeof(wstr)); - WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); - return QString()+"LOCALE_SABBREVLANGNAME="+str; -#else - return QString(); -#endif - } - QString ctryName() { -#ifdef HAVE_API_WIN32_BASE - wchar_t wstr[32]; - char str[32]; - - GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, wstr, sizeof(wstr)); - WideCharToMultiByte(CP_ACP,0,wstr,-1,str,sizeof(str),NULL,NULL); - return QString()+"LOCALE_SABBREVCTRYNAME="+str; -#else - return QString(); -#endif - } -protected: - int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return gui_get_attr(this->object->gui, type, attr, iter); } - int setAttrFunc(struct attr* attr) {return gui_set_attr(this->object->gui,attr); } -private: - QString source; - QString function; -}; +#include "searchProxy.h" +#include "bookmarksProxy.h" +#include "vehicleProxy.h" +#include "navitProxy.h" +#include "guiProxy.h" //Main window class for resizeEvent handling class NGQMainWindow : public QMainWindow { diff --git a/navit/navit/gui/qml/navitProxy.h b/navit/navit/gui/qml/navitProxy.h new file mode 100644 index 0000000..20787c7 --- /dev/null +++ b/navit/navit/gui/qml/navitProxy.h @@ -0,0 +1,93 @@ +#ifndef NAVIT_GUI_QML_NAVIT_H +#define NAVIT_GUI_QML_NAVIT_H + +class NGQProxyNavit : public NGQProxy { + Q_OBJECT; + +public: + NGQProxyNavit(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; + +public slots: + void quit() { + struct attr navit; + navit.type=attr_navit; + navit.u.navit=this->object->nav; + navit_destroy(navit.u.navit); + event_main_loop_quit(); + this->object->mainWindow->close(); + } + void setObjectByName(const QString& attr_name,const QString& attr_value) { + if (attr_name=="layout") { + navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str()); + } + if (attr_name=="vehicle") { + navit_set_vehicle_by_name(this->object->nav,attr_value.toStdString().c_str()); + } + return; + } + QString getAttrList(const QString &attr_name) { + NGQStandardItemModel* ret=new NGQStandardItemModel(this); + struct attr attr; + struct attr_iter *iter; + int counter=0; + QString currentValue, retId; + + //Find current value + getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ; + if (attr.type==attr_layout) { + currentValue=attr.u.layout->name; + } + + //Fill da list + iter=getIterFunc(); + if (iter == NULL) { + return retId; + } + + while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) { + QStandardItem* curItem=new QStandardItem(); + //Listed attributes are usualy have very complex structure + if (attr.type==attr_layout) { + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName); + if (currentValue==attr.u.layout->name) { + retId.setNum(counter); + } + } + if (attr.type==attr_vehicle) { + this->object->currVehicle=attr.u.vehicle; + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + curItem->setData(QVariant(this->object->vehicleProxy->getAttr("name")),NGQStandardItemModel::ItemName); + retId.setNum(0); + } + counter++; + ret->appendRow(curItem); + } + + dropIterFunc(iter); + + this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); + + dbg(0,"retId %s \n",retId.toStdString().c_str()); + + return retId; + } + void setDestination() { + navit_set_destination(this->object->nav,this->object->currentPoint->pc(),this->object->currentPoint->coordString().toStdString().c_str(),1); + } + void setPosition() { + navit_set_position(this->object->nav,this->object->currentPoint->pc()); + } +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); } + int setAttrFunc(struct attr* attr) {return navit_set_attr(this->object->nav,attr); } + struct attr_iter* getIterFunc() { return navit_attr_iter_new(); }; + void dropIterFunc(struct attr_iter* iter) { navit_attr_iter_destroy(iter); }; + +private: + +}; + +#include "navitProxy.moc" + +#endif /* NAVIT_GUI_QML_NAVITPROXY_H */ diff --git a/navit/navit/gui/qml/searchProxy.h b/navit/navit/gui/qml/searchProxy.h new file mode 100644 index 0000000..b82004d --- /dev/null +++ b/navit/navit/gui/qml/searchProxy.h @@ -0,0 +1,193 @@ +#ifndef NAVIT_GUI_QML_SEARCHPROXY_H +#define NAVIT_GUI_QML_SEARCHPROXY_H + +class NGQProxySearch : public NGQProxy { + Q_OBJECT; + + Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal); + Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal); + Q_PROPERTY(QString townName READ townName WRITE setTownName NOTIFY townNameSignal); + + Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext); + +public: + NGQProxySearch(struct gui_priv* this_,QObject* parent) : NGQProxy(this_,parent) { + struct attr search_attr, country_name, country_iso2, *country_attr; + struct item *item; + struct country_search *cs; + struct tracking *tracking; + struct search_list_result *res; + + this->sl=search_list_new(navit_get_mapset(this->object->nav)); + this->search_context="country"; + this->town_name="Select a town"; + + country_attr=country_default(); + tracking=navit_get_tracking(this->object->nav); + if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL)) + country_attr=&search_attr; + if (country_attr) { + cs=country_search_new(country_attr, 0); + item=country_search_get_item(cs); + if (item && item_attr_get(item, attr_country_name, &country_name)) { + search_attr.type=attr_country_all; + dbg(0,"country %s\n", country_name.u.str); + this->country_name=QString::fromLocal8Bit(country_name.u.str); + search_attr.u.str=country_name.u.str; + search_list_search(this->sl, &search_attr, 0); + while((res=search_list_get_result(this->sl))); + if (item_attr_get(item, attr_country_iso2, &country_iso2)) { + this->country_iso2=QString::fromLocal8Bit(country_iso2.u.str); + } + } + country_search_destroy(cs); + } else { + dbg(0,"warning: no default country found\n"); + if (!this->country_iso2.isEmpty()) { + dbg(0,"attempting to use country '%s'\n",this->country_iso2.toStdString().c_str()); + search_attr.type=attr_country_iso2; + search_attr.u.str=(char*)this->country_iso2.toStdString().c_str(); + search_list_search(this->sl, &search_attr, 0); + while((res=search_list_get_result(this->sl))); + } + } + } + ~NGQProxySearch() { + search_list_destroy(this->sl); + } + +signals: + void countryNameSignal(QString); + void countryISO2Signal(QString); + void townNameSignal(QString); + +public slots: + QString getAttrList(const QString &attr_name) { + NGQStandardItemModel* ret=new NGQStandardItemModel(this); + struct attr attr; + struct search_list_result *res; + int counter=0; + QString currentValue, retId; + + if (this->search_context=="country") { + currentValue=this->country_name; + attr.type=attr_country_name; + attr.u.str=""; + } + if (this->search_context=="town") { + currentValue=this->town_name; + attr.type=attr_town_or_district_name; + attr.u.str=""; + } + if (this->search_context=="street") { + currentValue=this->street_name; + attr.type=attr_street_name; + attr.u.str=""; + } + + search_list_search(this->sl,&attr,1); + + while ((res=search_list_get_result(this->sl))) { + QStandardItem* curItem=new QStandardItem(); + //Result processing depends on search type + if (this->search_context=="country") { + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + curItem->setData(QString::fromLocal8Bit(res->country->name),NGQStandardItemModel::ItemName); + curItem->setData(QString("country_%1%2").arg(res->country->iso2).arg(".svgz"),NGQStandardItemModel::ItemIcon); + if (this->country_name==QString::fromLocal8Bit(res->country->name)) { + retId.setNum(counter); + } + } + if (this->search_context=="town") { + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + if (res->town->common.town_name) { + curItem->setData(QString::fromLocal8Bit(res->town->common.town_name),NGQStandardItemModel::ItemName); + } + if (res->town->common.district_name) { + curItem->setData(QString::fromLocal8Bit(res->town->common.district_name),NGQStandardItemModel::ItemName); + } + if (this->town_name==QString::fromLocal8Bit(res->town->common.town_name) || this->town_name==QString::fromLocal8Bit(res->town->common.district_name)) { + retId.setNum(counter); + } + } + if (this->search_context=="street") { + curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId); + curItem->setData(QString::fromLocal8Bit(res->street->name),NGQStandardItemModel::ItemName); + if (this->street_name==QString::fromLocal8Bit(res->street->name)) { + retId.setNum(counter); + } + } + counter++; + ret->appendRow(curItem); + } + + this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast(ret)); + + return retId; + } + QString countryName() { + return this->country_name; + } + void setCountryName(QString countryName) { + this->country_name=countryName; + struct attr attr; + struct search_list_result *res; + + //We need to update ISO2 + attr.type=attr_country_name; + attr.u.str=countryName.toLocal8Bit().data(); + search_list_search(this->sl,&attr,0); + while ((res=search_list_get_result(this->sl))) { + this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2)); + } + //...and current town + this->town_name="Select a town"; + + countryNameSignal(countryName); + } + QString countryISO2() { + return this->country_iso2; + } + void setCountryISO2(QString countryISO2) { + this->country_iso2=countryISO2; + countryISO2Signal(countryISO2); + } + QString townName() { + return this->town_name; + } + void setTownName(QString townName) { + struct attr attr; + struct search_list_result *res; + + this->town_name=townName; + + //Specialize search + attr.type=attr_town_or_district_name; + attr.u.str=townName.toLocal8Bit().data(); + search_list_search(this->sl,&attr,0); + + townNameSignal(townName); + } + QString searchContext() { + return this->search_context; + } + void setSearchContext(QString searchContext) { + this->search_context=searchContext; + } + +protected: + virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) { + return 0; + } + virtual int setAttrFunc(struct attr *attr) { + return 0; + } +private: + struct search_list *sl; + QString search_context; + QString country_iso2,country_name,town_name,street_name; +}; + +#include "searchProxy.moc" + +#endif /* NAVIT_GUI_QML_SEARCHPROXY_H */ diff --git a/navit/navit/gui/qml/vehicleProxy.h b/navit/navit/gui/qml/vehicleProxy.h new file mode 100644 index 0000000..483a183 --- /dev/null +++ b/navit/navit/gui/qml/vehicleProxy.h @@ -0,0 +1,24 @@ +#ifndef NAVIT_GUI_QML_VEHICLEPROXY_H +#define NAVIT_GUI_QML_VEHICLEPROXY_H + +class NGQProxyVehicle : public NGQProxy { + Q_OBJECT; + +public: + NGQProxyVehicle(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { }; + +public slots: + +protected: + int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return vehicle_get_attr(this->object->currVehicle, type, attr, iter); } + int setAttrFunc(struct attr* attr) {return vehicle_set_attr(this->object->currVehicle,attr); } + struct attr_iter* getIterFunc() { return vehicle_attr_iter_new(); }; + void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); }; + +private: + +}; + +#include "vehicleProxy.moc" + +#endif /* NAVIT_GUI_QML_VEHICLEPROXY_H */ -- 2.7.4