<file_sep>#ifndef WEATHERWIDGET_H
#define WEATHERWIDGET_H

#include <QWidget>
#include <QUrl>
#include "downloader.h"
#include <QProgressBar>
#include <QLineEdit>
#include <QPushButton>
#include <QByteArray>
#include <QTextEdit>
#include <QString>
#include "picojson.h"
#include <QMap>
#include "logger.h"

namespace Ui {
    class Form;
}

class WeatherWidget : public QWidget
{
    Q_OBJECT
private:
    Ui::Form*       ui;
    Downloader*     pdl_;
    Downloader*     pdlImg_;

    QString urlRoot_;
    QString weatherQuery_;
    QString weatherImgQuery_;
    QString imgExtention_;
    const QString APPID_;
    typedef QMap<QString, QByteArray> ImgCache;
    ImgCache    cache_;
private:
    void JSONParseAndFill(picojson::value::object& obj);
    void JSONParseAndFill(picojson::value::array& obj);
    void displayError(const QString& title, const QString& message);
    void setText(const QString& widgetName, const QString& value);
    void downloadImg(const QString& imgName);
    const QByteArray* checkCache(const QString& key);
public:
    explicit WeatherWidget(QWidget *parent = 0);
    ~WeatherWidget();

    void connectLogger(const Logger& logger);
public slots:
    void slotGo         (const QString&);
    void slotClearFroms ();
private slots:
    void slotError      ();
    void slotDone       (const QUrl&, const QByteArray&);
    void slotImgDone    (const QUrl&, const QByteArray&);
    void slotResetToDefault (bool);
    void slotError          (QString errStatus);
};

#endif // WEATHERWIDGET_H
<file_sep>#ifndef DOWNLOADER_H
#define DOWNLOADER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>

class Downloader : public QObject
{
    Q_OBJECT
private:
    QNetworkAccessManager*  pnam_;

    QString getStringError(QNetworkReply::NetworkError);
public:
    explicit Downloader(QObject *parent = 0);

    void download(const QUrl&);
signals:
    void done(const QUrl&, const QByteArray&);
    void error(const QString);

private slots:
    void slotFinished(QNetworkReply*);
};

#endif // DOWNLOADER_H
<file_sep>#include "downloader.h"
#include <QNetworkRequest>

QString Downloader::getStringError(QNetworkReply::NetworkError err)
{
    QString error;

    switch (err) {
    case QNetworkReply::ConnectionRefusedError: error = "the remote server refused the connection (the server is not accepting requests)"; break;
    case QNetworkReply::RemoteHostClosedError: error = "the remote server closed the connection prematurely, before the entire reply was received and processed"; break;
    case QNetworkReply::HostNotFoundError: error = "the remote host name was not found (invalid hostname)"; break;
    case QNetworkReply::TimeoutError: error = "the connection to the remote server timed out"; break;
    case QNetworkReply::OperationCanceledError: error = "the operation was canceled via calls to abort() or close() before it was finished"; break;
    case QNetworkReply::SslHandshakeFailedError: error = "the SSL/TLS handshake failed and the encrypted channel could not be established. The sslErrors() signal should have been emitted"; break;
    case QNetworkReply::TemporaryNetworkFailureError: error = "the connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established."; break;
    case QNetworkReply::ProxyConnectionRefusedError: error = "the connection to the proxy server was refused (the proxy server is not accepting requests)"; break;
    case QNetworkReply::ProxyConnectionClosedError: error = "the proxy server closed the connection prematurely, before the entire reply was received and processed"; break;
    case QNetworkReply::ProxyNotFoundError: error = "the proxy host name was not found (invalid proxy hostname)"; break;
    case QNetworkReply::ProxyTimeoutError: error = "the connection to the proxy timed out or the proxy did not reply in time to the request sent"; break;
    case QNetworkReply::ProxyAuthenticationRequiredError: error = "the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any)"; break;
    case QNetworkReply::ContentAccessDenied: error = "the access to the remote content was denied (similar to HTTP error 401)"; break;
    case QNetworkReply::ContentOperationNotPermittedError: error = "the operation requested on the remote content is not permitted"; break;
    case QNetworkReply::ContentNotFoundError: error = "the remote content was not found at the server (similar to HTTP error 404)"; break;
    case QNetworkReply::AuthenticationRequiredError: error = "the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)"; break;
    case QNetworkReply::ContentReSendError: error = "the request needed to be sent again, but this failed for example because the upload data could not be read a second time."; break;
    case QNetworkReply::ProtocolUnknownError: error = "the Network Access API cannot honor the request because the protocol is not known"; break;
    case QNetworkReply::ProtocolInvalidOperationError: error = "the requested operation is invalid for this protocol"; break;
    case QNetworkReply::UnknownNetworkError: error = "an unknown network-related error was detected"; break;
    case QNetworkReply::UnknownProxyError: error = "an unknown proxy-related error was detected"; break;
    case QNetworkReply::UnknownContentError: error = "an unknown error related to the remote content was detected"; break;
    case QNetworkReply::ProtocolFailure: error = "a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.)"; break;
    default:
        error = "unkown error occured";
        break;
    }

    return error;
}

