Пример #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
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));
    }

}
Пример #3
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);

}
Пример #4
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();

}