本文整理汇总了C++中QStandardItem::appendRow方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::appendRow方法的具体用法?C++ QStandardItem::appendRow怎么用?C++ QStandardItem::appendRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::appendRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AMBottomBar
bool AMDatamanAppControllerForActions2::startupCreateUserInterface()
{
AMErrorMon::information(this, AMDATAMANAPPCONTROLLER_STARTUP_MESSAGES, "Acquaman Startup: Populating User Interface");
qApp->processEvents();
settingsMasterView_ = 0;
issueSubmissionView_ = 0;
bottomBar_ = new AMBottomBar();
// These buttons are never used. Hiding them.
bottomBar_->fullScreenButton->hide();
bottomBar_->adjustScanFinishButton->hide();
bottomBar_->restartScanButton->hide();
mw_->addBottomWidget(bottomBar_);
connect(bottomBar_, SIGNAL(addButtonClicked()), this, SLOT(onAddButtonClicked()));
connect(bottomBar_, SIGNAL(pauseScanIssued()), this, SIGNAL(pauseScanIssued()));
connect(bottomBar_, SIGNAL(resumeScanIssued()), this, SIGNAL(resumeScanIssued()));
connect(bottomBar_, SIGNAL(stopScanIssued()), this, SIGNAL(stopScanIssued()));
// Create panes in the main window:
////////////////////////////////////
// A heading for the scan editors
scanEditorsParentItem_ = mw_->windowPaneModel()->headingItem("Open Scans");
// Make a dataview widget and add it under two links/headings: "Runs" and "Experiments". See AMMainWindowModel for more information.
////////////////////////////////////
dataView_ = new AMDataViewWithActionButtons();
dataView_->setWindowTitle("Data");
QStandardItem* dataViewItem = new QStandardItem();
dataViewItem->setData(qVariantFromValue((QWidget*)dataView_), AM::WidgetRole);
dataViewItem->setFlags(Qt::ItemIsEnabled); // enabled, but should not be selectable
QFont font = QFont("Lucida Grande", 10, QFont::Bold);
font.setCapitalization(QFont::AllUppercase);
dataViewItem->setFont(font);
dataViewItem->setData(QBrush(QColor::fromRgb(100, 109, 125)), Qt::ForegroundRole);
dataViewItem->setData(true, AMWindowPaneModel::DockStateRole);
mw_->windowPaneModel()->appendRow(dataViewItem);
runsParentItem_ = new QStandardItem(QIcon(":/22x22/view_calendar_upcoming_days.png"), "Runs");
mw_->windowPaneModel()->initAliasItem(runsParentItem_, dataViewItem, "Runs", -1);
dataViewItem->appendRow(runsParentItem_);
experimentsParentItem_ = new QStandardItem(QIcon(":/applications-science.png"), "Experiments");
mw_->windowPaneModel()->initAliasItem(experimentsParentItem_, dataViewItem, "Experiments", -1);
dataViewItem->appendRow(experimentsParentItem_);
// Hook into the sidebar and add Run and Experiment links below these headings.
runExperimentInsert_ = new AMRunExperimentInsert(AMDatabase::database("user"), runsParentItem_, experimentsParentItem_, this);
connect(runExperimentInsert_, SIGNAL(newExperimentAdded(QModelIndex)), this, SLOT(onNewExperimentAdded(QModelIndex)));
// connect the activated signal from the dataview to our own slot
connect(dataView_, SIGNAL(selectionActivated(QList<QUrl>)), this, SLOT(onDataViewItemsActivated(QList<QUrl>)));
connect(dataView_, SIGNAL(selectionActivatedSeparateWindows(QList<QUrl>)), this, SLOT(onDataViewItemsActivatedSeparateWindows(QList<QUrl>)));
connect(dataView_, SIGNAL(selectionExported(QList<QUrl>)), this, SLOT(onDataViewItemsExported(QList<QUrl>)));
connect(dataView_, SIGNAL(launchScanConfigurationsFromDb(QList<QUrl>)), this, SLOT(onLaunchScanConfigurationsFromDb(QList<QUrl>)));
connect(dataView_, SIGNAL(fixCDF(QUrl)), this, SLOT(fixCDF(QUrl)));
// When 'alias' links are clicked in the main window sidebar, we might need to notify some widgets of the details
connect(mw_, SIGNAL(aliasItemActivated(QWidget*,QString,QVariant)), this, SLOT(onMainWindowAliasItemActivated(QWidget*,QString,QVariant)));
/////////////////////////
// Make connections:
//////////////////////////////
connect(mw_, SIGNAL(currentPaneChanged(QWidget*)), this, SLOT(onCurrentPaneChanged(QWidget*)));
// show main window
mw_->show();
return true;
}
示例2: addUdpNode
void AnalysisThread::addUdpNode(int protoInd)
{
struct udphdr* pudp_header = (struct udphdr *)this->snifferData.protocalVec.at(protoInd)->pProtocal;
QStandardItem* udpitem = new QStandardItem();
this->len = sizeof(struct udphdr);
setUserRoleData(udpitem);
QStandardItem* item = new QStandardItem();
uint16_t src_port = ntohs(pudp_header->source);
this->len = sizeof(src_port);
item->setText(QString("Source port: %1").arg(src_port));
setUserRoleData(item);
udpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
uint16_t dst_port = ntohs(pudp_header->dest);
this->len = sizeof(dst_port);
item->setText(QString("Destination port: %1").arg(dst_port));
setUserRoleData(item);
udpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
u_int16_t len = ntohs(pudp_header->len);
this->len = sizeof(len);
item->setText(QString("Length: %1").arg(len));
setUserRoleData(item);
udpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
u_int16_t check = ntohs(pudp_header->check);
this->len = sizeof(check);
item->setText(QString("Checksum: 0x%1 [validation disabled]")
.arg(check,0,16));
setUserRoleData(item);
udpitem->appendRow(item);
this->offset += this->len;
udpitem->setText(QString("User Datagram Protocol, Src Port: %1, Dst Port: %2")
.arg(src_port)
.arg(dst_port));
this->model->setItem(this->irow++, 0, udpitem);
// Add the application data, we just analysis ssdp
ApplicationData* pad = NULL;
try{
pad = static_cast<ApplicationData*>(this->snifferData.
protocalVec.at(protoInd+1)->pProtocal);
} catch(std::exception)
{
return;
}
if (pad == NULL)
{
return;
}
if (pad->strProtocal == SnifferType::SSDP_PROTOCAL)
{
addHttpNode(pad);
}
}
示例3: addEtherNode
void AnalysisThread::addEtherNode(int protoInd)
{
SnifferProtocal* psp = this->snifferData.protocalVec.at(protoInd);
struct ether_header* pether_header = (struct ether_header *)psp->pProtocal;
QStandardItem* etheritem = new QStandardItem();
this->offset = 0;
this->len = sizeof(struct ether_header);
setUserRoleData(etheritem);
QString tmpmacDst = SnifferUtil::macToHost(pether_header->ether_dhost);
QString tmpmacSrc = SnifferUtil::macToHost(pether_header->ether_shost);
etheritem->setText(QString("Ethernet V2, Src: %1, Dst: %2")
.arg(tmpmacSrc)
.arg(tmpmacDst));
// Destination
QStandardItem* item = new QStandardItem();
item->setText("Destination: " + tmpmacDst);
this->len = sizeof(pether_header->ether_dhost);
setUserRoleData(item);
QStandardItem* childitem = new QStandardItem();
this->len = sizeof(pether_header->ether_dhost);
setUserRoleData(childitem);
childitem->setText("Address: " + tmpmacDst);
item->appendRow(childitem);
childitem = new QStandardItem();
if (SnifferUtil::getBit(pether_header->ether_dhost[1], 6))
{
childitem->setText(QString(".... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)"));
}
else
{
childitem->setText(QString(".... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)"));
}
this->len = 3;
setUserRoleData(childitem);
item->appendRow(childitem);
childitem = new QStandardItem();
if (SnifferUtil::getBit(pether_header->ether_dhost[1], 7))
{
childitem->setText(QString(".... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)"));
}
else
{
childitem->setText(QString(".... ...0 .... .... .... .... = IG bit: Individual address (unicast)"));
}
setUserRoleData(childitem);
item->appendRow(childitem);
etheritem->appendRow(item);
this->offset += sizeof(pether_header->ether_dhost);
// Source
item = new QStandardItem();
item->setText("Source: " + tmpmacSrc);
this->len = sizeof(pether_header->ether_shost);
setUserRoleData(item);
childitem = new QStandardItem();
this->len = sizeof(pether_header->ether_shost);
setUserRoleData(childitem);
childitem->setText("Address: " + tmpmacSrc);
item->appendRow(childitem);
childitem = new QStandardItem();
if (SnifferUtil::getBit(pether_header->ether_shost[1], 6))
{
childitem->setText(QString(".... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)"));
}
else
{
childitem->setText(QString(".... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)"));
}
this->len = 3;
setUserRoleData(childitem);
item->appendRow(childitem);
childitem = new QStandardItem();
if (SnifferUtil::getBit(pether_header->ether_shost[1], 7))
{
childitem->setText(QString(".... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)"));
}
else
{
childitem->setText(QString(".... ...0 .... .... .... .... = IG bit: Individual address (unicast)"));
}
setUserRoleData(childitem);
item->appendRow(childitem);
etheritem->appendRow(item);
this->offset += sizeof(pether_header->ether_shost);
// Get the protocal type
int type = ntohs(pether_header->ether_type);
//.........这里部分代码省略.........
示例4: addAssociation
/**
\brief Add an ICD association \e asso to the model.
This member will firstly check if the association can be added to the model.
*/
bool IcdCollectionModel::addAssociation(const Internal::IcdAssociation &asso)
{
// Can add this association ?
if (!canAddThisAssociation(asso)) {
Utils::Log::addError(this, tr("Can not add this Association: %1-%2")
.arg(icdBase()->getIcdCode(asso.mainSid()).toString())
.arg(icdBase()->getIcdCode(asso.associatedSid()).toString()));
return false;
}
// add Code to model
d->m_SIDs.append(asso.mainSid().toInt());
d->m_SIDs.append(asso.associatedSid().toInt());
// Find root item (mainItem) based on the SID
QStandardItem *parentItem = 0;
QStandardItem *main = 0;
QList<QStandardItem *> list;
if (asso.mainIsDag()) {
list = findItems(asso.mainCodeWithDagStar(), Qt::MatchExactly, 0);
} else {
list = findItems(asso.associatedCodeWithDagStar(), Qt::MatchExactly, 0);
}
if (list.count()==0) {
parentItem = invisibleRootItem();
if (asso.mainIsDag()) {
main = new QStandardItem(asso.mainCodeWithDagStar());
list
<< main
<< new QStandardItem(asso.mainLabel())
<< new QStandardItem(asso.mainCode()) // Code without daget
<< new QStandardItem(asso.mainDaget()) // Human readable daget
<< new QStandardItem(asso.dagCode()) // DagCode
<< new QStandardItem(asso.mainSid().toString())
;
} else {
main = new QStandardItem(asso.associatedCodeWithDagStar());
list
<< main
<< new QStandardItem(asso.associatedLabel())
<< new QStandardItem(asso.associatedCode()) // Code without daget
<< new QStandardItem(asso.associatedDaget()) // Human readable daget
<< new QStandardItem(icdBase()->invertDagCode(asso.dagCode()))
<< new QStandardItem(asso.associatedSid().toString())
;
}
parentItem->appendRow(list);
parentItem = main;
} else {
parentItem = list.at(0);
}
list.clear();
if (asso.mainIsDag()) {
list
<< new QStandardItem(asso.associatedCodeWithDagStar())
<< new QStandardItem(asso.associatedLabel())
<< new QStandardItem(asso.associatedCode()) // Code without daget
<< new QStandardItem(asso.associatedDaget()) // Human readable daget
<< new QStandardItem(icdBase()->invertDagCode(asso.dagCode()))
<< new QStandardItem(asso.associatedSid().toString())
;
} else {
list
<< new QStandardItem(asso.mainCodeWithDagStar())
<< new QStandardItem(asso.mainLabel())
<< new QStandardItem(asso.mainCode()) // Code without daget
<< new QStandardItem(asso.mainDaget()) // Human readable daget
<< new QStandardItem(asso.dagCode()) // DagCode
<< new QStandardItem(asso.mainSid().toString())
;
}
parentItem->appendRow(list);
// get all exclusions
if (asso.mainIsDag()) {
d->m_ExcludedSIDs << icdBase()->getExclusions(asso.mainSid());
} else {
d->m_ExcludedSIDs << icdBase()->getExclusions(asso.associatedSid());
}
return true;
}
示例5: addArpNode
void AnalysisThread::addArpNode(int protoInd)
{
struct ether_arp* parp_header = (struct ether_arp *)this->snifferData.protocalVec.at(protoInd)->pProtocal;
QStandardItem* arpitem = new QStandardItem();
this->len = sizeof(struct ether_arp);
unsigned short int op = ntohs(parp_header->ea_hdr.ar_op);
if (op == 0x01)
{
arpitem->setText("Address Resolution Protocol (request)");
}
else if (op == 0x02)
{
arpitem->setText("Address Resolution Protocol (response)");
}
setUserRoleData(arpitem);
// Hardware type, here we just analysis the Ether type
QStandardItem* item = new QStandardItem();
if (ntohs(parp_header->ea_hdr.ar_hrd) == 0x01)
{
item->setText("Hardware type: Ethernet (1)");
}
else
{
item->setText(QString("Hardware type: 1%").arg(ntohs(parp_header->ea_hdr.ar_hrd)));
}
this->len = sizeof(parp_header->ea_hdr.ar_hrd);
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
// Protocal type, here we just analysis the ip type
item = new QStandardItem();
if (ntohs(parp_header->ea_hdr.ar_pro) == 0x0800)
{
item->setText("Protocol type: IP (0x0800)");
}
else
{
item->setText(QString("Protocol type: %1").arg(ntohs(parp_header->ea_hdr.ar_pro)));
}
this->len = sizeof(parp_header->ea_hdr.ar_pro);
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
// hardware size and protocal size
item = new QStandardItem();
this->len = sizeof(parp_header->ea_hdr.ar_hln);
item->setText(QString("Hardware size: %1").arg(parp_header->ea_hdr.ar_hln));
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
this->len = sizeof(parp_header->ea_hdr.ar_pln);
item->setText(QString("Protocal size: %1").arg(parp_header->ea_hdr.ar_pln));
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
this->len = sizeof(op);
if (op == 0x01)
{
item->setText("Opcode: request (1)");
}
else if (op == 0x02)
{
item->setText("Opcode: response (1)");
}
else
{
qDebug("Error arp op code: %0x", op);
}
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
// Add address
item = new QStandardItem();
this->len = sizeof(parp_header->arp_sha);
item->setText(QString("Sender MAC address: %1")
.arg(SnifferUtil::macToHost(parp_header->arp_sha)));
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
this->len = sizeof(parp_header->arp_spa);
item->setText(QString("Sender IP address: %1")
.arg(SnifferUtil::netToIp(parp_header->arp_spa)));
setUserRoleData(item);
arpitem->appendRow(item);
this->offset += this->len;
item = new QStandardItem();
this->len = sizeof(parp_header->arp_tha);
item->setText(QString("Target MAC address: %1")
.arg(SnifferUtil::macToHost(parp_header->arp_tha)));
//.........这里部分代码省略.........
示例6: defaults
ConfigurationContentsWidget::ConfigurationContentsWidget(Window *window) : ContentsWidget(window),
m_model(new QStandardItemModel(this)),
m_ui(new Ui::ConfigurationContentsWidget)
{
m_ui->setupUi(this);
QSettings defaults(QLatin1String(":/schemas/options.ini"), QSettings::IniFormat, this);
const QStringList groups = defaults.childGroups();
for (int i = 0; i < groups.count(); ++i)
{
QStandardItem *groupItem = new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), groups.at(i));
defaults.beginGroup(groups.at(i));
const QStringList keys = defaults.childGroups();
for (int j = 0; j < keys.count(); ++j)
{
const QString key = QStringLiteral("%1/%2").arg(groups.at(i)).arg(keys.at(j));
const QString type = defaults.value(QStringLiteral("%1/type").arg(keys.at(j))).toString();
const QVariant defaultValue = SettingsManager::getDefaultValue(key);
const QVariant value = SettingsManager::getValue(key);
QList<QStandardItem*> optionItems;
optionItems.append(new QStandardItem(keys.at(j)));
optionItems.append(new QStandardItem(type));
optionItems.append(new QStandardItem(value.toString()));
optionItems[2]->setData(QSize(-1, 30), Qt::SizeHintRole);
optionItems[2]->setData(key, Qt::UserRole);
optionItems[2]->setData(type, (Qt::UserRole + 1));
optionItems[2]->setData(((type == "enumeration") ? defaults.value(QStringLiteral("%1/choices").arg(keys.at(j))).toStringList() : QVariant()), (Qt::UserRole + 2));
if (value != defaultValue)
{
QFont font = optionItems[0]->font();
font.setBold(true);
optionItems[0]->setFont(font);
}
groupItem->appendRow(optionItems);
}
defaults.endGroup();
m_model->appendRow(groupItem);
}
QStringList labels;
labels << tr("Name") << tr("Type") << tr("Value");
m_model->setHorizontalHeaderLabels(labels);
m_model->sort(0);
m_ui->configurationView->setModel(m_model);
m_ui->configurationView->setItemDelegate(new ItemDelegate(this));
m_ui->configurationView->setItemDelegateForColumn(2, new OptionDelegate(false, this));
m_ui->configurationView->header()->setTextElideMode(Qt::ElideRight);
connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString,QVariant)));
connect(m_ui->configurationView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
connect(m_ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterConfiguration(QString)));
}
示例7: QgsDebugMsg
//.........这里部分代码省略.........
// is there already a root item with the given scheme Name?
QStandardItem *schemaItem = nullptr;
QList<QStandardItem *> schemaItems = findItems( layerProperty.schemaName, Qt::MatchExactly, DbtmSchema );
// there is already an item for this schema
if ( schemaItems.size() > 0 )
{
schemaItem = schemaItems.at( DbtmSchema );
}
else
{
// create a new toplevel item for this schema
schemaItem = new QStandardItem( layerProperty.schemaName );
schemaItem->setFlags( Qt::ItemIsEnabled );
invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), schemaItem );
}
QgsWkbTypes::Type wkbType = QgsDb2TableModel::wkbTypeFromDb2( layerProperty.type );
if ( wkbType == QgsWkbTypes::Unknown && layerProperty.geometryColName.isEmpty() )
{
wkbType = QgsWkbTypes::NoGeometry;
}
bool needToDetect = wkbType == QgsWkbTypes::Unknown && layerProperty.type != QLatin1String( "GEOMETRYCOLLECTION" );
QList<QStandardItem *> childItemList;
QStandardItem *schemaNameItem = new QStandardItem( layerProperty.schemaName );
schemaNameItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ),
needToDetect
? tr( "Detecting…" )
: QgsWkbTypes::displayString( wkbType ) );
typeItem->setData( needToDetect, Qt::UserRole + 1 );
typeItem->setData( wkbType, Qt::UserRole + 2 );
QStandardItem *tableItem = new QStandardItem( layerProperty.tableName );
QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName );
QStandardItem *sridItem = new QStandardItem( layerProperty.srid );
sridItem->setEditable( false );
QString pkText;
QString pkCol;
switch ( layerProperty.pkCols.size() )
{
case 0:
break;
case 1:
pkText = layerProperty.pkCols[0];
pkCol = pkText;
break;
default:
pkText = tr( "Select…" );
break;
}
QStandardItem *pkItem = new QStandardItem( pkText );
if ( pkText == tr( "Select…" ) )
pkItem->setFlags( pkItem->flags() | Qt::ItemIsEditable );
pkItem->setData( layerProperty.pkCols, Qt::UserRole + 1 );
pkItem->setData( pkCol, Qt::UserRole + 2 );
QStandardItem *selItem = new QStandardItem( QLatin1String( "" ) );
selItem->setFlags( selItem->flags() | Qt::ItemIsUserCheckable );
selItem->setCheckState( Qt::Checked );
selItem->setToolTip( tr( "Disable 'Fast Access to Features at ID' capability to force keeping the attribute table in memory (e.g. in case of expensive views)." ) );
QStandardItem *sqlItem = new QStandardItem( layerProperty.sql );
childItemList << schemaNameItem;
childItemList << tableItem;
childItemList << typeItem;
childItemList << geomItem;
childItemList << sridItem;
childItemList << pkItem;
childItemList << selItem;
childItemList << sqlItem;
bool detailsFromThread = needToDetect ||
( wkbType != QgsWkbTypes::NoGeometry && layerProperty.srid.isEmpty() );
if ( detailsFromThread || pkText == tr( "Select…" ) )
{
Qt::ItemFlags flags = Qt::ItemIsSelectable;
if ( detailsFromThread )
flags |= Qt::ItemIsEnabled;
for ( QStandardItem *item : qgis::as_const( childItemList ) )
{
item->setFlags( item->flags() & ~flags );
}
}
schemaItem->appendRow( childItemList );
++mTableCount;
}
示例8: setObject
/*!
\brief TreeModel::setObject
*/
void TreeModel::setObject( QObject* object )
{
// Clean up workspace if necessary.
if ( mp_object &&
mp_object != object )
{
// Remove connections.
for ( int i = 0 ; i < mp_object->metaObject()->propertyCount(); ++i )
{
if ( mp_object->metaObject()->property( i ).hasNotifySignal() )
{
QMetaMethod signal = mp_object->metaObject()->property( i ).notifySignal();
bool res = disconnect( mp_object, signal, this, m_updateSlot );
Q_ASSERT( res );
}
}
// Delete items.
deleteAllItems();
// Clear the mapping.
m_propertyIndexToItemMap.clear();
}
mp_object = object;
if ( !object )
{
// No object is passed, nothing needs to be done.
return;
}
// A valdid object is passed, fill the QTreeView with it's properties.
int propertyCount = object->metaObject()->propertyCount();
for ( int i = 0; i < propertyCount; ++i )
{
QMetaProperty metaProperty = object->metaObject()->property( i );
QString typeName = metaProperty.name();
QVariant value = object->property( metaProperty.name() );
QList<QStandardItem*> itemRow;
QStandardItem* first = createItem( metaProperty, typeName, false );
itemRow.append( first );
// if ( metaProperty.isEnumType() )
// {
// qDebug() << metaProperty.type();
// qDebug() << metaProperty.typeName();
// QString name = metaProperty.typeName();
// if ( name == "SkeletonData::Joints" )
// {
// qDebug() << "GOT IT";
// }
// }
// Unwrap special QVariant types.
if ( value.canConvert<QVector3D>() )
{
// Case: QVector3D
QVector3D vec = qvariant_cast<QVector3D>( value );
QList<QStandardItem*> nextRow;
// Extract values from QVector3D
QStandardItem* tmp = nullptr;
// x-coordinate
tmp= createItem( metaProperty, "x", false );
nextRow.append( tmp );
tmp = createItem( metaProperty, vec.x(), true );
nextRow.append( tmp );
tmp = createItem( metaProperty, "float", false );
nextRow.append( tmp );
first->appendRow( nextRow );
nextRow.clear();
// y-coordinate
tmp= createItem( metaProperty, "y", false );
nextRow.append( tmp );
tmp = createItem( metaProperty, vec.y(), true );
nextRow.append( tmp );
tmp = createItem( metaProperty, "float", false );
nextRow.append( tmp );
first->appendRow( nextRow );
nextRow.clear();
// z-coordinte
tmp= createItem( metaProperty, "z", false );
nextRow.append( tmp );
tmp = createItem( metaProperty, vec.z(), true );
nextRow.append( tmp );
tmp = createItem( metaProperty, "float", false );
nextRow.append( tmp );
first->appendRow( nextRow );
// Append second and third item on the top level.
tmp = createItem( metaProperty, value, false );
itemRow.append( tmp );
tmp = createItem( metaProperty, "QVector3D", false );
//.........这里部分代码省略.........
示例9: test
void FlatProxyModelTester::test()
{
qDebug()<<"set 1 row, 1 column";
m_standardmodel.setColumnCount( 1 );
m_standardmodel.setRowCount( 1 );
m_standardmodel.setHorizontalHeaderLabels( QStringList() << "Column 1" );
m_flatmodel.setSourceModel( &m_standardmodel );
QCOMPARE( m_flatmodel.columnCount(), 2 ); // it adds an extra column
QCOMPARE( m_flatmodel.rowCount(), 1 );
QCOMPARE( m_flatmodel.headerData( 0, Qt::Horizontal ), QVariant( "Column 1" ) );
m_standardmodel.setData( m_standardmodel.index( 0, 0 ), "Index 0,0" );
QModelIndex idx = m_flatmodel.index( 0, 0 );
QVERIFY( idx.isValid() );
qDebug()<<"Index 0,0:"<<idx.data();
QCOMPARE( idx.data(), QVariant( "Index 0,0" ) );
qDebug()<<"1 row, set 2 columns";
m_standardmodel.setColumnCount( 2 );
QCOMPARE( m_flatmodel.columnCount(), 3 ); // it adds an extra column
m_flatmodel.setHeaderData( 1, Qt::Horizontal, "Column 2" );
QCOMPARE( m_flatmodel.headerData( 1, Qt::Horizontal ), QVariant( "Column 2" ) );
m_standardmodel.setData( m_standardmodel.index( 0, 1 ), "Index 0,1" );
idx = m_flatmodel.index( 0, 1 );
QVERIFY( idx.isValid() );
qDebug()<<"Index 0,1:"<<idx.data();
QCOMPARE( idx.data(), QVariant( "Index 0,1" ) );
qDebug()<<"Set 2 rows, 2 columns";
m_standardmodel.setRowCount( 2 );
QCOMPARE( m_flatmodel.rowCount(), 2 );
m_standardmodel.setData( m_standardmodel.index( 1, 0 ), "Index 1,0" );
idx = m_flatmodel.index( 1, 0 );
QVERIFY( idx.isValid() );
qDebug()<<"Index 1,0:"<<idx.data();
QCOMPARE( idx.data(), QVariant( "Index 1,0" ) );
m_standardmodel.setData( m_standardmodel.index( 1, 1 ), "Index 1,1" );
idx = m_flatmodel.index( 1, 1 );
QVERIFY( idx.isValid() );
qDebug()<<"Index 1,1:"<<idx.data();
QCOMPARE( idx.data(), QVariant( "Index 1,1" ) );
qDebug()<<"Add child on last index, adds a new row 1 in the flat model";
// NOTE: m_standardmodel.insertRow( 0, m_standardmodel.index( 1, 0 ) );
// does not work as there will be no columns and thus no valid indexes for this row
QStandardItem *item = m_standardmodel.itemFromIndex( m_standardmodel.index( 1, 0 ) );
QList<QStandardItem*> items;
items << new QStandardItem( "Child last column 1" ) << new QStandardItem( "Child last column 2" );
item->appendRow( items );
QCOMPARE( m_flatmodel.rowCount(), 3 );
idx = m_flatmodel.index( 2, 0 );
QCOMPARE( idx.data(), QVariant( "Child last column 1" ) );
idx = m_flatmodel.index( 2, 1 );
QCOMPARE( idx.data(), QVariant( "Child last column 2" ) );
qDebug()<<"add child on first index";
item = m_standardmodel.itemFromIndex( m_standardmodel.index( 0, 0 ) );
items.clear();
items << new QStandardItem( "Child first column 1" ) << new QStandardItem( "Child first column 2" );
item->appendRow( items );
QCOMPARE( m_flatmodel.rowCount(), 4 );
idx = m_flatmodel.index( 1, 0 );
QCOMPARE( idx.data(), QVariant( "Child first column 1" ) );
idx = m_flatmodel.index( 1, 1 );
QCOMPARE( idx.data(), QVariant( "Child first column 2" ) );
qDebug()<<"add row (2) on top level between first and last";
item = m_standardmodel.invisibleRootItem();
items.clear();
items << new QStandardItem( "New index 1,0" ) << new QStandardItem( "New index 1,1" );
item->insertRow( 1, items );
QCOMPARE( m_flatmodel.rowCount(), 5 );
idx = m_flatmodel.index( 2, 0 );
QCOMPARE( idx.data(), QVariant( "New index 1,0" ) );
idx = m_flatmodel.index( 2, 1 );
QCOMPARE( idx.data(), QVariant( "New index 1,1" ) );
qDebug()<<"Add child on middle index, adds row 3 to flat model";
item = m_standardmodel.itemFromIndex( m_standardmodel.index( 1, 0 ) );
items.clear();
items << new QStandardItem( "Child middle column 1" ) << new QStandardItem( "Child middle column 2" );
item->appendRow( items );
QCOMPARE( m_flatmodel.rowCount(), 6 );
idx = m_flatmodel.index( 3, 0 );
QCOMPARE( idx.data().toString(), QVariant( "Child middle column 1" ).toString() );
idx = m_flatmodel.index( 3, 1 );
QCOMPARE( idx.data(), QVariant( "Child middle column 2" ) );
qDebug()<<"Add child on middle index's child, adds row 4 to flat model";
QModelIndex parent = m_standardmodel.index( 1, 0 );
//.........这里部分代码省略.........
示例10: updatePositivesGroup
void ClassifierTrainer::updatePositivesGroup()
{
project->load(); // get the latest from the file system
// remove existing model if it exists
if (positivesModel) delete positivesModel;
// create column headers for the model
positivesModel = new QStandardItemModel();
positivesModel->setColumnCount(5);
positivesModel->setHeaderData(0, Qt::Horizontal, "Image", Qt::DisplayRole);
positivesModel->setHeaderData(1, Qt::Horizontal, "X", Qt::DisplayRole);
positivesModel->setHeaderData(2, Qt::Horizontal, "Y", Qt::DisplayRole);
positivesModel->setHeaderData(3, Qt::Horizontal, "Width", Qt::DisplayRole);
positivesModel->setHeaderData(4, Qt::Horizontal, "Height", Qt::DisplayRole);
QStandardItem *invisibleRootNode = positivesModel->invisibleRootItem();
QList<QString> *keys = project->positives();
qDebug() << "Number of positives loaded: " << keys->length();
for(int i=0; i < keys->length(); i++)
{
QString path = keys->at(i);
QStandardItem *imageRowItem = new QStandardItem(path);
imageRowItem->setEditable(false);
imageRowItem->setIcon(QIcon(":/assets/img/image.png"));
QList<Section> sections = project->positive_sections()->values(path);
for(int j=0; j < sections.length(); j++)
{
Section s = sections.at(j);
// first column
QString firstColumn = path;
QStandardItem *firstColumnItem = new QStandardItem(firstColumn);
firstColumnItem->setIcon(QIcon(":/assets/img/shading.png"));
firstColumnItem->setEditable(false);
// second column
QStandardItem *secondColumnItem = new QStandardItem(QString::number(s.x()));
secondColumnItem->setEditable(false);
// third column
QStandardItem *thirdColumnItem = new QStandardItem(QString::number(s.y()));
thirdColumnItem->setEditable(false);
// fourth column
QStandardItem *fourthColumnItem = new QStandardItem(QString::number(s.width()));
fourthColumnItem->setEditable(false);
// fifth column
QStandardItem *fifthColumnItem = new QStandardItem(QString::number(s.height()));
fifthColumnItem->setEditable(false);
QList<QStandardItem *> sectionRowItems;
sectionRowItems.append(firstColumnItem);
sectionRowItems.append(secondColumnItem);
sectionRowItems.append(thirdColumnItem);
sectionRowItems.append(fourthColumnItem);
sectionRowItems.append(fifthColumnItem);
imageRowItem->appendRow(sectionRowItems);
}
invisibleRootNode->appendRow(imageRowItem);
}
positivesTreeView->setModel(positivesModel);
positivesTreeView->setColumnWidth(0, 350);
positivesTreeView->resizeColumnToContents(1);
positivesTreeView->resizeColumnToContents(2);
positivesTreeView->resizeColumnToContents(3);
positivesTreeView->resizeColumnToContents(4);
positivesTreeView->expandAll();
}
示例11: AddProject
void Workspace::AddProject(QString& projectFullPath, bool load)
{
QFileInfo projectFileInfo(projectFullPath);
// Extract project name from path.
QString projectNameQ = projectFileInfo.fileName().remove(".ndtr");
std::string projectName = Utils::StringQ2W(projectNameQ);
// If not exists, create dir to store images.
QDir projectDir = projectFileInfo.absoluteDir();
// Create dir if not exist.
if (!projectDir.exists(projectNameQ))
{
projectDir.mkdir(projectNameQ);
}
projectDir.cd(projectNameQ);
// There can't be more projects with same name.
if (m_Projects.count(projectName))
{
// "Project with the same name is already loaded."
throw std::exception();
}
// Initialize project.
m_Projects[projectName] = unique_ptr<Project>(new Project());
m_ProjectsPersistentState[projectName] = true; // loaded or saved
Project* project = m_Projects[projectName].get();
project->Init(projectName,
projectFullPath.toStdString(),
projectDir.absolutePath().toStdString());
// Load/Save project.
if (load)
{
// If exists load project from file.
if(!ProjectParser::Load(project))
{
// "Failed to load project file."
throw std::exception();
}
}
else
{
// Save project file. Serialize as XML.
if (!ProjectParser::Save(project))
{
// "Failed to save project file."
throw std::exception();
}
}
// TODO: Move to method. Add images to view.
// Add project to project model view.
QStandardItem* rootItem = m_ProjectsModel.invisibleRootItem();
ProjectItem* projectItem = new ProjectItem(projectName);
QList<QStandardItem*> projectItems;
projectItems << projectItem;
rootItem->appendRow(projectItems);
for (Document* doc : project->GetDocuments())
{
auto projRowItem = m_ProjectsModel.findItems(Utils::StringW2Q(projectName));
ProjectItem* projectItem = (ProjectItem*) projRowItem.first();
ProjectItem* docItem = new ProjectItem(doc->GetName(), true);
QList<QStandardItem*> docRowItem;
docRowItem << docItem;
projectItem->appendRow(docItem);
}
// Set new project as current project.
SetCurrent(projectName);
}
开发者ID:imilos,项目名称:Application-of-pattern-recognition-algorithms-in-neutron-dosimetry,代码行数:74,代码来源:workspace.cpp
示例12: packCreationQueueToItem
// Insert a queue content to the model
bool packCreationQueueToItem(const PackCreationQueue &queue)
{
// Already inserted?
if (isPackCreationQueueAlreadyInserted(queue))
return true;
QFont bold;
bold.setBold(true);
// Create the root item for this queue
QStandardItem *rootItem = 0;
if (_format == PackCreationModel::ShowByServer) {
// nothing to do
} else if (_format == PackCreationModel::ShowByQueue) {
rootItem = new QStandardItem(tkTr(Trans::Constants::_1_COLON_2)
.arg(tkTr(Trans::Constants::QUEUE))
.arg(queue.sourceAbsolutePathFile()));
rootItem->setToolTip(queue.sourceAbsolutePathFile());
rootItem->setFont(bold);
rootItem->setCheckable(true);
rootItem->setCheckState(Qt::Checked);
q->invisibleRootItem()->appendRow(rootItem);
insertPackCreationQueueInCache(queue, rootItem);
} else {
LOG_ERROR_FOR(q, "Format not supported");
return false;
}
// Get the content of the queue and create the tree for each pack
QHash<QString, QStandardItem *> serversUidToItem;
foreach(const RequestedPackCreation &request, queue.queue()) {
if (_packDescriptionFilesIncluded.contains(request.descriptionFilePath))
continue;
_packDescriptionFilesIncluded.append(request.descriptionFilePath);
// Get the serverUid root item
QStandardItem *server = 0;
if (_format == PackCreationModel::ShowByQueue) {
server = serversUidToItem.value(request.serverUid, 0);
} else if (_format == PackCreationModel::ShowByServer) {
server = serverItem(request.serverUid);
}
// If the server is not available yet: create it
if (!server) {
server = new QStandardItem(tkTr(Trans::Constants::_1_COLON_2)
.arg(tkTr(Trans::Constants::SERVER))
.arg(request.serverUid));
if (_format == PackCreationModel::ShowByQueue) {
// In this format
// append the server item in the cache and the queueItem
serversUidToItem.insert(request.serverUid, server);
server->setCheckable(true);
server->setCheckState(Qt::Checked);
server->setFont(bold);
rootItem->appendRow(server);
} else if (_format == PackCreationModel::ShowByServer) {
// In this format
// append the server item in the central cache and the rootItem
addServerItem(request.serverUid, server);
rootItem = server;
rootItem->setFont(bold);
rootItem->setCheckable(true);
rootItem->setCheckState(Qt::Checked);
q->invisibleRootItem()->appendRow(rootItem);
}
}
// Include datapack to the server item
server->appendRow(packToItem(request.descriptionFilePath, queue));
}
return true;
}
示例13: addAccount
void AccountsSettings::addAccount (QObjectList accObjects)
{
IBookmarksService *ibs = qobject_cast<IBookmarksService*> (sender ());
if (!ibs)
{
qWarning () << Q_FUNC_INFO
<< sender ()
<< "ins't IBookmarksService";
return;
}
QObjectList accounts;
Q_FOREACH (QObject *accObj, accObjects)
{
IAccount *account = qobject_cast<IAccount*> (accObj);
if (Id2Account_.contains (account->GetAccountID ()))
continue;
if (!account->GetPassword ().isEmpty ())
Core::Instance ().SavePassword (accObj);
else
account->SetPassword (Core::Instance ().GetPassword (accObj));
Id2Account_ [account->GetAccountID ()] = accObj;
accounts << accObj;
const QModelIndex& index = GetServiceIndex (ibs->GetObject ());
QStandardItem *parentItem = 0;
if (!index.isValid ())
{
parentItem = new QStandardItem (ibs->GetServiceIcon (), ibs->GetServiceName ());
parentItem->setEditable (false);
Item2Service_ [parentItem] = ibs;
AccountsModel_->appendRow (parentItem);
}
else
parentItem = AccountsModel_->itemFromIndex (index);
QList<QStandardItem*> record;
QStandardItem *item = new QStandardItem (account->GetLogin ());
item->setEditable (false);
item->setCheckable (true);
item->setCheckState (account->IsSyncing () ? Qt::Checked : Qt::Unchecked);
if (account->IsSyncing ())
{
Core::Instance ().AddActiveAccount (accObj);
IBookmarksService *ibs = qobject_cast<IBookmarksService*> (account->GetParentService ());
ibs->DownloadBookmarks (account->GetObject (), account->GetLastDownloadDateTime ());
ibs->UploadBookmarks (account->GetObject (), Core::Instance ().GetAllBookmarks ());
}
Item2Account_ [item] = account;
QStandardItem *uploaditem = new QStandardItem (account->GetLastUploadDateTime ()
.toString (Qt::DefaultLocaleShortDate));
uploaditem->setEditable (false);
QStandardItem *downloaditem = new QStandardItem (account->GetLastDownloadDateTime ()
.toString (Qt::DefaultLocaleShortDate));
uploaditem->setEditable (false);
record << item
<< uploaditem
<< downloaditem;
parentItem->appendRow (record);
if (account->IsSyncing ())
Core::Instance ().AddActiveAccount (accObj);
Ui_.AccountsView_->expandAll ();
Scheduled_ = false;
ScheduleResize ();
}
示例14: fillItemModel_availableNodes
void RxDev::fillItemModel_availableNodes(QString nodeFile, Specfile &node){
QBrush b;
QStandardItem *group = new QStandardItem(QString("%1").arg(QString::fromStdString(node.type)));
QStandardItem *child;
QStandardItem *item;
QStandardItem *item2;
child = new QStandardItem(QString("path"));
item = new QStandardItem(QString("%1").arg(nodeFile));
b.setColor(Qt::blue);
child->setForeground(b);
b.setColor(Qt::black);
item->setForeground(b);
child->appendRow(item);
// the appendRow function appends the child as new row
group->appendRow(child);
child = new QStandardItem(QString("type"));
item = new QStandardItem(QString("%1").arg(QString::fromStdString(node.type)));
child->appendRow(item);
child = new QStandardItem(QString("package"));
item = new QStandardItem(QString("%1").arg(QString::fromStdString(node.package)));
b.setColor(Qt::blue);
child->setForeground(b);
child->appendRow(item);
group->appendRow(child);
child = new QStandardItem(QString("subscriptions"));
for(std::list<Topic_Type>::iterator iter=node.subscriptions.begin();iter != node.subscriptions.end();iter++ )
{
item = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topic));
item2 = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topictype));
b.setColor(Qt::red);
item->setForeground(b);
b.setColor(Qt::gray);
item2->setForeground(b);
item->appendRow(item2);
child->appendRow(item);
}
b.setColor(Qt::blue);
child->setForeground(b);
group->appendRow(child);
child = new QStandardItem(QString("publications"));
for(std::list<Topic_Type>::iterator iter=node.publications.begin();iter != node.publications.end();iter++ )
{
item = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topic));
item2 = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topictype));
b.setColor(Qt::red);
item->setForeground(b);
b.setColor(Qt::gray);
item2->setForeground(b);
item->appendRow(item2);
child->appendRow(item);
}
b.setColor(Qt::blue);
child->setForeground(b);
group->appendRow(child);
child = new QStandardItem(QString("services"));
for(std::list<Topic_Type>::iterator iter=node.services.begin();iter != node.services.end();iter++ )
{
item = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topic));
item2 = new QStandardItem(QString::fromStdString(Topic_Type(*iter).topictype));
b.setColor(Qt::red);
item->setForeground(b);
b.setColor(Qt::gray);
item2->setForeground(b);
item->appendRow(item2);
child->appendRow(item);
}
b.setColor(Qt::blue);
child->setForeground(b);
group->appendRow(child);
child = new QStandardItem(QString("parameters"));
for(std::list<Name_Type_Default>::iterator iter=node.parameters.begin();iter != node.parameters.end();iter++ )
{
item = new QStandardItem(QString::fromStdString(Name_Type_Default(*iter).paramName));
item2 = new QStandardItem("type: "+QString::fromStdString(Name_Type_Default(*iter).paramType));
b.setColor(Qt::red);
item->setForeground(b);
b.setColor(Qt::gray);
item2->setForeground(b);
item->appendRow(item2);
item2 = new QStandardItem("default: "+QString::fromStdString(Name_Type_Default(*iter).paramDefault));
b.setColor(Qt::black);
item2->setForeground(b);
item->appendRow(item2);
item2 = new QStandardItem("range: "+QString::fromStdString(Name_Type_Default(*iter).paramRange));
b.setColor(Qt::gray);
item2->setForeground(b);
//.........这里部分代码省略.........
示例15: createTreeModel
void NotifyOptionsWidget::createTreeModel()
{
static const struct { ushort kind; QString name; } KindsList[] = {
{ INotification::PopupWindow, tr("Display a notification in popup window") },
{ INotification::SoundPlay, tr("Play sound at the notification") },
{ INotification::ShowMinimized, tr("Show the corresponding window minimized in the taskbar") },
{ INotification::AlertWidget, tr("Highlight the corresponding window in the taskbar") },
{ INotification::TabPageNotify, tr("Display a notification in tab") },
{ INotification::RosterNotify, tr("Display a notification in your roster") },
{ INotification::TrayNotify, tr("Display a notification in tray") },
{ INotification::TrayAction, tr("Display a notification in tray context menu") },
{ INotification::AutoActivate, tr("Immediately activate the notification") },
{ 0, QString::null }
};
FModel.clear();
FModel.setColumnCount(2);
INotificationType globalType;
globalType.order = 0;
globalType.kindMask = 0xFFFF;
globalType.title = tr("Allowed types of notifications");
globalType.icon = IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->getIcon(MNI_NOTIFICATIONS);
QMap<QString,INotificationType> notifyTypes;
notifyTypes.insert(QString::null,globalType);
foreach(const QString &typeId, FNotifications->notificationTypes())
notifyTypes.insert(typeId,FNotifications->notificationType(typeId));
for(QMap<QString,INotificationType>::const_iterator it=notifyTypes.constBegin(); it!=notifyTypes.constEnd(); ++it)
{
if (!it->title.isEmpty() && it->kindMask>0)
{
QStandardItem *typeNameItem = new QStandardItem(it->title);
typeNameItem->setFlags(Qt::ItemIsEnabled);
typeNameItem->setData(it.key(),MDR_TYPE);
typeNameItem->setData(it->order,MDR_SORT);
typeNameItem->setIcon(it->icon);
setItemBold(typeNameItem,true);
QStandardItem *typeEnableItem = new QStandardItem;
typeEnableItem->setFlags(Qt::ItemIsEnabled);
FTypeItems.insert(it.key(),typeNameItem);
FModel.invisibleRootItem()->appendRow(QList<QStandardItem *>() << typeNameItem << typeEnableItem);
for (int index =0; KindsList[index].kind!=0; index++)
{
if ((it->kindMask & KindsList[index].kind)>0)
{
QStandardItem *kindNameItem = new QStandardItem(KindsList[index].name);
kindNameItem->setFlags(Qt::ItemIsEnabled);
kindNameItem->setData(index,MDR_SORT);
QStandardItem *kindEnableItem = new QStandardItem();
kindEnableItem->setFlags(Qt::ItemIsEnabled);
kindEnableItem->setTextAlignment(Qt::AlignCenter);
kindEnableItem->setCheckable(true);
kindEnableItem->setCheckState(Qt::PartiallyChecked);
kindEnableItem->setData(it.key(),MDR_TYPE);
kindEnableItem->setData(KindsList[index].kind,MDR_KIND);
typeNameItem->appendRow(QList<QStandardItem *>() << kindNameItem << kindEnableItem);
}
}
}
}
}