Downloader::Downloader(QObject *parent) :
    QObject(parent)
{
    pnam_ = new QNetworkAccessManager(this);
    connect(pnam_, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(slotFinished(QNetworkReply*))
            );
}

void Downloader::download(const QUrl & url)
{
    QNetworkRequest request(url);

    QNetworkReply* reply = pnam_->get(request);
}

void Downloader::slotFinished(QNetworkReply *reply)
{
    if(reply->error() != QNetworkReply::NoError){
        emit error(getStringError(reply->error()));
    } else {
        emit done(reply->url(), reply->readAll());
    }
    reply->deleteLater();
}
<file_sep>#ifndef DATA_H
#define DATA_H
#include <memory>
#include <QString>
#include <QByteArray>
#include <iostream>

class City;
class Coord
{
    friend class City;
public:
    Coord(double lon, double lat) : lon_(lon), lat_(lat){}

    double lon() const;
    double lat() const;
private:
    double lon_;
    double lat_;
    Coord() : lon_(0), lat_(0){}
};

class City {
public:
    static std::shared_ptr<City> makeCity(const QByteArray& JSONRaw);

    City(unsigned int id, const QString& name, const QString& country, const Coord& coord);

    unsigned id() const;
    const QString& name() const;
    const QString& country() const;
    const Coord& coord() const;
private:
    unsigned int    id_;
    QString         name_;
    QString         country_;
    Coord           coord_;

    static City* hardCodeParse(const QByteArray& JSONRaw);
    City();
};

class Data
{
public:
    Data();
};

#endif // DATA_H


std::ostream &operator<<(std::ostream& out, const City& city);


<file_sep>#include "data.h"
#include <iomanip>
#include <QDebug>
#include <QByteArray>
#include <cassert>

Data::Data()
{
}

double Coord::lon() const
{
    return lon_;
}

double Coord::lat() const
{
    return lat_;
}


std::shared_ptr<City> City::makeCity(const QByteArray& JSONRaw)
{
    City* p = hardCodeParse(JSONRaw);
    if (!p) {
        return std::shared_ptr<City>();
    }

    return std::shared_ptr<City>(p);
}

City::City(unsigned int id, const QString& name, const QString& country, const Coord& coord) :
    id_(id),
    name_(name),
    country_(country),
    coord_(coord)
{
}

unsigned City::id() const
{
    return id_;
}

const QString &City::name() const
{
    return  name_;
}

const QString &City::country() const
{
    return country_;
}

const Coord &City::coord() const
{
    return coord_;
}

