本文整理汇总了C++中QStandardItemModel类的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel类的具体用法?C++ QStandardItemModel怎么用?C++ QStandardItemModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QStandardItemModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setContact
void BE::Contacts::manageContact(const QString &mail, const QString &prettyName)
{
QStandardItemModel *model = m_abook->model();
for (int i = 0; i < model->rowCount(); ++i) {
QStandardItem *item = model->item(i);
if (QString::compare(item->data(Gui::AbookAddressbook::Mail).toString(), mail, Qt::CaseInsensitive) == 0) {
setContact(model->index(i, 0));
return;
}
}
// no match -> create one
addContact();
m_ui2->mail->setText(mail);
if (!prettyName.isEmpty()) {
m_ui2->name->setText(prettyName);
m_currentContact->setText(prettyName);
} else {
m_ui2->name->setText("[name]");
}
}
示例2: selectAction
void KSelectAction_UnitTest::testChildActionStateChangeComboMode()
{
KSelectAction selectAction("selectAction", 0);
selectAction.setToolBarMode(KSelectAction::ComboBoxMode);
QWidget parent;
QWidget* widget = selectAction.requestWidget(&parent);
KComboBox* comboBox = qobject_cast<KComboBox*>(widget);
QVERIFY(comboBox);
const QString itemText = "foo";
KAction* childAction = selectAction.addAction(itemText);
QCOMPARE(comboBox->itemText(0), itemText);
childAction->setEnabled(false);
// There's no API for item-is-enabled, need to go via the internal model like kselectaction does...
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboBox->model());
QVERIFY(model);
QVERIFY(!model->item(0)->isEnabled());
// Now remove the action
selectAction.removeAction(childAction);
QCOMPARE(comboBox->count(), 0);
}
示例3: populateColorRamps
void QgsStyleManagerDialog::populateColorRamps( const QStringList &colorRamps, bool check )
{
QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
model->clear();
for ( int i = 0; i < colorRamps.count(); ++i )
{
QString name = colorRamps[i];
std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
QStandardItem *item = new QStandardItem( name );
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), listItems->iconSize(), 18 );
item->setIcon( icon );
item->setData( name ); // used to find out original name when user edited the name
item->setCheckable( check );
item->setToolTip( name );
model->appendRow( item );
}
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
symbolSelected( listItems->currentIndex() );
}
示例4: outputMessage
void SvnJobBase::outputMessage(const QString& message)
{
if (!model()) return;
if (verbosity() == KDevelop::OutputJob::Silent) return;
QStandardItemModel *m = qobject_cast<QStandardItemModel*>(model());
QStandardItem *previous = m->item(m->rowCount()-1);
if (message == "." && previous && previous->text().contains(QRegExp("\\.+")))
previous->setText(previous->text() + message);
else
m->appendRow(new QStandardItem(message));
KDevelop::IPlugin* i = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IOutputView");
if( i )
{
KDevelop::IOutputView* view = i->extension<KDevelop::IOutputView>();
if( view )
{
view->raiseOutput( outputId() );
}
}
}
示例5: QDialog
CSatelliteDlg::CSatelliteDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::CSatelliteDlg)
{
ui->setupUi(this);
m_cSaveQuest = tr("Save current catalogue to disc?");
setWindowFlags(((windowFlags() | Qt::CustomizeWindowHint)
& ~Qt::WindowCloseButtonHint));
QStandardItemModel *model = new QStandardItemModel(0, 1, NULL);
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));
ui->listView->setModel(model);
ui->listView->activateWindow();
fillList();
ui->widget->setModel((QSortFilterProxyModel *)ui->listView->model(), 0);
connect(ui->widget, SIGNAL(sigSetSelection(QModelIndex&)), this, SLOT(slotSelChange(QModelIndex&)));
}
示例6: changeEvent
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgFilletEdges::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
int index = ui->shapeObject->currentIndex();
// only get the items from index 1 on since the first one will be added automatically
int count = ui->shapeObject->count() - 1;
QStringList text;
QList<QVariant> data;
for (int i=0; i<count; i++) {
text << ui->shapeObject->itemText(i+1);
data << ui->shapeObject->itemData(i+1);
}
ui->retranslateUi(this);
for (int i=0; i<count; i++) {
ui->shapeObject->addItem(text.at(i));
ui->shapeObject->setItemData(i+1, data.at(i));
}
ui->shapeObject->setCurrentIndex(index);
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
count = model->rowCount();
for (int i=0; i<count; i++) {
int id = model->data(model->index(i, 0), Qt::UserRole).toInt();
model->setData(model->index(i, 0), QVariant(tr("Edge%1").arg(id)));
}
}
else {
QWidget::changeEvent(e);
}
}
示例7: getSelectedTypes
void VegetationWidget::getSelectedTypes(std::vector<std::string>& returnTypeList)
{
returnTypeList.clear();
QWidget* curWidget = _tabWidget->currentWidget();
if (curWidget == _treeListView)
{
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_treeListView->model());
for (int j = 0; j < model->rowCount(); ++j)
{
QStandardItem* item = model->item(j);
if (item->checkState() == Qt::Checked)
{
returnTypeList.push_back(chineseTextToUTF8String(item->text()));
}
}
}
else
{
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_grassListView->model());
for (int j = 0; j < model->rowCount(); ++j)
{
QStandardItem* item = model->item(j);
if (item->checkState() == Qt::Checked)
{
returnTypeList.push_back(chineseTextToUTF8String(item->text()));
}
}
}
}
示例8: chineseTextUTF8ToQString
void VegetationWidget::buildList()
{
QStringList extList;
extList << ".png" << ".tga" << ".osgb";
std::string plantDir = g_SystemContext._workContextDir;
plantDir.append(CONTEXT_DIR);
plantDir.append("/Plant/");
QString grassDir = chineseTextUTF8ToQString(plantDir + "Grass");
QStringList returnList;
findAllFilesByExt(grassDir, extList, returnList);
QStandardItemModel* grassModel = qobject_cast<QStandardItemModel*>(_grassListView->model());
grassModel->clear();
for (int i = 0; i < returnList.size(); ++i)
{
QFileInfo fileInfo = returnList.at(i);
QStandardItem* newItem = new QStandardItem(fileInfo.fileName());
setupIcon(newItem, "grass");
newItem->setCheckable(true);
grassModel->appendRow(newItem);
}
QString treeDir = chineseTextUTF8ToQString(plantDir + "Tree");
returnList.clear();
findAllFilesByExt(treeDir, extList, returnList);
QStandardItemModel* treeModel = qobject_cast<QStandardItemModel*>(_treeListView->model());
treeModel->clear();
for (int i = 0; i < returnList.size(); ++i)
{
QFileInfo fileInfo = returnList.at(i);
QStandardItem* newItem = new QStandardItem(fileInfo.fileName());
setupIcon(newItem, "tree");
newItem->setCheckable(true);
treeModel->appendRow(newItem);
}
}
示例9: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QListView *listView = new QListView;
QListView *newListView = new QListView;
QStringList nameItem;
nameItem << "Linux" << "Android" << "Mac OS";
QStandardItemModel *model = new QStandardItemModel(nameItem.length(),1); // initialize row and columns of data model
for(int i = 0; i < model->rowCount(); ++i)
{
QModelIndex modelIndex = model->index(i,0);
QString str = nameItem.at(i);
model->setData(modelIndex,str,Qt::DisplayRole);
model->setData(modelIndex,"ToolTip for" + str,Qt::ToolTipRole);
model->setData(modelIndex,QIcon(":/Images/" + str + ".jpeg"),Qt::DecorationRole);
}
listView->setViewMode(QListView::IconMode);
listView->setModel(model);
listView->setGeometry(430,340,200,200);
newListView->setViewMode(QListView::IconMode);
newListView->setModel(model);
newListView->setGeometry(listView->geometry());
listView->show();
newListView->show();
return a.exec();
}
示例10: select
void CSVSettings::View::setSelectedValues (const QStringList &list,
bool doViewUpdate, bool signalUpdate) const
{
QItemSelection selection;
if (stringListsMatch (list, selectedValues()))
return;
if (!mHasFixedValues)
{
QStandardItemModel *model =
static_cast <QStandardItemModel *>(mDataModel);
model->clear();
model->appendColumn (toStandardItemList (list));
for (int i = 0; i < model->rowCount(); i++)
{
QModelIndex idx = model->index(i, 0);
selection.append (QItemSelectionRange (idx, idx));
}
}
else
{
for (int i = 0; i < mDataModel->rowCount(); i++)
{
if (list.contains(value(i)))
{
QModelIndex idx = mDataModel->index(i, 0);
selection.append(QItemSelectionRange (idx, idx));
}
}
}
select (selection);
//update the view if the selection was set from the model side, not by the
//user
if (doViewUpdate)
updateView (signalUpdate);
}
示例11: QWidget
tiBackupEdit::tiBackupEdit(QWidget *parent, tiBackupJob *job) :
QWidget(parent),
ui(new Ui::tiBackupEdit)
{
ui->setupUi(this);
currentJob = job;
currentJobDiskisAttached = false;
ui->btnPartitionMount->setDisabled(true);
parent->installEventFilter(this);
QStringList headers;
headers << "Quellordner" << "Destinationfolder";
QStandardItemModel *model = new QStandardItemModel(ui->tvBackupFolders);
model->setHorizontalHeaderLabels(headers);
ui->tvBackupFolders->setModel(model);
ui->tvBackupFolders->header()->resizeSection(0, 350);
// Load available Backup devices
TiBackupLib blib;
QList<DeviceDisk> disks = blib.getAttachedDisks();
qDebug() << "tiBackupEdit::tiBackupEdit() -> disks found:" << disks.count();
for(int i=0; i < disks.count(); i++)
{
DeviceDisk disk = disks.at(i);
qDebug() << "tiBackupEdit::tiBackupEdit() -> disk:" << disk.devname;
if(disk.devtype == "disk")
{
ui->comboBackupDevice->insertItem(0, QString("%1 - %2 (%3)").arg(disk.vendor, disk.model, disk.devname), disk.devname);
}
}
updateJobDetails();
if(currentJobDiskisAttached == true)
updatePartitionInformation();
}
示例12: if
void PanelObjectEvent::getCommandObjectEvent(QVector<QString> &command) const {
// Event
QStandardItemModel *model = nullptr;
SystemEvent *event = nullptr;
if (ui->radioButtonEventSystem->isChecked()) {
command.append("0");
model = RPM::get()->project()->gameDatas()->commonEventsDatas()
->modelEventsSystem();
event = reinterpret_cast<SystemEvent *>(model->item(ui
->comboBoxEventsSystem->currentIndex())->data().value<quintptr>());
} else if (ui->radioButtonEventUser->isChecked()){
command.append("1");
model = RPM::get()->project()->gameDatas()->commonEventsDatas()
->modelEventsUser();
event = reinterpret_cast<SystemEvent *>(model->item(ui
->comboBoxEventsUser->currentIndex())->data().value<quintptr>());
}
command.append(QString::number(event->id()));
// Parameters
QStandardItemModel *modelParameters = ui->treeViewParameters->getModel();
SystemParameter *param;
for (int i = 0; i < modelParameters->invisibleRootItem()->rowCount(); i++) {
param = reinterpret_cast<SystemParameter *>(modelParameters->item(i)
->data().value<quintptr>());
command.append(QString::number(param->id()));
param->value()->getCommandParameter(command);
}
}
示例13: QDialog
TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
const QMap<QString, QUrl> &links)
: QDialog(parent)
, m_filterModel(new QSortFilterProxyModel(this))
{
ui.setupUi(this);
setFocusProxy(ui.lineEdit);
ui.lineEdit->setFiltering(true);
ui.lineEdit->installEventFilter(this);
ui.lineEdit->setPlaceholderText(tr("Filter"));
ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword));
QStandardItemModel *model = new QStandardItemModel(this);
m_filterModel->setSourceModel(model);
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
QMap<QString, QUrl>::const_iterator it = links.constBegin();
for (; it != links.constEnd(); ++it) {
m_links.append(it.value());
QStandardItem *item = new QStandardItem(it.key());
item->setToolTip(it.value().toString());
model->appendRow(item);
}
ui.listWidget->setModel(m_filterModel);
ui.listWidget->setUniformItemSizes(true);
ui.listWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
if (m_filterModel->rowCount() != 0)
ui.listWidget->setCurrentIndex(m_filterModel->index(0, 0));
connect(ui.buttonDisplay, SIGNAL(clicked()), this, SLOT(acceptDialog()));
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(ui.listWidget, SIGNAL(activated(QModelIndex)), this,
SLOT(activated(QModelIndex)));
connect(ui.lineEdit, SIGNAL(filterChanged(QString)), this,
SLOT(setFilter(QString)));
}
示例14: uintEdit
void tst_QItemDelegate::uintEdit()
{
QListView view;
QStandardItemModel model;
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(0, 0, data);
}
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(1, 0, data);
}
view.setModel(&model);
view.setEditTriggers(QAbstractItemView::AllEditTriggers);
const QModelIndex firstCell = model.index(0, 0);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
view.selectionModel()->setCurrentIndex(model.index(0, 0), QItemSelectionModel::Select);
view.edit(firstCell);
QSpinBox *sb = view.findChild<QSpinBox*>();
QVERIFY(sb);
sb->stepUp();
// Select another index to trigger the end of editing.
const QModelIndex secondCell = model.index(1, 0);
view.selectionModel()->setCurrentIndex(secondCell, QItemSelectionModel::Select);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(firstCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(2));
view.edit(secondCell);
// The first spinbox is deleted with deleteLater, so it is still there.
QList<QSpinBox*> sbList = view.findChildren<QSpinBox*>();
QCOMPARE(sbList.size(), 2);
sb = sbList.at(1);
sb->stepDown(); // 1 -> 0
sb->stepDown(); // 0 (no effect)
sb->stepDown(); // 0 (no effect)
// Select another index to trigger the end of editing.
view.selectionModel()->setCurrentIndex(firstCell, QItemSelectionModel::Select);
QCOMPARE(secondCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(secondCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(0));
}
示例15: tr
void MainWindow::openProject()
{
const QString sfm_data_fileName = QFileDialog::getOpenFileName(this, tr("Choose a sfm_data project file"),
QString::null, tr("sfm_data (*.json *.xml *.bin)"));
if (sfm_data_fileName.isEmpty())
return;
m_sfm_data_filename = sfm_data_fileName.toStdString();
if (m_doc.loadData(sfm_data_fileName.toStdString()))
{
//Add image names in the QT tree view
{
QStandardItemModel * model = new QStandardItemModel(0,1, this);
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Views"));
m_treeView_Images->setModel(model);
for (Views::const_reverse_iterator iterV = m_doc._sfm_data.GetViews().rbegin();
iterV != m_doc._sfm_data.GetViews().rend();
++iterV)
{
const View * view = iterV->second.get();
if (m_doc._sfm_data.IsPoseAndIntrinsicDefined(view))
{
std::ostringstream os;
os << view->id_view << " " << view->s_Img_path;
model->insertRow(0);
model->setData(model->index(0, 0), QString::fromStdString(os.str()));
}
}
}
}
else
{
QMessageBox msgBox;
msgBox.setText("Cannot open the provided sfm_data file.");
msgBox.exec();
}
}