void VegetationWidget::slotDeleteSelected() { QListView* view = qobject_cast<QListView*>(sender()); QStandardItemModel* model = qobject_cast<QStandardItemModel*>(view->model()); QString dirString(""); if (view == _treeListView) { std::string plantDir = g_SystemContext._workContextDir; plantDir.append(CONTEXT_DIR); plantDir.append("/Plant/"); dirString = chineseTextUTF8ToQString(plantDir + "Tree/"); } else { std::string plantDir = g_SystemContext._workContextDir; plantDir.append(CONTEXT_DIR); plantDir.append("/Plant/"); dirString = chineseTextUTF8ToQString(plantDir + "Grass/"); } QItemSelectionModel* selectionModel = view->selectionModel(); QModelIndexList modelList = selectionModel->selectedIndexes(); if (modelList.size() < 1) return; for (int i = 0; i < modelList.size(); ++i) { QStandardItem* everyItem = model->itemFromIndex(modelList.at(i)); QFile::remove(dirString + everyItem->text()); int row = everyItem->row(); model->removeRow(row); } }
/*! Sets \a model to be the ThemeListModel associated with this ThemeListItem. If this item currently has a QListView widget set, this model is installed immediately on the view using QListView::setModel(). If a call is made to QWidget::setWidget() in the future, this model will be installed in the same way. */ void QThemeListItem::setModel(QThemeListModel *model) { if (d->model != model) { d->model = model; QListView* view = listView(); if (view != 0 && view->model() != d->model) view->setModel(d->model); } }
void tst_QFontDialog::task256466_wrongStyle() { QFontDatabase fdb; FriendlyFontDialog dialog; QListView *familyList = reinterpret_cast<QListView*>(dialog.d_func()->familyList); QListView *styleList = reinterpret_cast<QListView*>(dialog.d_func()->styleList); QListView *sizeList = reinterpret_cast<QListView*>(dialog.d_func()->sizeList); for (int i = 0; i < familyList->model()->rowCount(); ++i) { QModelIndex currentFamily = familyList->model()->index(i, 0); familyList->setCurrentIndex(currentFamily); const QFont current = dialog.currentFont(), expected = fdb.font(currentFamily.data().toString(), styleList->currentIndex().data().toString(), sizeList->currentIndex().data().toInt()); QCOMPARE(current.family(), expected.family()); QCOMPARE(current.style(), expected.style()); QCOMPARE(current.pointSizeF(), expected.pointSizeF()); } }
void VegetationWidget::slotViewSelected() { QListView* view = qobject_cast<QListView*>(sender()); QItemSelectionModel* selectionModel = view->selectionModel(); QModelIndexList modelList = selectionModel->selectedIndexes(); if (modelList.size() < 1) return; QStandardItemModel* model = qobject_cast<QStandardItemModel*>(view->model()); std::string dirString(""); if (view == _treeListView) { std::string plantDir = g_SystemContext._workContextDir; plantDir.append(CONTEXT_DIR); plantDir.append("/Plant/"); dirString = plantDir + "Tree/"; } else { std::string plantDir = g_SystemContext._workContextDir; plantDir.append(CONTEXT_DIR); plantDir.append("/Plant/"); dirString = plantDir + "Grass/"; } QStandardItem* currentItem = model->itemFromIndex(modelList.at(0)); dirString.append(chineseTextToUTF8String(currentItem->text())); osg::ref_ptr<osg::Node> node; if (currentItem->text().endsWith(".osgb")) { node = g_SystemContext._resourceLoader->getNodeByName(dirString, false); } else { osg::ref_ptr<osg::Image> image = g_SystemContext._resourceLoader->getImageByFileName(dirString); if (image.valid()) { float s = image->s(); float t = image->t(); osg::ref_ptr<osg::Geometry> geometry = osg::createTexturedQuadGeometry(osg::Vec3(-s / 2.0f, -t / 2.0f, 0), osg::Vec3(s, 0, 0), osg::Vec3(0, t, 0)); osg::ref_ptr<osg::Geode> geode = new osg::Geode; geode->addDrawable(geometry); osg::StateSet* ss = geode->getOrCreateStateSet(); ss->setMode(GL_BLEND, osg::StateAttribute::ON); ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); osg::Texture2D* texture = new osg::Texture2D(image); ss->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); node = geode; } } if (node.valid()) { _nodeViewDialog = new NodeViewDialog; _nodeViewDialog->setNode(node); _nodeViewDialog->exec(); //_nodeViewDialog->setNode(NULL); } }
void MainWindow::loadProjects() { QListView *view = ui->centralWidget->findChild<QListView*>("projectLst"); QStandardItemModel *model = static_cast<QStandardItemModel*>(view->model()); QVector<Project*> projects = Project::getProjects(); foreach(Project *p, projects) { QStandardItem *item = new QStandardItem(); item->setData(p->getName(), ProjectItemDelegate::nameTextRole); model->appendRow(item); }
/*! \reimp Sets the QListView \a w as this ThemeListItem's widget. \a w must be non-zero and inherit QListView, otherwise this function will abort. An internal implementation of QItemDelegate is installed on the view to handle communication between itself and a ThemeListModel. If a ThemeListModel object has already been set using setModel(), it is installed immediately using QListView::setModel(). If a call is made to setModel() in the future, that model will be installed on this widget in the same way. */ void QThemeListItem::setWidget(QWidget *w) { QThemeWidgetItem::setWidget(w); Q_ASSERT(widget() == 0 || widget()->inherits("QListView") == true); if (!widget()) return; QListView* v = listView(); v->setItemDelegate(new QThemeListDelegate(v, themedScene()->themedView(), themedScene()->themedView())); if (d->model != 0 && v->model() != d->model) v->setModel(d->model); }
/** Process results sent back from various search engines (local, remote). */ void SearchDialog::processResults(Request type, const QStandardItemList &results) { QListView *listToProcess = nullptr; switch (type) { case Artist: listToProcess = _artists; break; case Album: listToProcess = _albums; break; case Track: listToProcess = _tracks; break; } QStandardItemModel *m = qobject_cast<QStandardItemModel*>(listToProcess->model()); for (int i = 0; i < results.size(); i++) { m->insertRow(0, results.at(i)); } m->sort(0); listToProcess->setFixedHeight(listToProcess->model()->rowCount() * listToProcess->sizeHintForRow(0)); qDebug() << "number of items" << listToProcess->model()->rowCount(); qDebug() << "size h f r 1" << _artists->sizeHintForRow(0) << _albums->sizeHintForRow(0) << _tracks->sizeHintForRow(0); qDebug() << "size h f r 2" << iconArtists->height() << iconAlbums->height() << iconTracks->height(); int ar = qMax(_artists->model()->rowCount() * _artists->sizeHintForRow(0), iconArtists->height()); int al = qMax(_albums->model()->rowCount() * _albums->sizeHintForRow(0), iconAlbums->height()); int tr = qMax(_tracks->model()->rowCount() * _tracks->sizeHintForRow(0), iconTracks->height()); artistLayoutWidget->setFixedHeight(ar); albumLayoutWidget->setFixedHeight(al); trackLayoutWidget->setFixedHeight(tr); qDebug() << "ar al tr" << ar << al << tr; int h = ar + al + tr; //int h = 300; h += labelSearchMore->height() + aggregated->height() + 3; int minW = qMax(iconArtists->width() + _artists->sizeHintForColumn(0), 400); this->resize(minW, h); }
void MessagePage::on_deleteButton_clicked() { QListView *list = ui->listConversation; if(!list->selectionModel()) return; QModelIndexList indexes = list->selectionModel()->selectedIndexes(); if(!indexes.isEmpty()) { list->model()->removeRow(indexes.at(0).row()); indexes = list->selectionModel()->selectedIndexes(); if(indexes.isEmpty()) on_backButton_clicked(); } }
/** * @brief MainWindow::setDocumentModel * * Will be called whe a new q2d::Project is created, to link the projects * document model with the appropriate list view in the UI. * @param model */ void MainWindow::slot_setDocumentModel(QStandardItemModel* model) { // close all tabs related to the old model m_ui->schematicsTabWidget->clear(); QListView* documentView = m_ui->documentListView; documentView->clearSelection(); QAbstractItemModel* oldModel = documentView->model(); m_ui->documentListView->setModel(model); if (oldModel != nullptr) { oldModel->disconnect(); oldModel->deleteLater(); } }
QStringListModel * GraphicalArrayTest::findModel(const GraphicalArray* value) { // /!\ WARNING /!\ // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION // OF THE GRAPHICAL LOOK OF GraphicalArray QListView * view = findListView(value); QStringListModel * model = nullptr; if( is_not_null(view) ) { model = dynamic_cast<QStringListModel*>( view->model() ); if( is_null(model) ) QWARN("Failed to find the view model."); } return model; }
void EmoticonViewer::deleteSelected() { QListView *view = _ui->listView; view->model()->removeRow(view->currentIndex().row()); }
void EmoticonViewer::accept() { QListView *view = _ui->listView; emit hasTextToInsert(view->model()->data(view->currentIndex()).toString()); close(); }