City *City::hardCodeParse(const QByteArray& JSONRaw)
{ //TODO    negative lon lat to implement
    City* newCity = new City;
    newCity->id_= 0;
    const char* curr = JSONRaw.data();
    unsigned char divide_counter = 0;
    static double pow_10[] = { 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0 };
    QByteArray cityName;
    QByteArray countryName;


    enum STATES {
        start,
        first_colon,
        first_colon_comma,
        second_colon,
        second_colon_open_quote,
        second_colon_close_quote,
        third_colon,
        third_colon_open_quote,
        third_colon_close_quote,
        forth_colon,
        fifth_colon,
        fifth_colon_dot,
        fifth_colon_comma,
        sixth_colon,
        sixth_colon_dot,
        sixth_colon_right_bracket,
        enough
    };

    STATES state = start;
    while (*curr) {
        char ch = *curr;

        switch (state) {
        case start:
            if ( ch == ':' ) {
                state = first_colon;
            }
            break;
        case first_colon:
            if ( ch == ',' ) {
                state = first_colon_comma;
            } else {
                if ( ch >= '0' && ch <= '9' ){
                    newCity->id_ =  newCity->id_ *10 +(ch - '0');
                } else {
                    return nullptr;
                }
            }
            break;
        case first_colon_comma:
            if ( ch == ':' ) {
                state = second_colon;
            }
            break;
        case second_colon:
            if ( ch == '\"' ) {
               state = second_colon_open_quote;
            }
            break;
        case second_colon_open_quote:
            if ( ch == '\"' ){
                state = second_colon_close_quote;
            } else {
                cityName.append(ch);
            }
            break;
        case second_colon_close_quote:
            if ( ch == ':' ) {
                state = third_colon;
            }
            break;
        case third_colon:
            if ( ch == '\"' ) {
               state = third_colon_open_quote;
            }
            break;
        case third_colon_open_quote:
            if ( ch == '\"' ){
                state = third_colon_close_quote;
            } else {
                countryName.append(ch);
            }
            break;
        case third_colon_close_quote:
            if ( ch == ':' ) {
                state = forth_colon;
            }
            break;
        case forth_colon:
            if ( ch == ':' ) {
                state = fifth_colon;
            }
            break;
        case fifth_colon:
            if ( ch == '.' ) {
                state = fifth_colon_dot;
            } else if ( ch >= '0' && ch <= '9' ) {
                newCity->coord_.lon_ = newCity->coord_.lon_*10 +(ch - '0');
            } else {
                return nullptr;
            }
            break;
        case fifth_colon_dot:
            if ( ch == ',' ) {
                state = fifth_colon_comma;
                divide_counter = 0;
            } else if ( ch >= '0' && ch <= '9' ) {
                newCity->coord_.lon_ += (ch - '0') / pow_10[divide_counter++];
            } else {
                return nullptr;
            }
            break;
        case fifth_colon_comma:
            if ( ch == ':' ) {
                state = sixth_colon;
            }
            break;
        case sixth_colon:
            if ( ch == '.' ) {
                state = sixth_colon_dot;
            } else if ( ch >= '0' && ch <= '9' ) {
                newCity->coord_.lat_ = newCity->coord_.lat_*10 +(ch - '0');
            } else {
                return nullptr;
            }
            break;
        case sixth_colon_dot:
            if ( ch == '}' ) {
                state = sixth_colon_right_bracket;
            } else if ( ch >= '0' && ch <= '9' ) {
                newCity->coord_.lat_ += (ch - '0') / pow_10[divide_counter++];
            } else {
                return nullptr;
            }
            break;
        case sixth_colon_right_bracket:
            state = enough;
            break;
        case enough:
            assert("We can't be here");
            break;
        };
        if ( state == enough ) {
            break; // break while
        }

        ++curr;
    }
    newCity->name_.append(cityName);
    newCity->country_.append(countryName);

    return newCity;
}

City::City()
{

}

std::ostream& operator<<(std::ostream &out, const City &city)
{
    qDebug() << "_________Start__________\n";
    qDebug() << "Name: " << city.name();// << std::endl;
    qDebug() << "id: " << city.id();
    qDebug() << "country: " << city.country();
    qDebug() << "coord.lon: " <<  city.coord().lon();
    qDebug() << "coord.lat: " << city.coord().lat();
    qDebug() << "_________Finish__________\n";

    return out;
}
<file_sep>#include "logger.h"
#include <QFileDialog>
#include <QDebug>
#include <QDir>
#include <QMessageBox>
#include <cassert>
#include <QDateTime>

Logger::Logger( mode::ENUM m, QObject* parrent ) :
    QObject(parrent)
{
    assert( (m == mode::append || m == mode::clear) && "Unknown mode");
    QString currDir = QDir::currentPath();
    bool isFileSelected = false;
    while ( !isFileSelected ) {
        do {
            logFileName_ =  QFileDialog::getOpenFileName(0, "Select the log file", currDir);
        }
        while( logFileName_.isEmpty() );

        log_.setFileName(logFileName_);
        QIODevice::OpenMode openMode;
        openMode = (m == mode::append) ? QIODevice::Append : QIODevice::Truncate;
        log_.open(QIODevice::WriteOnly|openMode);
        if ( !log_.isWritable() ) {
            QMessageBox::critical(0, "Error",
                                  "Can not write to the file, please chose another file"
                                  );
            log_.close();
        } else {
            isFileSelected = true;
        }
    } //end while (!isFileSelected)
    markStartMessage();
}

