本文整理汇总了C++中QTreeWidgetItem::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeWidgetItem::setData方法的具体用法?C++ QTreeWidgetItem::setData怎么用?C++ QTreeWidgetItem::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findShapes
void Tessellation::findShapes()
{
App::Document* activeDoc = App::GetApplication().getActiveDocument();
if (!activeDoc) return;
Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc);
if (!activeGui) return;
this->document = QString::fromAscii(activeDoc->getName());
std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>();
double edgeLen = 0;
bool foundSelection = false;
for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) {
const TopoDS_Shape& shape = (*it)->Shape.getValue();
if (shape.IsNull()) continue;
bool hasfaces = false;
TopExp_Explorer xp(shape,TopAbs_FACE);
while (xp.More()) {
hasfaces = true;
break;
}
if (hasfaces) {
Base::BoundBox3d bbox = (*it)->Shape.getBoundingBox();
edgeLen = std::max<double>(edgeLen, bbox.LengthX());
edgeLen = std::max<double>(edgeLen, bbox.LengthY());
edgeLen = std::max<double>(edgeLen, bbox.LengthZ());
QString label = QString::fromUtf8((*it)->Label.getValue());
QString name = QString::fromAscii((*it)->getNameInDocument());
QTreeWidgetItem* child = new QTreeWidgetItem();
child->setText(0, label);
child->setToolTip(0, label);
child->setData(0, Qt::UserRole, name);
Gui::ViewProvider* vp = activeGui->getViewProvider(*it);
if (vp) child->setIcon(0, vp->getIcon());
ui->treeWidget->addTopLevelItem(child);
if (Gui::Selection().isSelected(*it)) {
child->setSelected(true);
foundSelection = true;
}
}
}
ui->spinMaximumEdgeLength->setValue(edgeLen/10);
if (foundSelection)
ui->treeWidget->hide();
}
示例2: defined
void QgsVectorGradientColorRampV2Dialog::addStop()
{
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// also Qt 4.7 Mac Cocoa bug: calling QInputDialog::getInt after QColorDialog::getColor will freeze app
// workaround: call QColorDialog::getColor below instead of here,
// but not needed at this time because of the other Qt bug
// FIXME need to also check max QT_VERSION when Qt bug(s) fixed
QColor color = QColorDialog::getColor( QColor(), this, "", QColorDialog::DontUseNativeDialog );
#else
QColor color = QColorDialog::getColor( QColor(), this );
#endif
if ( !color.isValid() )
return;
bool ok;
int val = 50;
#if QT_VERSION >= 0x40500
val = QInputDialog::getInt( this, tr( "Offset of the stop" ),
tr( "Please enter offset in percents (%) of the new stop" ),
val, 0, 100, 1, &ok );
#else
QString res = QInputDialog::getText( this, tr( "Offset of the stop" ),
tr( "Please enter offset in percents (%) of the new stop" ),
QLineEdit::Normal, QString::number( val ), &ok );
if ( ok )
val = res.toInt( &ok );
if ( ok )
ok = val >= 0 && val <= 100;
#endif
if ( !ok )
return;
double key = val / 100.0;
QStringList lst;
lst << "." << QString::number( val, 'f', 0 );
QTreeWidgetItem* item = new QTreeWidgetItem( lst );
setStopColor( item, color );
item->setData( 0, StopOffsetRole, key );
treeStops->addTopLevelItem( item );
treeStops->resizeColumnToContents( 0 );
updatePreview();
}
示例3: addCollectionsToTree
// Add collection data to CollectionTree under specified item
void UChromaWindow::addCollectionsToTree(Collection* collection, QTreeWidgetItem* parent)
{
// Add on collection item
QTreeWidgetItem* item;
if (parent) item = new QTreeWidgetItem(parent, 0);
else item = new QTreeWidgetItem(ui.CollectionTree, 0);
// Set item information
item->setData(0, Qt::UserRole, VariantPointer<Collection>(collection));
updateCollectionTreeItem(item);
item->setExpanded(true);
// Add any additional data
for (Collection* fit = collection->fits(); fit != NULL; fit = fit->next) addCollectionsToTree(fit, item);
for (Collection* extract = collection->slices(); extract != NULL; extract = extract->next) addCollectionsToTree(extract, item);
}
示例4: addAttribute
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget );
newItem->setText( 0, item->text( 0 ) );
newItem->setData( 0, Qt::UserRole, item->data( 0, Qt::UserRole ) );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
//set initial color for diagram category
int red = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int green = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int blue = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
QColor randomColor( red, green, blue );
newItem->setBackground( 1, QBrush( randomColor ) );
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
}
示例5: onListTestsFinished
void TestListView::onListTestsFinished(void) {
// sanity check
Q_ASSERT_X(m_runner, Q_FUNC_INFO, "null test runner");
if ( m_runner == 0 )
return;
// clear any previous data (necessary here?)
clear();
// foreach program
const int numPrograms = m_runner->programCount();
for ( int i = 0; i < numPrograms; ++i ) {
TestProgram* program = m_runner->programAt(i);
Q_ASSERT_X(program, Q_FUNC_INFO, "null test program");
// create top-level item for program
QTreeWidgetItem* programItem = new QTreeWidgetItem;
programItem->setData(0, Qt::DisplayRole, program->programName());
programItem->setData(0, Qt::UserRole, QVariant::fromValue(program));
// programItem->setCheckState(0, Qt::Checked);
// foreach test suite
const int numSuites = program->suiteCount();
for ( int j = 0; j < numSuites; ++j ) {
TestSuite* suite = program->suiteAt(j);
Q_ASSERT_X(suite, Q_FUNC_INFO, "null test suite");
// create item for suite
QTreeWidgetItem* suiteItem = new QTreeWidgetItem(programItem);
suiteItem->setData(0, Qt::DisplayRole, suite->name());
suiteItem->setData(0, Qt::UserRole, QVariant::fromValue(suite));
// suiteItem->setCheckState(0, Qt::Checked);
// foreach test case
const int numTests = suite->testCount();
for ( int k = 0; k < numTests; ++k ) {
TestCase* test = suite->testAt(k);
Q_ASSERT_X(test, Q_FUNC_INFO, "null test case");
// create item for test
QTreeWidgetItem* testItem = new QTreeWidgetItem(suiteItem);
testItem->setData(0, Qt::DisplayRole, test->name());
testItem->setData(0, Qt::UserRole, QVariant::fromValue(test));
// testItem->setCheckState(0, Qt::Checked);
}
}
// add program item to table
addTopLevelItem(programItem);
}
// start with all items collapsed
collapseAll();
}
示例6: fillChannelsTrees
void AddChannelsDialog::fillChannelsTrees(QList<QLCChannel *> allList, QList<QLCChannel *> modeList)
{
int i = 0;
foreach (QLCChannel *ch, allList)
{
QTreeWidgetItem *item = NULL;
if (modeList.contains(ch) == false)
item = new QTreeWidgetItem(m_allTree);
else
item = new QTreeWidgetItem(m_modeTree);
item->setText(0, ch->name());
item->setIcon(0, ch->getIconFromGroup(ch->group()));
item->setData(0, Qt::UserRole, QVariant(i));
i++;
}
示例7: Insert
/**
* Inserts widget to be layed out.
*
* @param widget ContactWidget object to display.
* @param key Grouping object.
*/
void Insert(ContactWidget* widget, const T key){
if (!map_.contains(key)) {
QTreeWidgetItem* item = new QTreeWidgetItem;
item->setData(0, Qt::DisplayRole, titler_(widget, key));
item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
items_[key] = item;
tree_->addTopLevelItem(item);
}
map_.insert(key, widget);
QTreeWidgetItem* item = new QTreeWidgetItem;
items_[key]->addChild(item);
items_[key]->setExpanded(true);
tree_->setItemWidget(item, 0, widget);
// sort childern, which causes them to recalculate stylesheet and hide indentation
items_[key]->sortChildren(0, Qt::AscendingOrder);
}
示例8: handleFeedStateChanged
void FeedListWidget::handleFeedStateChanged(RSS::Feed *feed)
{
QTreeWidgetItem *item = m_rssToTreeItemMapping.value(feed);
Q_ASSERT(item);
QIcon icon;
if (feed->isLoading())
icon = QIcon(QStringLiteral(":/icons/loading.png"));
else if (feed->hasError())
icon = GuiIconProvider::instance()->getIcon(QStringLiteral("unavailable"));
else if (!feed->iconPath().isEmpty())
icon = QIcon(feed->iconPath());
else
icon = GuiIconProvider::instance()->getIcon(QStringLiteral("application-rss+xml"));
item->setData(0, Qt::DecorationRole, icon);
}
示例9: buildJsonTree
void MainWindow::buildJsonTree(QTreeWidgetItem *parent, QJsonValue &obj, QString key = "")
{
QTreeWidgetItem *toAdd = NULL;
switch(obj.type())
{
case QJsonValue::Bool:
case QJsonValue::Double:
case QJsonValue::String:
case QJsonValue::Undefined:
case QJsonValue::Null:
toAdd = createJsonTreeLeaf(parent, obj, key);
break;
case QJsonValue::Array:
{
toAdd = new QTreeWidgetItem(parent);
QJsonArray array = obj.toArray();
int count = array.count();
toAdd->setText(0, key+"["+QString::number(count)+"]");
for(int i = 0; i < count; ++i)
{
QJsonValue val = array.at(i);
buildJsonTree(toAdd, val, QString::number(i)+" : ");
}
break;
}
case QJsonValue::Object:
{
toAdd = new QTreeWidgetItem(parent);
QJsonObject object = obj.toObject();
int count = object.count();
toAdd->setText(0, key+"{"+QString::number(count)+"}");
for(QJsonObject::ConstIterator i = object.begin(); i != object.end(); ++i)
{
QJsonValue val = i.value();
buildJsonTree(toAdd, val, i.key()+" : ");
}
break;
}
default:
break;
}
toAdd->setData(0, Qt::UserRole, QVariant(obj));
parent->addChild(toAdd);
}
示例10: sortItems
void VAttachmentList::sortItems()
{
const QVector<VAttachment> &attas = m_file->getAttachments();
if (attas.size() < 2) {
return;
}
VSortDialog dialog(tr("Sort Attachments"),
tr("Sort attachments of note <span style=\"%1\">%2</span> "
"in the configuration file.")
.arg(g_config->c_dataTextStyle)
.arg(m_file->getName()),
g_mainWin);
QTreeWidget *tree = dialog.getTreeWidget();
tree->clear();
tree->setColumnCount(1);
QStringList headers(tr("Name"));
tree->setHeaderLabels(headers);
for (int i = 0; i < attas.size(); ++i) {
QTreeWidgetItem *item = new QTreeWidgetItem(tree, QStringList(attas[i].m_name));
item->setData(0, Qt::UserRole, i);
}
dialog.treeUpdated();
if (dialog.exec()) {
QVector<QVariant> data = dialog.getSortedData();
Q_ASSERT(data.size() == attas.size());
QVector<int> sortedIdx(data.size(), -1);
for (int i = 0; i < data.size(); ++i) {
sortedIdx[i] = data[i].toInt();
}
if (!m_file->sortAttachments(sortedIdx)) {
VUtils::showMessage(QMessageBox::Warning,
tr("Warning"),
tr("Fail to sort attachments of note <span style=\"%1\">%2</span>.")
.arg(g_config->c_dataTextStyle)
.arg(m_file->getName()),
"",
QMessageBox::Ok,
QMessageBox::Ok,
this);
}
}
}
示例11: init
void DataInspectionDialog::init(bool isInd,const QString &src, const QString &bn,
ImageFileType ft,int nImgs)
{
// note that fileType should never be allowed to be RAW
individual = isInd;
path = src;
baseName = bn;
fileType = ft;
expectedNImages = nImgs;
PreviousButton->setEnabled(false);
if (individual) {
// if individual, disable all control buttons, no need for tree
NextButton->setEnabled(false);
Subject_ID_Text->setEnabled(false);
SubjectsTree->setEnabled(false);
}
else {
QStringList subjects = QDir(path).entryList(QDir::NoDotAndDotDot | QDir::AllDirs);
nSubjects = subjects.size();
NextButton->setEnabled(nSubjects > 1);
// identify first subject
Subject_ID_Text->setText("Subject ID: "+subjects.first());
SubjectsTree->clear();
// prepare tree
for (int i =0; i<subjects.size();i++) {
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setData(0,Qt::CheckStateRole,true);
item->setText(1,subjects.at(i));
item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsUserCheckable);
SubjectsTree->insertTopLevelItem(i,item);
}
SubjectsTree->setColumnWidth(0,36);
SubjectsTree->setColumnWidth(1,64);
SubjectsTree->setCurrentItem(SubjectsTree->invisibleRootItem()->child(0));
}
subjectIndex = 0;
imageIndex = 0;
// prepare color table
for (int i = 0;i<256;i++)
cTable.append(qRgb( i, i, i ));
// load image
clearDisplay();
data.clear();
updateSubject();
}
示例12: addColumn
void ColumnPreferencesFrame::addColumn(bool visible, const char *title, int fmt, const char *custom_fields, int custom_occurrence)
{
QTreeWidgetItem *item = new QTreeWidgetItem(ui->columnTreeWidget);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));
item->setCheckState(visible_col_, visible ? Qt::Checked : Qt::Unchecked);
item->setText(title_col_, title);
item->setText(type_col_, col_format_desc(fmt));
item->setData(type_col_, Qt::UserRole, QVariant(fmt));
if (fmt == COL_CUSTOM) {
item->setText(custom_fields_col_, custom_fields);
item->setText(custom_occurrence_col_, QString::number(custom_occurrence));
}
updateWidgets();
}
示例13: UpdateScene
void QSceneTreeWidget::UpdateScene(c4g::scene::ISceneImpl* const& rpScene)
{
clear();
scene::IPanel* const& panel_ptr = rpScene->GetPanel();
QTreeWidgetItem* item = new QTreeWidgetItem(this);
item->setData(0, Qt::UserRole, qVariantFromValue((void*)panel_ptr));
item->setText(0, panel_ptr->id.c_str());
item->setToolTip(0, item->text(0));
item->setText(1, panel_ptr->class_name.c_str());
item->setToolTip(1, item->text(1));
addTopLevelItem(item);
m_vItemPtr.push_back(item);
panel_ptr->Visit(this);
}
示例14: apiReplyReceived
void songDbBrowser::apiReplyReceived()
{
QXmlStreamReader xml;
xml.addData( apiReply->readAll() );
if( xml.readNextStartElement() )
{
if(xml.name() == "genres")
{
ui->genres->clear();
ui->genres->addItem(tr("-- ALL --"),"*");
while(xml.readNextStartElement())
{
if( xml.name() == "genre")
{
ui->genres->addItem(
xml.attributes().value("name").toString(),
xml.attributes().value("id").toString()
);
}
xml.skipCurrentElement();
}
}
if(xml.name() == "songs")
{
ui->songList->clear();
ui->songList->setColumnHidden( 4, true );
while(xml.readNextStartElement())
{
if( xml.name() == "song")
{
QTreeWidgetItem* itm = new QTreeWidgetItem( ui->songList );
itm->setText( 0, xml.attributes().value("title").toString() );
itm->setText( 1, xml.attributes().value("interpret").toString() );
itm->setText( 2, xml.attributes().value("genre").toString() );
itm->setText( 3, xml.attributes().value("length").toString() );
itm->setData( 4, Qt::UserRole, xml.attributes().value("id").toString() );
}
xml.skipCurrentElement();
}
ui->songList->resizeColumnToContents(0);
ui->songList->resizeColumnToContents(1);
}
xml.skipCurrentElement();
}
apiReply->deleteLater();
}
示例15: startFetchingIcons
void BookmarksImportDialog::startFetchingIcons()
{
ui->nextButton->setText(tr("Finish"));
ui->nextButton->setEnabled(false);
ui->progressBar->setValue(0);
ui->progressBar->setMaximum(m_exportedBookmarks.count());
m_fetcherThread = new QThread();
m_fetcher = new BookmarksImportIconFetcher();
m_fetcher->moveToThread(m_fetcherThread);
QIcon defaultIcon = qIconProvider->emptyWebIcon();
QIcon folderIcon = style()->standardIcon(QStyle::SP_DirIcon);
QHash<QString, QTreeWidgetItem*> hash;
foreach(const Bookmark & b, m_exportedBookmarks) {
QTreeWidgetItem* item;
QTreeWidgetItem* findParent = hash[b.folder];
if (findParent) {
item = new QTreeWidgetItem(findParent);
}
else {
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->treeWidget);
newParent->setText(0, b.folder);
newParent->setIcon(0, folderIcon);
ui->treeWidget->addTopLevelItem(newParent);
hash[b.folder] = newParent;
item = new QTreeWidgetItem(newParent);
}
QVariant bookmarkVariant = qVariantFromValue(b);
item->setText(0, b.title);
if (b.image.isNull()) {
item->setIcon(0, defaultIcon);
}
else {
item->setIcon(0, QIcon(QPixmap::fromImage(b.image)));
}
item->setText(1, b.url.toString());
item->setData(0, Qt::UserRole + 10, bookmarkVariant);
ui->treeWidget->addTopLevelItem(item);
m_fetcher->addEntry(b.url, item);
}