void TreeModel::setupModelData(const QString &tableName, TreeItem *parent){ QList<TreeItem*> parents; parents << parent; QSqlTableModel* modelName = new QSqlTableModel; modelName->setTable(tableName); modelName->select(); QString str; for(int count = 0; count < modelName->rowCount(); count++) { str = modelName->record(count).value("name").toString(); TreeItem* item = new TreeItem(str, parents.last()); parents.last()->appendChild(item); }}
void TreeModel::setupModelData(const QString &nameDb, TreeItem *parent){ connection(nameDb); QSqlTableModel* modelGenre = new QSqlTableModel(); QSqlTableModel* modelFilm = new QSqlTableModel(); modelGenre->setTable("genre"); modelGenre->select(); modelFilm->setTable("film"); for(int count_parent = 0; count_parent < modelGenre->rowCount(); count_parent++) { QString str = modelGenre->record(count_parent).value("name").toString(); TreeItem* item = new TreeItem(QStringList() << str, parent); parent->appendChild(item); modelFilm->setFilter("genre = '" + str + "'"); modelFilm->select(); for(int count_child = 0; count_child < modelFilm->rowCount(); count_child++) { TreeItem* child = new TreeItem(QStringList() << modelFilm->record(count_child).value("name").toString(), item); item->appendChild(child); } }}