Logger::~Logger()
{
    markEndMessage();
}

Logger& Logger::operator<<(const QString &logThis)
{
    QDateTime now = QDateTime::currentDateTime();
    QString date = now.toString() + " ";
    //qDebug() << date;
    log_.write(date.toStdString().c_str(), date.toStdString().size());

    log_.write(logThis.toStdString().c_str(), logThis.toStdString().size());
    addNextLine();

    return *this;
}

void Logger::markStartMessage()
{
    QString message = " Writing started";

    (*this) << message;
    addNextLine();
}

void Logger::markEndMessage()
{
    QString message = " Writing finished";

    (*this) << message;
    addNextLine();
    log_.flush();
}

void Logger::addNextLine()
{
#if defined(Q_OS_WIN) || defined(Q_OS_WIN32) || defined(Q_OS_OS2)
    log_.write("\r\n", 2);
#elif defined Q_OS_MAC
   log_.write("\n", 1);
#endif

}

void Logger::slotLog(const QUrl& url,const QByteArray& ba)
{
    slotLog(url);
    (*this) << QString(ba);
}

void Logger::slotLog(const QUrl& url)
{
    (*this) << url.toString();
}
<file_sep>#ifndef LO_TREEWIDGET_H
#define LO_TREEWIDGET_H

#include <QTreeWidget>
#include <QObject>
#include <QWidget>
#include <QHash>

class LO_TreeWidget : public QTreeWidget
{
    Q_OBJECT
private:
    QString sourceFileName_;

public:
    explicit LO_TreeWidget(const QString& sourceFileName, QWidget *parent = 0);
    bool loadData();
signals:
    void activated(const QString& cityName);
protected slots:
    void slot_emitActivated(QTreeWidgetItem*,int);
};

#endif // LO_TREEWIDGET_H
<file_sep>#include "weatherwidget.h"
#include <QGridLayout>
#include <QDebug>
#include <QMessageBox>
#include <iostream>
#include "ui_weather_display.h"
#include <QWidget>
#include <QList>

WeatherWidget::WeatherWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form),
    APPID_("<KEY>")
{
    ui->setupUi(this);
    urlRoot_ = "http://api.openweathermap.org/";
    weatherQuery_ = "data/2.5/weather/?q=";
    weatherImgQuery_ = "img/w/";
    imgExtention_ = ".png";

    ui->APPID->setText(APPID_);
    pdl_ = new Downloader(this);
    pdlImg_ = new Downloader(this);

    connect(pdl_, SIGNAL(done(const QUrl&,const QByteArray&)), this, SLOT(slotDone(const QUrl&,const QByteArray&)));
    connect(pdlImg_, SIGNAL(done(const QUrl&,const QByteArray&)), this, SLOT(slotImgDone(const QUrl&,const QByteArray&)));
    connect(ui->btn_resetAPPID, SIGNAL(clicked(bool)), this, SLOT(slotResetToDefault(bool)));
    connect(pdl_, SIGNAL(error(QString)), this, SLOT(slotError(QString)));
}

WeatherWidget::~WeatherWidget()
{
    delete ui;
}

void WeatherWidget::connectLogger(const Logger &logger)
{
       connect(pdl_, SIGNAL(done(const QUrl&,const QByteArray&)),
            &logger, SLOT(slotLog(const QUrl&,const QByteArray&))
            );
       connect(pdlImg_, SIGNAL(done(const QUrl&,const QByteArray&)),
            &logger, SLOT(slotLog(const QUrl&))
            );
}

void WeatherWidget::slotGo(const QString & url)
{
    slotClearFroms();
    QString request = urlRoot_ + weatherQuery_ + url +"&APPID=" + ui->APPID->text();
    pdl_->download(QUrl(request));
}

