本文整理汇总了C++中QSqlTableModel::filter方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::filter方法的具体用法?C++ QSqlTableModel::filter怎么用?C++ QSqlTableModel::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QString
QTreeWidgetItem *CollectionTreeWidget::addAlbum(QString artist, QString album, unsigned int albumId) {
// Find id in database if we don't have it
if (albumId == 0) {
QSqlTableModel *model = service->collectionModel();
// SQLite used two single quotes to escape a single quote! :)
QString filter = "artist = '" + QString(artist).replace("'","''") + "' AND "
"album = '" + QString(album).replace("'","''") + "'";
model->setFilter(filter);
model->select();
while (model->canFetchMore()) model->fetchMore();
int total = model->rowCount();
if (total > 0) {
albumId = model->record(0).value(model->fieldIndex("id_album")).toInt();
}
else {
qDebug("ERROR: no album found! -- " + model->filter().toUtf8());
return NULL;
}
}
// Looks for the artist
QTreeWidgetItem *newAlbumNode; // The node with the album, whether it exists or not
QTreeWidgetItem *artistItem;
artistItem = addArtist(artist);
// Look for album
for (int i = 0; i < artistItem->childCount(); i++) {
if (artistItem->child(i)->text(0) == album) {
newAlbumNode = artistItem->child(i);
return newAlbumNode;
}
}
// Create our new album node and add it if it was not found
newAlbumNode = new CollectionTreeWidgetItem(LevelAlbum, albumId, (QTreeWidget*)0);
newAlbumNode->setText(0, album);
newAlbumNode->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
// Set icon
newAlbumNode->setIcon(0, IconFactory::fromTheme("media-cdrom"));
artistItem->addChild(newAlbumNode);
artistItem->sortChildren(0, Qt::AscendingOrder);
return newAlbumNode;
}
示例2: while
CollectionTreeWidgetItem *CollectionTreeWidget::addMusic(Music *music, unsigned int id) {
// Find id in database if we don't have it
if (id == 0) {
QSqlTableModel *model = service->collectionModel();
// SQLite used two single quotes to escape a single quote! :)
QString filter = "artist = '" + music->getArtist().replace("'","''") + "' AND "
"album = '" + music->getAlbum().replace("'","''") + "' AND "
"music = '" + music->getTitle().replace("'","''") + "'";
model->setFilter(filter);
model->select();
while (model->canFetchMore()) model->fetchMore();
int total = model->rowCount();
if (total > 0) {
id = model->record(0).value(model->fieldIndex("id_music")).toInt();
}
else {
qDebug("ERROR: no songs found! -- " + model->filter().toUtf8());
return NULL;
}
}
// Looks for the album
QTreeWidgetItem *albumItem = addAlbum(music->getArtist(), music->getAlbum());
// Create our new music node and add it if it was not found
removeMusic(id);
CollectionTreeWidgetItem *newMusicNode = new CollectionTreeWidgetItem(LevelMusic, id, (QTreeWidget*)0);
newMusicNode->setText(0, music->getTitle());
newMusicNode->setIcon(0, IconFactory::fromTheme("sound"));
albumItem->addChild(newMusicNode);
musicList.append(newMusicNode);
return newMusicNode;
}