本文整理汇总了C++中QStandardItem::setFlags方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::setFlags方法的具体用法?C++ QStandardItem::setFlags怎么用?C++ QStandardItem::setFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::setFlags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setFileList
void CleanDialog::setFileList(const QString &workingDirectory, const QStringList &l)
{
d->m_workingDirectory = workingDirectory;
d->ui.groupBox->setTitle(tr("Repository: %1").
arg(QDir::toNativeSeparators(workingDirectory)));
if (const int oldRowCount = d->m_filesModel->rowCount())
d->m_filesModel->removeRows(0, oldRowCount);
QStyle *style = QApplication::style();
const QIcon folderIcon = style->standardIcon(QStyle::SP_DirIcon);
const QIcon fileIcon = style->standardIcon(QStyle::SP_FileIcon);
const QString diffSuffix = QLatin1String(".diff");
const QString patchSuffix = QLatin1String(".patch");
const QString proUserSuffix = QLatin1String(".pro.user");
const QString qmlProUserSuffix = QLatin1String(".qmlproject.user");
const QChar slash = QLatin1Char('/');
// Do not initially check patches or 'pro.user' files for deletion.
foreach(const QString &fileName, l) {
const QFileInfo fi(workingDirectory + slash + fileName);
const bool isDir = fi.isDir();
QStandardItem *nameItem = new QStandardItem(QDir::toNativeSeparators(fileName));
nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
nameItem->setIcon(isDir ? folderIcon : fileIcon);
const bool saveFile = !isDir && (fileName.endsWith(diffSuffix)
|| fileName.endsWith(patchSuffix)
|| fileName.endsWith(proUserSuffix)
|| fileName.endsWith(qmlProUserSuffix));
nameItem->setCheckable(true);
nameItem->setCheckState(saveFile ? Qt::Unchecked : Qt::Checked);
nameItem->setData(QVariant(fi.absoluteFilePath()), fileNameRole);
nameItem->setData(QVariant(isDir), isDirectoryRole);
// Tooltip with size information
if (fi.isFile()) {
const QString lastModified = fi.lastModified().toString(Qt::DefaultLocaleShortDate);
nameItem->setToolTip(tr("%1 bytes, last modified %2")
.arg(fi.size()).arg(lastModified));
}
d->m_filesModel->appendRow(nameItem);
}
for (int c = 0; c < d->m_filesModel->columnCount(); c++)
d->ui.filesTreeView->resizeColumnToContents(c);
}
示例2: populateLog
bool LogChangeWidget::populateLog(const QString &repository, const QString &commit, LogFlags flags)
{
const QString currentCommit = this->commit();
int selected = currentCommit.isEmpty() ? 0 : -1;
if (const int rowCount = m_model->rowCount())
m_model->removeRows(0, rowCount);
// Retrieve log using a custom format "Sha1:Subject [(refs)]"
GitClient *client = GitPlugin::instance()->gitClient();
QStringList arguments;
arguments << QLatin1String("--max-count=1000") << QLatin1String("--format=%h:%s %d");
arguments << (commit.isEmpty() ? QLatin1String("HEAD") : commit);
if (!(flags & IncludeRemotes))
arguments << QLatin1String("--not") << QLatin1String("--remotes");
QString output;
if (!client->synchronousLog(repository, arguments, &output, 0, VcsBasePlugin::NoOutput))
return false;
foreach (const QString &line, output.split(QLatin1Char('\n'))) {
const int colonPos = line.indexOf(QLatin1Char(':'));
if (colonPos != -1) {
QList<QStandardItem *> row;
for (int c = 0; c < ColumnCount; ++c) {
QStandardItem *item = new QStandardItem;
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
if (line.endsWith(QLatin1Char(')'))) {
QFont font = item->font();
font.setBold(true);
item->setFont(font);
}
row.push_back(item);
}
const QString sha1 = line.left(colonPos);
row[Sha1Column]->setText(sha1);
row[SubjectColumn]->setText(line.right(line.size() - colonPos - 1));
m_model->appendRow(row);
if (selected == -1 && currentCommit == sha1)
selected = m_model->rowCount() - 1;
}
}
setCurrentIndex(m_model->index(selected, 0));
return true;
}
示例3: copyUserDict
void SpellCheckWidget::copyUserDict()
{
// Get the current dictionary.
if (!ui.userDictList->selectionModel()->hasSelection()) {
return;
}
int row = ui.userDictList->selectionModel()->selectedIndexes().first().row();
QStandardItem *item = m_Model.item(row, 1);
if (!item) {
return;
}
// Get the current words, before creating so list doesn't change
QStringList words;
for (int i = 0; i < ui.userWordList->count(); ++i) {
QString word = ui.userWordList->item(i)->text();
words.append(word);
}
// Create a new dictionary
QStringList current_dicts;
for (int row = 0; row < m_Model.rowCount(); ++row) {
QStandardItem *item = m_Model.itemFromIndex(m_Model.index(row, 1));
current_dicts.append(item->text());
}
QString dict_name = item->text();
while (current_dicts.contains(dict_name)) {
dict_name += "_copy";
}
if (!createUserDict(dict_name)) {
return;
}
// Add the words to the dictionary
foreach(QString word, words) {
QListWidgetItem *item = new QListWidgetItem(word, ui.userWordList);
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui.userWordList->addItem(item);
}
示例4: editorEvent
void tst_QItemDelegate::editorEvent()
{
QFETCH(QRect, rect);
QFETCH(QString, text);
QFETCH(int, checkState);
QFETCH(int, flags);
QFETCH(bool, inCheck);
QFETCH(int, type);
QFETCH(int, button);
QFETCH(bool, edited);
QFETCH(int, expectedCheckState);
QStandardItemModel model(1, 1);
QModelIndex index = model.index(0, 0);
QVERIFY(index.isValid());
QStandardItem *item = model.itemFromIndex(index);
item->setText(text);
item->setCheckState((Qt::CheckState)checkState);
item->setFlags((Qt::ItemFlags)flags);
QStyleOptionViewItem option;
option.rect = rect;
option.state |= QStyle::State_Enabled;
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = inCheck ? qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0) : QPoint(200,200);
QEvent *event = new QMouseEvent((QEvent::Type)type,
pos,
(Qt::MouseButton)button,
(Qt::MouseButton)button,
Qt::NoModifier);
TestItemDelegate delegate;
bool wasEdited = delegate.editorEvent(event, &model, option, index);
delete event;
QApplication::processEvents();
QCOMPARE(wasEdited, edited);
QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState);
}
示例5: startElement
bool PdmlHandler::startElement(const QString & /* namespaceURI */,
const QString & /* localName */,
const QString &qName,
const QXmlAttributes &attributes)
{
qDebug("%s (%s)", __FUNCTION__, qName.toAscii().constData());
if (qName == "pdml")
{
packetCount = 0;
}
else if (qName == "packet")
{
currentItem = _model->item(packetCount, 0);
}
else if ((qName == "proto") || (qName == "field"))
{
QStandardItem *item;
if (attributes.value("hide") == "yes")
{
skip = true;
}
else
{
QString val;
val = attributes.value("showname");
if (val.isEmpty())
val = attributes.value("show");
if (!val.isEmpty())
{
item = new QStandardItem(val);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
currentItem->appendRow(item);
currentItem = item;
//qDebug("ITEM(%p) --> %s", item, attributes.value("showname").toAscii().constData());
}
else
skip = true;
}
}
return true;
}
示例6: read
void ClassesDatas::read(const QJsonObject &json){
// Clear
SuperListItem::deleteModel(m_model, false);
// Read
QJsonArray jsonList = json["classes"].toArray();
QStandardItem* item;
SystemClass* sysClass;
for (int i = 0; i < jsonList.size(); i++){
item = new QStandardItem;
sysClass= new SystemClass;
sysClass->read(jsonList[i].toObject());
item->setData(QVariant::fromValue(
reinterpret_cast<quintptr>(sysClass)));
item->setFlags(item->flags() ^ (Qt::ItemIsDropEnabled));
item->setText(sysClass->toString());
m_model->appendRow(item);
}
}
示例7: setProjectsInMenu
void MainWindow::setProjectsInMenu() {
QStandardItem* parent = projectsModel->invisibleRootItem();
ProjectFactory* pf = &(ProjectFactory::getInstance());
for (Iterator<Project> it = pf->getIterator(); !(it.isDone()); it.next()) {
QStandardItem* temp = new QStandardItem(it.current().getId()); // gonna need to manage those items, and delete them at the end of the process
temp->setFlags(temp->flags() & ~Qt::ItemIsEditable);
parent->appendRow(temp);
//parent = temp;
for(Iterator<Task> it2 = it.current().getIterator(); !(it2.isDone()); it2.next()) {
QStandardItem* temp2 = new QStandardItem(it2.current().getId());
temp2->setFlags(temp2->flags() & ~Qt::ItemIsEditable);
temp->appendRow(temp2);
if (it2.current().getTaskType()==COMPOSITE) {
for (Iterator<Task> it3 = dynamic_cast<CompositeTask&>(it2.current()).getIterator(); !(it3.isDone()); it3.next()) {
injectSubTaskInModel(temp2,it3.current());
}
}
}
}
}
示例8: convertTo
void ParserTreeItem::convertTo(QStandardItem *item) const
{
if (!item)
return;
QMap<SymbolInformation, ParserTreeItem::Ptr> map;
// convert to map - to sort it
CitSymbolInformations curHash = d->symbolInformations.constBegin();
CitSymbolInformations endHash = d->symbolInformations.constEnd();
while (curHash != endHash) {
map.insert(curHash.key(), curHash.value());
++curHash;
}
typedef QMap<SymbolInformation, ParserTreeItem::Ptr>::const_iterator MapCitSymbolInformations;
// add to item
MapCitSymbolInformations cur = map.constBegin();
MapCitSymbolInformations end = map.constEnd();
while (cur != end) {
const SymbolInformation &inf = cur.key();
ParserTreeItem::Ptr ptr = cur.value();
QStandardItem *add = new QStandardItem();
Utils::setSymbolInformationToItem(inf, add);
if (!ptr.isNull()) {
// icon
add->setIcon(ptr->icon());
// draggable
if (!ptr->symbolLocations().isEmpty())
add->setFlags(add->flags() | Qt::ItemIsDragEnabled);
// locations
add->setData(Utils::locationsToRole(ptr->symbolLocations()),
Constants::SymbolLocationsRole);
}
item->appendRow(add);
++cur;
}
}
示例9: addTableEntry
void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString tableName, QString geometryColName, QString sql )
{
//is there already a root item with the given scheme Name?
QStandardItem* schemaItem;
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 );
//there is already an item for this schema
if ( schemaItems.size() > 0 )
{
schemaItem = schemaItems.at( 0 );
}
else //create a new toplevel item for this schema
{
schemaItem = new QStandardItem( schemaName );
schemaItem->setFlags( Qt::ItemIsEnabled );
invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem );
}
//path to icon for specified type
QString typeName;
QGis::WkbType wkbType = qgisTypeFromDbType( type );
QIcon iconFile = iconForType( wkbType );
QList<QStandardItem*> childItemList;
QStandardItem* schemaNameItem = new QStandardItem( schemaName );
schemaNameItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QStandardItem* typeItem = new QStandardItem( QIcon( iconFile ), type );
typeItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QStandardItem* tableItem = new QStandardItem( tableName );
tableItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QStandardItem* geomItem = new QStandardItem( geometryColName );
geomItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QStandardItem* sqlItem = new QStandardItem( sql );
sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
childItemList.push_back( schemaNameItem );
childItemList.push_back( tableItem );
childItemList.push_back( typeItem );
childItemList.push_back( geomItem );
childItemList.push_back( sqlItem );
schemaItem->appendRow( childItemList );
++mTableCount;
}
示例10:
void
MSCalibrationForm::setCalibrateMethod( const adcontrols::MSCalibrateMethod& method )
{
QStandardItemModel& model = *pModel_;
ui->spinPolynomials->setValue( method.polynomialDegree() );
ui->spinMassTolerance->setValue( method.massToleranceDa() );
ui->spinMinimumRA->setValue( method.minimumRAPercent() );
ui->spinLowMass->setValue( method.lowMass() );
ui->spinHighMass->setValue( method.highMass() );
const adcontrols::MSReferences& references = method.references();
int nRows = static_cast<int>( references.size() );
if ( nRows < model.rowCount() )
model.removeRows( 0, model.rowCount() ); // make sure all clear
model.setRowCount( nRows + 1 ); // be sure last empty line
int row = 0;
for ( auto& ref: references ) {
std::wstring formula = ref.display_formula();
model.setData( model.index( row, c_formula ), qtwrapper::qstring::copy( formula ) );
model.setData( model.index( row, c_exact_mass ), ref.exact_mass() );
model.setData( model.index( row, c_enable ), ref.enable() );
QStandardItem * chk = model.itemFromIndex( model.index( row, c_enable ) );
if ( chk ) {
chk->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
chk->setEditable( true );
model.setData( model.index( row, c_enable ), ref.enable() ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
}
model.setData( model.index( row, c_description ), qtwrapper::qstring::copy( ref.description() ) );
model.setData( model.index( row, c_charge ), ref.charge_count() );
++row;
}
}
示例11: PopulateDataContainerComboBox
static void PopulateDataContainerComboBox(AbstractFilter* filter, FilterParameter* filterParameter,
QComboBox* dcCombo, DataContainerArrayProxy& dcaProxy)
{
FilterParameterType* fp = dynamic_cast<FilterParameterType*>(filterParameter);
assert(fp != NULL);
DataContainerArray::Pointer dca = filter->getDataContainerArray();
// Populate the DataContainerArray Combo Box with all the DataContainers
QList<DataContainerProxy> dcList = dcaProxy.dataContainers.values();
QListIterator<DataContainerProxy> iter(dcList);
dcCombo->clear();
QVector<unsigned int> defVec = fp->getDefaultGeometryTypes();
while(iter.hasNext() )
{
DataContainerProxy dcProxy = iter.next();
DataContainer::Pointer dc = dca->getDataContainer(dcProxy.name);
IGeometry::Pointer geom = IGeometry::NullPointer();
uint32_t geomType = 999;
if (NULL != dc.get()) { geom = dc->getGeometry(); }
if (NULL != geom.get()) { geomType = geom->getGeometryType(); }
dcCombo->addItem(dcProxy.name);
if (defVec.isEmpty() == false)
{
if (defVec.contains(geomType) == false)
{
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(dcCombo->model());
if (NULL != model)
{
QStandardItem* item = model->item(dcCombo->findText(dcProxy.name));
if (NULL != item)
{
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
}
}
}
}
}
}
示例12: setDefault
void StatusDatas::setDefault() {
int i, length;
SystemStatus *status;
QStandardItem *item;
QString names[] = {
"KO"
};
int iconsID[] = {
-1
};
length = (sizeof(names)/sizeof(*names));
for (i = 0; i < length; i++) {
status = new SystemStatus(i + 1, new LangsTranslation(names[i]),
iconsID[i]);
item = new QStandardItem;
item->setData(QVariant::fromValue(reinterpret_cast<quintptr>(status)));
item->setFlags(item->flags() ^ (Qt::ItemIsDropEnabled));
item->setText(status->toString());
m_model->appendRow(item);
}
}
示例13: QStandardItem
QList<QStandardItem*> DkFileAssociationsPreference::getItems(const QString& filter, bool browse, bool reg) {
QList<QStandardItem* > items;
QStandardItem* item = new QStandardItem(filter);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
items.append(item);
item = new QStandardItem("");
//item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
item->setCheckable(true);
item->setCheckState(browse ? Qt::Checked : Qt::Unchecked);
items.append(item);
item = new QStandardItem("");
//item->setFlags(Qt::Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
item->setCheckable(true);
item->setCheckState(reg ? Qt::Checked : Qt::Unchecked);
#ifndef Q_OS_WIN // registering is windows only
item->setEnabled(false);
#endif
items.append(item);
return items;
}
示例14: addCookie
void CookiesContentsWidget::addCookie(const QNetworkCookie &cookie)
{
const QString domain = (cookie.domain().startsWith('.') ? cookie.domain().mid(1) : cookie.domain());
QStandardItem *domainItem = findDomain(domain);
if (domainItem)
{
for (int i = 0; i < domainItem->rowCount(); ++i)
{
if (domainItem->child(i, 0)->text() == cookie.name() && domainItem->child(i, 0)->data(Qt::UserRole).toString() == cookie.path())
{
return;
}
}
}
else
{
domainItem = new QStandardItem(HistoryManager::getIcon(QUrl(QStringLiteral("http://%1/").arg(domain))), domain);
domainItem->setToolTip(domain);
m_model->appendRow(domainItem);
if (sender())
{
m_model->sort(0);
}
}
QStandardItem *cookieItem = new QStandardItem(QString(cookie.name()));
cookieItem->setData(cookie.path(), Qt::UserRole);
cookieItem->setData(cookie.domain(), (Qt::UserRole + 1));
cookieItem->setToolTip(cookie.name());
cookieItem->setFlags(cookieItem->flags() | Qt::ItemNeverHasChildren);
domainItem->appendRow(cookieItem);
domainItem->setText(QStringLiteral("%1 (%2)").arg(domain).arg(domainItem->rowCount()));
}
示例15: model
void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
{
QStandardItemModel model(3, 1);
for (int i = 0; i < 3; ++i) {
QStandardItem *item = new QStandardItem(QLatin1String("Item ") + QString::number(i));
item->setCheckable(true);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
model.setItem(i, item);
}
QTableView view;
view.setModel(&model);
view.setItemDelegate(new TestItemDelegate);
view.show();
view.selectAll();
QTest::qWaitForWindowShown(&view);
QStyleOptionViewItem option;
option.rect = view.visualRect(model.index(0, 0));
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos);
QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex()));
QCOMPARE(model.item(0)->checkState(), Qt::Checked);
}