Пример #1
0
void StationPage::sourceChanged(int val)
{
    std::cerr << "source changed val = " << val << std::endl;
    std::string path(Core::AbstractConfig::prefix);
    path += Core::AbstractConfig::sharePath;
    path += "db/";
    QString filename = sourceCombo->currentText();
    std::cerr << filename.toStdString() << std::endl;
    filename.append(".db");
    filename.prepend(path.c_str());
    if (!this->db) {
        this->db->set_databasename(filename.toStdString());
    }else {
        this->db->set_databasename(filename.toStdString());

    }
    this->db->open_database();

    Core::listdata * list = db->create_countries_list();

    countryCombo->clear();

    //countryCombo->addItem("");
    if (!list)
        return;
    for (int i=0; i<list->size(); i++){
        countryCombo->addItem(QString::fromStdString(list->at(i).second));
        countryCombo->setData(i, QString::fromStdString(list->at(i).first));
    }
    if (countryCombo->count() > 0)
        countryCombo->setCurrentIndex(0);
}
Пример #2
0
QString
ConfigQml::getCityId(int region_id, int index)
{
    Core::listdata * list = db->create_stations_list(region_id);
    Core::listdata::iterator cur;

    if (!list)
        return 0;
    cur = list->begin()+index;
    return QString::fromStdString((*cur).first);
}
Пример #3
0
int
ConfigQml::getRegionId(int country, int index)
{
    Core::listdata * list = db->create_region_list(getCountryId(country));

    Core::listdata::iterator cur;

    if (!list)
        return 0;
    cur = list->begin()+index;
    return atoi((*cur).first.c_str());
}
Пример #4
0
QStringList
ConfigQml::Cities(int country_index, int index)
{
    QStringList l;
    Core::listdata * list = db->create_stations_list(getRegionId(country_index, index));

    if (list->size() == 0) return l;
    Core::listdata::iterator cur;
    for (cur=list->begin(); cur<list->end(); cur++)
        l << QString::fromStdString((*cur).second);

    return l;
}
Пример #5
0
void
StationPage::regionChanged(int val)
{
    cityCombo->clear();

    Core::listdata * list = db->create_stations_list(regionCombo->data(val).toInt());

    if (list->size() == 0) return;
    for (int i=0; i<list->size(); i++){
        cityCombo->addItem(QString::fromStdString(list->at(i).second));
        cityCombo->setData(i, QString::fromStdString(list->at(i).first));
    }

}
Пример #6
0
void StationPage::countryChanged(int val)
{
    QString str = countryCombo->data(val).toString();
    std::cerr << "country changed val = " << str.toStdString() << std::endl;
    regionCombo->clear();

    Core::listdata * list = db->create_region_list(countryCombo->data(val).toInt());

    if (list->size() == 0) return;
    for (int i=0; i<list->size(); i++){
        regionCombo->addItem(QString::fromStdString(list->at(i).second));
        regionCombo->setData(i, QString::fromStdString(list->at(i).first));
    }
    if (regionCombo->count() > 0)
        regionCombo->setCurrentIndex(0);

}
Пример #7
0
void
CityModel::populate(QString source, QString region)
{
    beginInsertRows(QModelIndex(), rowCount(), rowCount());
    _list.clear();
    std::string path(Core::AbstractConfig::prefix);
    path += Core::AbstractConfig::sharePath;
    path += "db/";
    if (source == "") return ;
    QString filename(source);
    filename.append(".db");
    filename.prepend(path.c_str());
    Core::DatabaseSqlite *db;
    db = new Core::DatabaseSqlite("");
    qDebug() << "filename = " << filename;
    if (db) {
        db->set_databasename(filename.toStdString());
    }else {
        qDebug() << "error db";

    }
    if (!db->open_database()){
        qDebug() << "error open database";
        return;
    }

    Core::listdata * list = db->create_stations_list(region.toInt());

    if (list->size() == 0) return;
    Core::listdata::iterator cur;
    for (cur=list->begin(); cur<list->end(); cur++){
        QString str = QString::fromUtf8((*cur).second.c_str());
        _list.append(new SelectData(str, QString::fromStdString((*cur).first), str.left(1)));
    }
    endInsertRows();
    //reset();
    endResetModel();
}
Пример #8
0
QStringList
ConfigQml::Countries(QString source)
{
    QStringList l;
    std::string path(Core::AbstractConfig::prefix);
    path += Core::AbstractConfig::sharePath;
    path += "db/";
    if (source == "") return l;
    QString filename(source);
    filename.append(".db");
    filename.prepend(path.c_str());
    if (!this->db) {
        this->db->set_databasename(filename.toStdString());
    }else {
        this->db->set_databasename(filename.toStdString());

    }
    if (!this->db->open_database()){
        l << "error open db";
        return l;
    }
    Core::listdata * list = db->create_countries_list();
    Core::listdata::iterator cur;

    if (!list)
        return l;
    for (cur=list->begin(); cur<list->end(); cur++){
        l << QString::fromStdString((*cur).second);
        /*if (isKeys) {
            l << QString::fromStdString((*cur).first);
        }else {
            l << QString::fromStdString((*cur).second);
        }*/
    }

    return l;
}
Пример #9
0
void
RegionModel::populate(QString source, QString country)
{
    beginInsertRows(QModelIndex(), rowCount(), rowCount());
    _list.clear();
    std::string path(Core::AbstractConfig::prefix);
    path += Core::AbstractConfig::sharePath;
    path += "db/";
    if (source == "") return ;
    QString filename(source);
    filename.append(".db");
    filename.prepend(path.c_str());
    Core::DatabaseSqlite *db;
    db = new Core::DatabaseSqlite("");
    qDebug() << "Region list filename = " << filename;
    if (db) {
        db->set_databasename(filename.toStdString());
    }else {
        qDebug() << "error db";

    }
    if (!db->open_database()){
        qDebug() << "error open database";
        return;
    }

    Core::listdata * list = db->create_region_list(country.toInt());

    if (list->size() == 0) return;
    qDebug() << "list size = " << list->size() << " at 0 " << QString::fromStdString(list->at(0).second);
    for (int i=0; i < list->size(); i++){
        QString str = QString::fromUtf8(list->at(i).second.c_str());
        _list.append(new SelectData(str, QString::fromStdString(list->at(i).first), str.left(1)));
    }
    endInsertRows();
    reset();

}