void WeatherWidget::slotClearFroms()
{
    {
        QList<QLineEdit*> list = ui->layoutWidget->findChildren<QLineEdit*>();
        QList<QLineEdit*>::iterator iter = list.begin();
        for( ; iter != list.end(); ++iter ) {
            if ( (*iter)->objectName() == QString("APPID") ){
                continue;
            }
            (*iter)->clear();
        }
    }
    {
        QList<QTextEdit*> list = ui->layoutWidget->findChildren<QTextEdit*>();
        QList<QTextEdit*>::iterator iter = list.begin();
        for( ; iter != list.end(); ++iter ) {
            (*iter)->clear();
        }
    }
    {
        ui->image->clear();
    }
}

void WeatherWidget::slotError()
{
    displayError("Error", "An error while download occured");
}

void WeatherWidget::slotDone(const QUrl &url, const QByteArray &ba)
{
    ui->textEdit->setPlainText(ba);
    ui->requestLine->setText(url.toString());

    picojson::value         v;
    std::string             error;

    picojson::parse(v, ba.constData(), ba.constData()+ ba.size(), &error);
    if (!error.empty()) {
        displayError("Error", QString("Error occured ") + QString().fromStdString(error));
        return;
    }
    if (!v.is<picojson::object>()) {
        displayError("Error", "It is not JSON object");
        return;
    } else {
        JSONParseAndFill(v.get<picojson::object>());
    }
}

void WeatherWidget::slotImgDone(const QUrl &, const QByteArray &ba)
{
    QPixmap pix;
    pix.loadFromData(ba);
    ui->image->setPixmap(pix);

    QVariant qvar = ui->image->property("fileName");
    QString name = qvar.value<QString>();

    cache_[name] = ba;
}

void WeatherWidget::slotResetToDefault(bool)
{
    ui->APPID->setText(APPID_);
}

void WeatherWidget::slotError(QString errStatus)
{
    qDebug() << "Debug message void WeatherWidget::slotError(QString errStatus)";
    displayError("Error", errStatus);
}

void WeatherWidget::JSONParseAndFill(picojson::value::object &obj)
{
    picojson::value::object::const_iterator i = obj.begin();
    for ( ; i != obj.end(); ++i ) {
        picojson::value v =  i->second;
        if (i->second.is<picojson::object>()) {
            JSONParseAndFill(v.get<picojson::object>());
        } else if (i->second.is<picojson::array>()) {
            JSONParseAndFill(v.get<picojson::array>());
        } else {
            setText(QString().fromStdString(i->first),
                    QString().fromStdString(i->second.to_str())
                    );
        }
    }
}

void WeatherWidget::JSONParseAndFill(picojson::value::array &obj)
{
    picojson::value::array::iterator i = obj.begin();
    for ( ; i != obj.end(); ++i ) {
        picojson::value v = *i;

        if ((*i).is<picojson::object>()) {
             JSONParseAndFill(v.get<picojson::object>());
        } else if ( (*i).is<picojson::array>() ) {
            JSONParseAndFill(v.get<picojson::array>());
        }
    }
}

void WeatherWidget::displayError(const QString &title, const QString& message)
{
    QMessageBox::critical(0, title, message);
}

void WeatherWidget::setText(const QString &widgetName, const QString &value)
{
        QWidget* curr = ui->layoutWidget->findChild<QWidget*>(widgetName);

        if (curr && curr->metaObject()->className() == QString("QLineEdit") ) {
            if (curr->objectName() == "icon") {
                ui->image->setProperty("fileName", QVariant(value));
                downloadImg(value);
            }
            qobject_cast<QLineEdit*>(curr)->setText(value);
        }
}

void WeatherWidget::downloadImg(const QString &imgName)
{
    QString request = urlRoot_ + weatherImgQuery_ + imgName + imgExtention_;

    qDebug() << request;

    const QByteArray* ba = checkCache(imgName);
    if( ba != nullptr ) {
        qDebug() << request << "From cache";
        slotImgDone(QUrl(request), *ba);
    } else {
        pdlImg_->download(QUrl(request));
    }
}

const QByteArray *WeatherWidget::checkCache(const QString &key)
{
    ImgCache::const_iterator i = cache_.find(key);

    if ( i != cache_.end() ) {
        return &(*i);
    }

    return nullptr;
}
<file_sep>#ifndef CITY_H
#define CITY_H

class City
{
public:
    City();
};

#endif // CITY_H
<file_sep>#include <QApplication>
#include "lo_treewidget.h"
#include "weatherwidget.h"
#include <QHBoxLayout>
#include <QWidget>
#include "logger.h"


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setWindowIcon(QIcon(QPixmap(":/icons/mainIcon.png")));

    Logger log(Logger::mode::clear);

    QWidget central;
