From b7e6b7f02e7cf19bf71e99accfcd53042401732e Mon Sep 17 00:00:00 2001 From: Max Lapan Date: Sun, 7 Mar 2010 20:47:26 +0300 Subject: [PATCH 1/1] Implemented table of regions. It is not complete so far (it lacks save/load and refresh code), but it already has tests. --- main.cpp | 2 +- regions.cpp | 31 +++++++++++++++++++++++++++++++ regions.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ tests/regions/main.cpp | 20 ++++++++++++++++++++ tests/regions/regions.pro | 5 +++++ tests/tests.pro | 2 ++ yandex-traffic-core.pri | 4 ++++ yandex-traffic-widget.pro | 2 ++ 8 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 regions.cpp create mode 100644 regions.hpp create mode 100644 tests/regions/main.cpp create mode 100644 tests/regions/regions.pro create mode 100644 tests/tests.pro create mode 100644 yandex-traffic-core.pri diff --git a/main.cpp b/main.cpp index 075f0f7..c3e31ae 100644 --- a/main.cpp +++ b/main.cpp @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor (&w); adaptor->setSettingsAvailable (true); - + w.show (); return app.exec (); diff --git a/regions.cpp b/regions.cpp new file mode 100644 index 0000000..9a2c1bc --- /dev/null +++ b/regions.cpp @@ -0,0 +1,31 @@ +#include + +#include "regions.hpp" + + +RegionsTable::RegionsTable () +{ + // Load saved table, if failed, initialize default table of regions + makeDefaultTable (); +} + + +void RegionsTable::makeDefaultTable () +{ + _map.clear (); + _map.insert ("1", RegionInfo ("1", "Moscow")); + _map.insert ("10174", RegionInfo ("10174", "St. Petersburg")); + _map.insert ("20544", RegionInfo ("20544", "Kiev")); + _map.insert ("11162", RegionInfo ("11162", "Ekaterinburg")); +} + + +const RegionInfo *RegionsTable::lookup (const QString &id) const +{ + QMap::const_iterator it = _map.find (id); + + if (it == _map.end ()) + return NULL; + else + return &*it; +} diff --git a/regions.hpp b/regions.hpp new file mode 100644 index 0000000..0c3c6b5 --- /dev/null +++ b/regions.hpp @@ -0,0 +1,41 @@ +#ifndef __REGIONS_H__ +#define __REGIONS_H__ + +#include + + +class RegionInfo +{ +private: + QString _id; + QString _name; + +public: + RegionInfo (const QString &id, const QString &name) + : _id (id), + _name (name) + {}; + + QString id () const + { return _id; }; + + QString name () const + { return _name; }; +}; + + +// Map between region ID and it's information +class RegionsTable +{ +private: + QMap _map; + + void makeDefaultTable (); + +public: + RegionsTable (); + + const RegionInfo *lookup (const QString &id) const; +}; + +#endif // __REGIONS_H__ diff --git a/tests/regions/main.cpp b/tests/regions/main.cpp new file mode 100644 index 0000000..a2f6fdc --- /dev/null +++ b/tests/regions/main.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include + + +int main() +{ + RegionsTable table; + const RegionInfo *ri; + + ri = table.lookup ("1"); + if (ri) + printf ("Region 1 is %s\n", ri->name ().toUtf8 ().constData ()); + else + printf ("Region 1 is not found\n"); + + return 0; +} + diff --git a/tests/regions/regions.pro b/tests/regions/regions.pro new file mode 100644 index 0000000..104a01c --- /dev/null +++ b/tests/regions/regions.pro @@ -0,0 +1,5 @@ +TEMPLATE = app + +SOURCES += main.cpp + +include (../../yandex-traffic-core.pri) diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..cfcadce --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = regions diff --git a/yandex-traffic-core.pri b/yandex-traffic-core.pri new file mode 100644 index 0000000..d7d6021 --- /dev/null +++ b/yandex-traffic-core.pri @@ -0,0 +1,4 @@ +HEADERS += $$PWD/regions.hpp +SOURCES += $$PWD/regions.cpp + +INCLUDEPATH += $$PWD \ No newline at end of file diff --git a/yandex-traffic-widget.pro b/yandex-traffic-widget.pro index 9a239ea..1ac06e4 100644 --- a/yandex-traffic-widget.pro +++ b/yandex-traffic-widget.pro @@ -6,6 +6,8 @@ HEADERS += qmaemo5homescreenadaptor.h SOURCES += main.cpp HEADERS += mainwidget.hpp +include (ynadex-traffic-core.pri) + desktop.path = /usr/share/applications/hildon-home desktop.files = yandex-traffic-widget.desktop -- 1.7.9.5