コード例 #1
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();

}
コード例 #2
0
ファイル: citymodel.cpp プロジェクト: Dichotomia/meecast
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();
}