#ifdef QT_DEBUG
    LO_TreeWidget tree(":/allcities/city.list1.json");
#elif QT_NO_DEBUG
    LO_TreeWidget tree(":/allcities/city.list.json");
#else
#error("Please define QT_DEBUG or QT_DEBUG macro")
#endif
    if ( !tree.loadData()) {
        return -1;
    }
    tree.show();

    //
    WeatherWidget weather;
    weather.show();
    weather.connectLogger(log);
    QObject::connect(&tree, SIGNAL(activated(QString)),
                     &weather, SLOT(slotGo(QString))
                     );

    //Layouts
    QHBoxLayout* phbl = new QHBoxLayout();
    phbl->addWidget(&tree);
    phbl->addWidget(&weather);

    central.setLayout(phbl);
    central.show();

    return a.exec();
}
<file_sep>#ifndef LOGGER_H
#define LOGGER_H

#include <QFile>
#include <QObject>

class Logger : public QObject
{
    Q_OBJECT
private:
    QString logFileName_;
    QFile   log_;
public:
    struct mode {
        enum ENUM { clear, append };
    };
    explicit Logger( mode::ENUM, QObject* parrent = 0 );
    ~Logger();

    Logger &operator<<(const QString& logThis);
private:
    Logger(const Logger& orig) = delete;
    Logger& operator=(const Logger& rhs) = delete;
    void markStartMessage();
    void markEndMessage();

    void addNextLine();
public slots:
    void slotLog(const QUrl&,const QByteArray&);
    void slotLog(const QUrl&);
};

#endif // LOGGER_H
<file_sep>#include "lo_treewidget.h"
#include "data.h"
#include <QByteArray>
#include <QFile>
#include <memory>
#include <iostream>
#include <QDebug>
#include <QStringList>
#include <cassert>

LO_TreeWidget::LO_TreeWidget(const QString& sourceFileName, QWidget *parent) :
    QTreeWidget(parent),
    sourceFileName_(sourceFileName)
{
    setMinimumWidth(200);
    QStringList lst;
    lst << "Name" << "Id" << "Country" << "Lon" << "Lat";
    setHeaderLabels(lst);
    setSortingEnabled(true);

}

bool LO_TreeWidget::loadData()
{
    QFile file(sourceFileName_);
   if ( !file.open(QIODevice::ReadOnly)) {
       return  false;
   } else {
       QHash<QChar, QTreeWidgetItem*> firstSymbolHash;
       QByteArray b_array(1024, '\0');
       std::shared_ptr<City> sp_city;
       while ( file.readLine(b_array.data(), 1024) != -1 ) {

           sp_city = City::makeCity(b_array);
           if ( sp_city.get() != nullptr){
              QChar firstCh = sp_city->name().at(0);

              QTreeWidgetItem* p_topLevel = 0;
              auto iter = firstSymbolHash.find(firstCh);
              if ( iter == firstSymbolHash.cend()) {
                  p_topLevel = new QTreeWidgetItem(this);
                  p_topLevel->setText(0, firstCh);
                  firstSymbolHash[firstCh] = p_topLevel;
              } else {
                  p_topLevel = iter.value();
              }
              assert(p_topLevel!= 0 &&
                      "bool LO_TreeWidget::loadData(),  QTreeWidgetItem* p_topLevel = 0"
                      );
              QTreeWidgetItem* p_twgItem = new QTreeWidgetItem(p_topLevel);
              p_twgItem->setText(0, sp_city->name());
              p_twgItem->setText(1, QString::number(sp_city->id()));
              p_twgItem->setText(2, sp_city->country());
              p_twgItem->setText(3, QString::number(sp_city->coord().lon()));
              p_twgItem->setText(4, QString::number(sp_city->coord().lat()));
           }
       }
       sortByColumn(0,Qt::AscendingOrder);
   }
   connect(this,
           SIGNAL(itemActivated(QTreeWidgetItem*,int)),
           SLOT(slot_emitActivated(QTreeWidgetItem*,int))
                  );
           return true;
}

void LO_TreeWidget::slot_emitActivated(QTreeWidgetItem* item ,int col) {
    emit activated(item->text(0));
}
