本文整理汇总了C++中QVariant::type方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::type方法的具体用法?C++ QVariant::type怎么用?C++ QVariant::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluation
void evaluation()
{
QFETCH( QString, string );
QFETCH( bool, evalError );
QFETCH( QVariant, result );
QgsExpression exp( string );
QCOMPARE( exp.hasParserError(), false );
if ( exp.hasParserError() )
qDebug() << exp.parserErrorString();
QVariant res = exp.evaluate();
if ( exp.hasEvalError() )
qDebug() << exp.evalErrorString();
if ( res.type() != result.type() )
{
qDebug() << "got " << res.typeName() << " instead of " << result.typeName();
}
//qDebug() << res.type() << " " << result.type();
//qDebug() << "type " << res.typeName();
QCOMPARE( exp.hasEvalError(), evalError );
QCOMPARE( res.type(), result.type() );
switch ( res.type() )
{
case QVariant::Invalid:
break; // nothing more to check
case QVariant::Int:
QCOMPARE( res.toInt(), result.toInt() );
break;
case QVariant::Double:
QCOMPARE( res.toDouble(), result.toDouble() );
break;
case QVariant::String:
QCOMPARE( res.toString(), result.toString() );
break;
case QVariant::Date:
QCOMPARE( res.toDate(), result.toDate() );
break;
case QVariant::DateTime:
QCOMPARE( res.toDateTime(), result.toDateTime() );
break;
case QVariant::Time:
QCOMPARE( res.toTime(), result.toTime() );
break;
case QVariant::UserType:
{
if ( res.userType() == qMetaTypeId<QgsExpression::Interval>() )
{
QgsExpression::Interval inter = res.value<QgsExpression::Interval>();
QgsExpression::Interval gotinter = result.value<QgsExpression::Interval>();
QCOMPARE( inter.seconds(), gotinter.seconds() );
}
else
{
QFAIL( "unexpected user type" );
}
break;
}
default:
Q_ASSERT( false ); // should never happen
}
}
示例2: editItem
void ParameterEdit::editItem()
{
if(_table->currentSelection() != -1) {
bool do_update = false;
int r = _table->currentRow();
Q3CheckTableItem * ctItem = (Q3CheckTableItem*)_table->item(r, 0);
if(ctItem == 0)
return;
bool active = ctItem->isChecked();
QString name = _table->text(r, 1);
QVariant var = _params[name];
BoolEdit * be = 0;
IntEdit * ie = 0;
DoubleEdit * de = 0;
StringEdit * se = 0;
ListEdit * le = 0;
switch(var.type()) {
case QVariant::Bool:
be = new BoolEdit(this);
be->_name->setText(name);
be->_active->setChecked(active);
be->setValue(var.toBool());
if(be->exec() == QDialog::Accepted) {
var = QVariant(be->value(), 0);
active = be->_active->isChecked();
do_update = TRUE;
}
delete be;
be = 0;
break;
case QVariant::Int:
ie = new IntEdit(this);
ie->_name->setText(name);
ie->_active->setChecked(active);
ie->_value->setText(QString::number(var.toInt()));
if(ie->exec() == QDialog::Accepted) {
var = QVariant(ie->_value->text().toInt());
active = ie->_active->isChecked();
do_update = TRUE;
}
delete ie;
ie = 0;
break;
case QVariant::Double:
de = new DoubleEdit(this);
de->_name->setText(name);
de->_active->setChecked(active);
de->_value->setText(QString::number(var.toDouble()));
if(de->exec() == QDialog::Accepted) {
var = QVariant(de->_value->text().toDouble());
active = de->_active->isChecked();
do_update = TRUE;
}
delete de;
de = 0;
break;
case QVariant::String:
se = new StringEdit(this);
se->_name->setText(name);
se->_active->setChecked(active);
se->_value->setText(var.toString());
if(se->exec() == QDialog::Accepted) {
var = QVariant(se->_value->text());
active = se->_active->isChecked();
do_update = TRUE;
}
delete se;
se = 0;
break;
case QVariant::List:
le = new ListEdit(this);
le->_name->setText(name);
le->_active->setChecked(active);
le->setList(var.toList());
if(le->exec() == QDialog::Accepted) {
var = QVariant(le->list());
active = le->_active->isChecked();
do_update = TRUE;
}
delete le;
le = 0;
break;
default:
QMessageBox::warning(this, tr("Warning"), QString(tr("I do not know how to edit QVariant type %1.")).arg(var.typeName()));
};
if(do_update) {
_params[name] = var;
ctItem->setChecked(active);
_table->setText(r, 1, name);
_table->setText(r, 2, var.typeName());
_table->setText(r, 3, var.toString());
}
}
}
示例3: paint
void GroupDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QRect r = option.rect;
QFont font = painter->font();
QPen pen = painter->pen();
if (!index.parent().isValid())
{
painter->setBrush(Qt::red);
font.setPixelSize(14);
font.setUnderline(false);
painter->setFont(font);
pen.setColor(grayFont);
//painter->setBackground(Qt::gray);
painter->fillRect(option.rect, grayBackground);
if (index.column()==0)
{
//if (option.state & QStyle::State_Editing)
QPixmap icon = tree->isExpanded(index)
? QPixmap(":/Images/Visitors/icon_minus.png")
: QPixmap(":/Images/Visitors/icon_plus.png");
painter->drawPixmap(r.x() + 8, r.y() + 6, 16, 16, icon);
}
painter->setPen(pen);
painter->setFont(font);
painter->drawText(QPoint(r.x() + 32, r.y() + 18), index.data().toString());
}
else
{
if (option.state & QStyle::State_MouseOver)
{
painter->fillRect(option.rect, grayBackground);
}
QVariant value = index.data(Qt::DecorationRole);
int adjust = index.column()==0 ? 24 : 0;
if (value.isValid() && value.type() == QVariant::Icon)
{
QIcon icon = value.value<QIcon>();
if (icon.availableSizes().count()>0)
{
int width = icon.availableSizes().at(0).width();
icon.paint(painter, r.x()+8 + adjust, r.y(), width, 28);
adjust += width + 8;
}
}
font.setPixelSize(12);
if (index.column() == 0 || index.column() == 10)
{
font.setUnderline(true);
pen.setColor(hyperlink);
}
else
{
font.setUnderline(false);
pen.setColor(grayFont);
}
painter->setPen(pen);
painter->setFont(font);
QTextOption textOptions(Qt::AlignLeft);
textOptions.setWrapMode(QTextOption::NoWrap);
painter->drawText(r.adjusted(8 + adjust,6,0,0), index.data().toString(), textOptions);
//painter->drawText(QPoint(r.x() + 32, r.y() + r.height()/2 + font.pixelSize()/2 - 1), index.data().toString(), o);
}
}
示例4: outputSettings
void SettingsDialog::outputSettings() {
QSettings settings;
QListIterator<QString> itr(settings.allKeys());
QString output;
output += "QOwnNotes Debug Information\n";
output += "===========================\n";
QDateTime dateTime = QDateTime::currentDateTime();
// add information about QOwnNotes
output += "\n## General Info\n\n";
output += prepareDebugInformationLine("Current Date", dateTime.toString());
output += prepareDebugInformationLine("Version", QString(VERSION));
output += prepareDebugInformationLine("Build date", QString(__DATE__));
output += prepareDebugInformationLine("Build number",
QString::number(BUILD));
output += prepareDebugInformationLine("Platform", QString(PLATFORM));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
output += prepareDebugInformationLine("Operating System",
QSysInfo::prettyProductName());
output += prepareDebugInformationLine("Build architecture",
QSysInfo::buildCpuArchitecture());
output += prepareDebugInformationLine("Current architecture",
QSysInfo::currentCpuArchitecture());
#endif
output += prepareDebugInformationLine("Release", QString(RELEASE));
output += prepareDebugInformationLine("Qt Version", QT_VERSION_STR);
// add information about the server
output += "\n## Server Info\n\n";
output += prepareDebugInformationLine("serverUrl",
ui->serverUrlEdit->text());
output += prepareDebugInformationLine("appIsValid",
QString(appIsValid ? "yes" : "no"));
if (appIsValid) {
output += prepareDebugInformationLine("serverVersion", serverVersion);
output += prepareDebugInformationLine("appVersion", appVersion);
} else {
output += prepareDebugInformationLine("connectionErrorMessage",
connectionErrorMessage);
}
// add information about the settings
output += "\n## Settings\n\n";
// hide values of these keys
QStringList keyHiddenList = (QStringList() << "cryptoKey" <<
"ownCloud/password");
while (itr.hasNext()) {
QString key = itr.next();
QVariant value = settings.value(key);
// hide values of certain keys
if (keyHiddenList.contains(key)) {
output += prepareDebugInformationLine(key, "<hidden>");
} else {
switch (value.type()) {
case QVariant::StringList:
output += prepareDebugInformationLine(
key,
value.toStringList().join(", "));
break;
case QVariant::ByteArray:
output += prepareDebugInformationLine(key, "<binary data>");
break;
default:
output += prepareDebugInformationLine(key,
value.toString());
}
}
}
ui->debugInfoTextEdit->setPlainText(output);
}
示例5: set
void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value)
{
if (writeHandle() == 0) {
setStatus(QSettings::AccessError);
return;
}
QString rKey = escapedKey(uKey);
HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey));
if (handle == 0) {
setStatus(QSettings::AccessError);
return;
}
DWORD type;
QByteArray regValueBuff;
// Determine the type
switch (value.type()) {
case QVariant::List:
case QVariant::StringList: {
// If none of the elements contains '\0', we can use REG_MULTI_SZ, the
// native registry string list type. Otherwise we use REG_BINARY.
type = REG_MULTI_SZ;
QStringList l = variantListToStringList(value.toList());
QStringList::const_iterator it = l.constBegin();
for (; it != l.constEnd(); ++it) {
if ((*it).length() == 0 || stringContainsNullChar(*it)) {
type = REG_BINARY;
break;
}
}
if (type == REG_BINARY) {
QString s = variantToString(value);
regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
} else {
QStringList::const_iterator it = l.constBegin();
for (; it != l.constEnd(); ++it) {
const QString &s = *it;
regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
}
regValueBuff.append((char)0);
regValueBuff.append((char)0);
}
break;
}
case QVariant::Int:
case QVariant::UInt: {
type = REG_DWORD;
qint32 i = value.toInt();
regValueBuff = QByteArray((const char*)&i, sizeof(qint32));
break;
}
case QVariant::LongLong:
case QVariant::ULongLong: {
type = REG_QWORD;
qint64 i = value.toLongLong();
regValueBuff = QByteArray((const char*)&i, sizeof(qint64));
break;
}
case QVariant::ByteArray:
// fallthrough intended
default: {
// If the string does not contain '\0', we can use REG_SZ, the native registry
// string type. Otherwise we use REG_BINARY.
QString s = variantToString(value);
type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ;
if (type == REG_BINARY) {
regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
} else {
regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
}
break;
}
}
// set the value
LONG res = RegSetValueEx(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()), 0, type,
reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
regValueBuff.size());
if (res == ERROR_SUCCESS) {
deleteWriteHandleOnExit = false;
} else {
qWarning("QSettings: failed to set subkey \"%s\": %s",
rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data());
setStatus(QSettings::AccessError);
}
RegCloseKey(handle);
}
示例6: rowSelected
void ExpandingWidgetModel::rowSelected(const QModelIndex& idx_)
{
QModelIndex idx( firstColumn(idx_) );
if( !m_partiallyExpanded.contains( idx ) )
{
QModelIndex oldIndex = partiallyExpandedRow();
//Unexpand the previous partially expanded row
if( !m_partiallyExpanded.isEmpty() )
{ ///@todo allow multiple partially expanded rows
while( !m_partiallyExpanded.isEmpty() )
m_partiallyExpanded.erase(m_partiallyExpanded.begin());
//partiallyUnExpand( m_partiallyExpanded.begin().key() );
}
//Notify the underlying models that the item was selected, and eventually get back the text for the expanding widget.
if( !idx.isValid() ) {
//All items have been unselected
if( oldIndex.isValid() )
emit dataChanged(oldIndex, oldIndex);
} else {
QVariant variant = data(idx, CodeCompletionModel::ItemSelected);
if( !isExpanded(idx) && variant.type() == QVariant::String) {
//Either expand upwards or downwards, choose in a way that
//the visible fields of the new selected entry are not moved.
if( oldIndex.isValid() && (oldIndex < idx || (!(oldIndex < idx) && oldIndex.parent() < idx.parent()) ) )
m_partiallyExpanded.insert(idx, ExpandUpwards);
else
m_partiallyExpanded.insert(idx, ExpandDownwards);
//Say that one row above until one row below has changed, so no items will need to be moved(the space that is taken from one item is given to the other)
if( oldIndex.isValid() && oldIndex < idx ) {
emit dataChanged(oldIndex, idx);
if( treeView()->verticalScrollMode() == QAbstractItemView::ScrollPerItem )
{
//Qt fails to correctly scroll in ScrollPerItem mode, so the selected index is completely visible,
//so we do the scrolling by hand.
QRect selectedRect = treeView()->visualRect(idx);
QRect frameRect = treeView()->frameRect();
if( selectedRect.bottom() > frameRect.bottom() ) {
int diff = selectedRect.bottom() - frameRect.bottom();
//We need to scroll down
QModelIndex newTopIndex = idx;
QModelIndex nextTopIndex = idx;
QRect nextRect = treeView()->visualRect(nextTopIndex);
while( nextTopIndex.isValid() && nextRect.isValid() && nextRect.top() >= diff ) {
newTopIndex = nextTopIndex;
nextTopIndex = treeView()->indexAbove(nextTopIndex);
if( nextTopIndex.isValid() )
nextRect = treeView()->visualRect(nextTopIndex);
}
treeView()->scrollTo( newTopIndex, QAbstractItemView::PositionAtTop );
}
}
//This is needed to keep the item we are expanding completely visible. Qt does not scroll the view to keep the item visible.
//But we must make sure that it isn't too expensive.
//We need to make sure that scrolling is efficient, and the whole content is not repainted.
//Since we are scrolling anyway, we can keep the next line visible, which might be a cool feature.
//Since this also doesn't work smoothly, leave it for now
//treeView()->scrollTo( nextLine, QAbstractItemView::EnsureVisible );
} else if( oldIndex.isValid() && idx < oldIndex ) {
emit dataChanged(idx, oldIndex);
//For consistency with the down-scrolling, we keep one additional line visible above the current visible.
//Since this also doesn't work smoothly, leave it for now
/* QModelIndex prevLine = idx.sibling(idx.row()-1, idx.column());
if( prevLine.isValid() )
treeView()->scrollTo( prevLine );*/
} else
emit dataChanged(idx, idx);
} else if( oldIndex.isValid() ) {
//We are not partially expanding a new row, but we previously had a partially expanded row. So signalize that it has been unexpanded.
emit dataChanged(oldIndex, oldIndex);
}
}
}else{
qCDebug( PLUGIN_QUICKOPEN ) << "ExpandingWidgetModel::rowSelected: Row is already partially expanded";
}
}
示例7: on_buttonSet_clicked
void ChangeProperties::on_buttonSet_clicked()
{
QTreeWidgetItem *item = listProperties->currentItem();
if (!item)
return;
QString prop = item->text(0);
QVariant value = activex->property(prop.toLatin1());
QVariant::Type type = value.type();
if (!value.isValid()) {
const QMetaObject *mo = activex->metaObject();
const QMetaProperty property = mo->property(mo->indexOfProperty(prop.toLatin1()));
type = QVariant::nameToType(property.typeName());
}
switch (type) {
case QVariant::Color:
{
QColor col;
col.setNamedColor(editValue->text());
if (col.isValid()) {
value = qVariantFromValue(col);
} else {
QMessageBox::warning(this, tr("Can't parse input"),
tr("Failed to create a color from %1\n"
"The string has to be a valid color name (e.g. 'red')\n"
"or a RGB triple of format '#rrggbb'."
).arg(editValue->text()));
}
}
break;
case QVariant::Font:
{
QFont fnt;
if (fnt.fromString(editValue->text())) {
value = qVariantFromValue(fnt);
} else {
QMessageBox::warning(this, tr("Can't parse input"),
tr("Failed to create a font from %1\n"
"The string has to have a format family,<point size> or\n"
"family,pointsize,stylehint,weight,italic,underline,strikeout,fixedpitch,rawmode."
).arg(editValue->text()));
}
}
break;
case QVariant::Pixmap:
{
QString fileName = editValue->text();
if (fileName.isEmpty())
fileName = QFileDialog::getOpenFileName(this);
QPixmap pm(fileName);
if (pm.isNull())
return;
value = qVariantFromValue(pm);
}
break;
case QVariant::Bool:
{
QString txt = editValue->text().toLower();
value = QVariant(txt != QLatin1String("0") && txt != QLatin1String("false"));
}
break;
case QVariant::List:
{
QStringList txtList = editValue->text().split(QRegExp(QLatin1String("[,;]")));
QList<QVariant> varList;
for (int i = 0; i < txtList.count(); ++i) {
QVariant svar(txtList.at(i));
QString str = svar.toString();
str = str.trimmed();
bool ok;
int n = str.toInt(&ok);
if (ok) {
varList << n;
continue;
}
double d = str.toDouble(&ok);
if (ok) {
varList << d;
continue;
}
varList << str;
}
value = varList;
}
break;
default:
value = editValue->text();
break;
}
Q_ASSERT(activex->setProperty(prop.toLatin1(), value));
updateProperties();
listProperties->setCurrentItem(listProperties->findItems(prop, Qt::MatchExactly).at(0));
}
示例8: createEditor
QWidget* MultiDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
const QAbstractItemModel* model = index.model();
QVariant value = model->data( index, Qt::EditRole);
switch (value.type()) {
case QMetaType::QTime:
{
QTimeEdit* editor = new QTimeEdit( parent);
editor->setMaximumWidth( editor->sizeHint().width());
//// Get value snapshot into editor
editor->setTime( value.toTime());
return editor;
}
case QMetaType::QDate:
{
QDateEdit* editor = new QDateEdit( parent);
setupCalenderWidget( editor);
editor->setMaximumWidth( editor->sizeHint().width());
//// Get value snapshot into editor
editor->setDate( value.toDate());
return editor;
}
case QMetaType::QDateTime:
{
QDateTimeEdit* editor = new QDateTimeEdit( parent);
setupCalenderWidget( editor);
editor->setMaximumWidth( editor->sizeHint().width());
editor->setDateTime( value.toDateTime());
return editor;
}
case QMetaType::QImage:
// Fall throu
case QMetaType::QPixmap:
// Fall throu
case QMetaType::QIcon:
{
PixmapViewer* editor = new PixmapViewer( parent);
connect( editor, SIGNAL(finished(int)), this, SLOT(closeEmittingEditor()));
return editor;
}
case QMetaType::QStringList:
{
QVariant varList = index.model()->data( index, ItemDataRole::EnumList);
if (varList.isNull()) break; // Not a enum-list, fall to std
QListWidget* editor = new QListWidget( parent);
foreach (const QString& bitItemText, varList.toStringList()) {
QListWidgetItem* bitItem = new QListWidgetItem( bitItemText, editor);
bitItem->setFlags(bitItem->flags() | Qt::ItemIsUserCheckable);
bitItem->setCheckState(Qt::Unchecked);
}
int width = editor->sizeHintForColumn(0) + 25;
int height = editor->sizeHintForRow(0) * editor->count() + 10;
editor->setMinimumWidth( width);
editor->setMaximumWidth( width);
editor->setMinimumHeight( height);
editor->setMaximumHeight( height);
//// Get value snapshot into editor
QStringList valList = value.toStringList();
int itemCount = editor->count();
for (int i = 0; i < itemCount; ++i) {
QListWidgetItem* bitItem = editor->item(i);
bool isActive = valList.contains( bitItem->text());
bitItem->setCheckState( isActive ? Qt::Checked : Qt::Unchecked);
}
return editor;
}
case QMetaType::QString:
{
QVariant varList = index.model()->data( index, ItemDataRole::EnumList);
if (varList.isNull()) break; // Not a enum-list, fall to std
QComboBox* editor = new QComboBox( parent);
editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
editor->addItems( varList.toStringList());
editor->setMaximumWidth( editor->minimumSizeHint().width());
//// Get value snapshot into editor
editor->setCurrentIndex( editor->findText( value.toString()));
return editor;
}
default:;
}
if (index.column() == 0) {
emit itemEditTrigged( index);
return 0; // No inline editor
}
QWidget* editor = QItemDelegate::createEditor( parent, option, index);
//// Get value snapshot into editor
QItemDelegate::setEditorData( editor, index);
return editor;
//.........这里部分代码省略.........
示例9: QVariantToVARIANT
/*
Converts \a var to \a arg, and tries to coerce \a arg to \a type.
Used by
QAxServerBase:
- QAxServerBase::qt_metacall
- IDispatch::Invoke(PROPERTYGET, METHOD)
- IPersistPropertyBag::Save
QAxBase:
- IDispatch::Invoke (QAxEventSink)
- QAxBase::internalProperty(WriteProperty)
- QAxBase::internalInvoke()
- QAxBase::dynamicCallHelper()
- IPropertyBag::Read (QtPropertyBag)
Also called recoursively for lists.
*/
bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &typeName, bool out)
{
QVariant qvar = var;
// "type" is the expected type, so coerce if necessary
QVariant::Type proptype = typeName.isEmpty() ? QVariant::Invalid : QVariant::nameToType(typeName);
if (proptype == QVariant::UserType && !typeName.isEmpty()) {
if (typeName == "short" || typeName == "char")
proptype = QVariant::Int;
else if (typeName == "float")
proptype = QVariant::Double;
}
if (proptype != QVariant::Invalid && proptype != QVariant::UserType && proptype != qvar.type()) {
if (qvar.canConvert(proptype))
qvar.convert(proptype);
else
qvar = QVariant(proptype);
}
if (out && arg.vt == (VT_VARIANT|VT_BYREF) && arg.pvarVal) {
return QVariantToVARIANT(var, *arg.pvarVal, typeName, false);
}
if (out && proptype == QVariant::Invalid && typeName == "QVariant") {
VARIANT *pVariant = new VARIANT;
QVariantToVARIANT(var, *pVariant, QByteArray(), false);
arg.vt = VT_VARIANT|VT_BYREF;
arg.pvarVal = pVariant;
return true;
}
switch ((int)qvar.type()) {
case QVariant::String:
if (out && arg.vt == (VT_BSTR|VT_BYREF)) {
if (*arg.pbstrVal)
SysFreeString(*arg.pbstrVal);
*arg.pbstrVal = QStringToBSTR(qvar.toString());
arg.vt = VT_BSTR|VT_BYREF;
} else {
arg.vt = VT_BSTR;
arg.bstrVal = QStringToBSTR(qvar.toString());
if (out) {
arg.pbstrVal = new BSTR(arg.bstrVal);
arg.vt |= VT_BYREF;
}
}
break;
case QVariant::Int:
if (out && arg.vt == (VT_I4|VT_BYREF)) {
*arg.plVal = qvar.toInt();
} else {
arg.vt = VT_I4;
arg.lVal = qvar.toInt();
if (out) {
if (typeName == "short") {
arg.vt = VT_I2;
arg.piVal = new short(arg.lVal);
} else if (typeName == "char") {
arg.vt = VT_I1;
arg.pcVal= new char(arg.lVal);
} else {
arg.plVal = new long(arg.lVal);
}
arg.vt |= VT_BYREF;
}
}
break;
case QVariant::UInt:
if (out && (arg.vt == (VT_UINT|VT_BYREF) || arg.vt == (VT_I4|VT_BYREF))) {
*arg.puintVal = qvar.toUInt();
} else {
arg.vt = VT_UINT;
arg.uintVal = qvar.toUInt();
if (out) {
arg.puintVal = new uint(arg.uintVal);
arg.vt |= VT_BYREF;
}
}
break;
//.........这里部分代码省略.........
示例10: paint
/*!
Renders the delegate using the given \a painter and style \a option for
the item specified by \a index.
When reimplementing this function in a subclass, you should update the area
held by the option's \l{QStyleOption::rect}{rect} variable, using the
option's \l{QStyleOption::state}{state} variable to determine the state of
the item to be displayed, and adjust the way it is painted accordingly.
For example, a selected item may need to be displayed differently to
unselected items, as shown in the following code:
\snippet itemviews/pixelator/pixeldelegate.cpp 2
\dots
After painting, you should ensure that the painter is returned to its
the state it was supplied in when this function was called. For example,
it may be useful to call QPainter::save() before painting and
QPainter::restore() afterwards.
\sa QStyle::State
*/
void QItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_D(const QItemDelegate);
Q_ASSERT(index.isValid());
QStyleOptionViewItem opt = setOptions(index, option);
// prepare
painter->save();
if (d->clipPainting)
painter->setClipRect(opt.rect);
// get the data and the rectangles
QVariant value;
QPixmap pixmap;
QRect decorationRect;
value = index.data(Qt::DecorationRole);
if (value.isValid()) {
// ### we need the pixmap to call the virtual function
pixmap = decoration(opt, value);
if (value.type() == QVariant::Icon) {
d->tmp.icon = qvariant_cast<QIcon>(value);
d->tmp.mode = d->iconMode(option.state);
d->tmp.state = d->iconState(option.state);
const QSize size = d->tmp.icon.actualSize(option.decorationSize,
d->tmp.mode, d->tmp.state);
decorationRect = QRect(QPoint(0, 0), size);
} else {
d->tmp.icon = QIcon();
decorationRect = QRect(QPoint(0, 0), pixmap.size());
}
} else {
d->tmp.icon = QIcon();
decorationRect = QRect();
}
QString text;
QRect displayRect;
value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull()) {
text = QItemDelegatePrivate::valueToText(value, opt);
displayRect = textRectangle(painter, d->textLayoutBounds(opt), opt.font, text);
}
QRect checkRect;
Qt::CheckState checkState = Qt::Unchecked;
value = index.data(Qt::CheckStateRole);
if (value.isValid()) {
checkState = static_cast<Qt::CheckState>(value.toInt());
checkRect = doCheck(opt, opt.rect, value);
}
// do the layout
doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
// draw the item
drawBackground(painter, opt, index);
drawCheck(painter, opt, checkRect, checkState);
drawDecoration(painter, opt, decorationRect, pixmap);
drawDisplay(painter, opt, displayRect, text);
drawFocus(painter, opt, displayRect);
// done
painter->restore();
}
示例11: toString
QString QGalleryTrackerStringListColumn::toString(const QVariant &variant) const
{
return variant.type() == QVariant::StringList
? variant.toStringList().join(m_separatorString)
: variant.toString();
}
示例12: setVariant
void TestObject::setVariant(const QVariant &value)
{
qDebug() << value.type();
}
示例13: streamDebug
static void streamDebug(QDebug dbg, const QVariant &v)
{
switch(v.type()) {
case QVariant::Cursor:
#ifndef QT_NO_CURSOR
// dbg.nospace() << qvariant_cast<QCursor>(v); //FIXME
#endif
break;
case QVariant::Bitmap:
// dbg.nospace() << qvariant_cast<QBitmap>(v); //FIXME
break;
case QVariant::Polygon:
dbg.nospace() << qvariant_cast<QPolygon>(v);
break;
case QVariant::Region:
dbg.nospace() << qvariant_cast<QRegion>(v);
break;
case QVariant::Font:
// dbg.nospace() << qvariant_cast<QFont>(v); //FIXME
break;
case QVariant::Matrix:
dbg.nospace() << qvariant_cast<QMatrix>(v);
break;
case QVariant::Transform:
dbg.nospace() << qvariant_cast<QTransform>(v);
break;
case QVariant::Pixmap:
// dbg.nospace() << qvariant_cast<QPixmap>(v); //FIXME
break;
case QVariant::Image:
// dbg.nospace() << qvariant_cast<QImage>(v); //FIXME
break;
case QVariant::Brush:
dbg.nospace() << qvariant_cast<QBrush>(v);
break;
case QVariant::Color:
dbg.nospace() << qvariant_cast<QColor>(v);
break;
case QVariant::Palette:
// dbg.nospace() << qvariant_cast<QPalette>(v); //FIXME
break;
#ifndef QT_NO_ICON
case QVariant::Icon:
// dbg.nospace() << qvariant_cast<QIcon>(v); // FIXME
break;
#endif
case QVariant::SizePolicy:
// dbg.nospace() << qvariant_cast<QSizePolicy>(v); //FIXME
break;
#ifndef QT_NO_SHORTCUT
case QVariant::KeySequence:
dbg.nospace() << qvariant_cast<QKeySequence>(v);
break;
#endif
case QVariant::Pen:
dbg.nospace() << qvariant_cast<QPen>(v);
break;
#ifndef QT_NO_MATRIX4X4
case QVariant::Matrix4x4:
dbg.nospace() << qvariant_cast<QMatrix4x4>(v);
break;
#endif
#ifndef QT_NO_VECTOR2D
case QVariant::Vector2D:
dbg.nospace() << qvariant_cast<QVector2D>(v);
break;
#endif
#ifndef QT_NO_VECTOR3D
case QVariant::Vector3D:
dbg.nospace() << qvariant_cast<QVector3D>(v);
break;
#endif
#ifndef QT_NO_VECTOR4D
case QVariant::Vector4D:
dbg.nospace() << qvariant_cast<QVector4D>(v);
break;
#endif
#ifndef QT_NO_QUATERNION
case QVariant::Quaternion:
dbg.nospace() << qvariant_cast<QQuaternion>(v);
break;
#endif
default:
qcoreVariantHandler()->debugStream(dbg, v);
break;
}
}
示例14: to_sexp
SEXP to_sexp(QVariant variant) {
SEXP ans = NULL;
switch(variant.type()) {
case QMetaType::Void:
ans = R_NilValue;
break;
case QMetaType::UChar:
ans = ScalarRaw(variant.value<unsigned char>());
break;
case QMetaType::Bool:
ans = ScalarLogical(variant.value<bool>());
break;
case QMetaType::Int:
case QMetaType::UInt:
case QMetaType::Long:
case QMetaType::Short:
case QMetaType::UShort:
ans = ScalarInteger(variant.value<int>());
break;
case QMetaType::Double:
case QMetaType::LongLong:
case QMetaType::ULong:
case QMetaType::ULongLong:
case QMetaType::Float:
ans = ScalarReal(variant.value<double>());
break;
case QMetaType::QChar:
case QMetaType::Char:
case QMetaType::QString:
ans = qstring2sexp(variant.value<QString>());
break;
case QMetaType::QByteArray:
ans = to_sexp(variant.value<QByteArray>());
break;
case QMetaType::VoidStar:
ans = wrapPointer(variant.value<void *>());
break;
case QMetaType::QObjectStar:
ans = ptr_to_sexp(variant.value<QObject *>(),
SmokeType(qt_Smoke, "QObject"));
break;
case QMetaType::QWidgetStar:
ans = ptr_to_sexp(variant.value<QWidget *>(),
SmokeType(qt_Smoke, "QWidget"));
break;
case QMetaType::QCursor:
ans = QVARIANT_TO_SEXP(variant, QCursor);
break;
case QMetaType::QDate:
ans = QVARIANT_TO_SEXP(variant, QDate);
break;
case QMetaType::QSize:
ans = QVARIANT_TO_SEXP(variant, QSize);
case QMetaType::QSizeF:
ans = QVARIANT_TO_SEXP(variant, QSizeF);
break;
case QMetaType::QTime:
ans = QVARIANT_TO_SEXP(variant, QTime);
break;
case QMetaType::QVariantList:
ans = to_sexp(variant.value<QVariantList>(),
SmokeType(qt_Smoke, "QList<QVariant>"));
break;
case QMetaType::QPolygon:
ans = QVARIANT_TO_SEXP(variant, QPolygon);
break;
case QMetaType::QColor:
ans = QVARIANT_TO_SEXP(variant, QColor);
break;
case QMetaType::QRectF:
ans = QVARIANT_TO_SEXP(variant, QRectF);
break;
case QMetaType::QRect:
ans = QVARIANT_TO_SEXP(variant, QRect);
break;
case QMetaType::QLine:
ans = QVARIANT_TO_SEXP(variant, QLine);
break;
case QMetaType::QTextLength:
ans = QVARIANT_TO_SEXP(variant, QTextLength);
break;
case QMetaType::QStringList:
ans = to_sexp(variant.value<QStringList>(),
SmokeType(qt_Smoke, "QStringList"));
break;
case QMetaType::QVariantMap:
ans = to_sexp(variant.value<QVariantMap>(),
SmokeType(qt_Smoke, "QMap<QString,QVariant>"));
break;
case QMetaType::QVariantHash:
ans = to_sexp(variant.value<QVariantHash>(),
SmokeType(qt_Smoke, "QHash<QString,QVariant>"));
break;
case QMetaType::QIcon:
ans = QVARIANT_TO_SEXP(variant, QIcon);
break;
case QMetaType::QPen:
ans = QVARIANT_TO_SEXP(variant, QPen);
break;
case QMetaType::QLineF:
//.........这里部分代码省略.........
示例15: scribus_getproperty
PyObject* scribus_getproperty(PyObject* /*self*/, PyObject* args, PyObject* kw)
{
PyObject* objArg = NULL;
char* propertyName = NULL;
char* kwargs[] = {const_cast<char*>("object"),
const_cast<char*>("property"),
NULL};
if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes", kwargs,
&objArg, "ascii", &propertyName))
return NULL;
// Get the QObject* the object argument refers to
QObject* obj = getQObjectFromPyArg(objArg);
if (!obj)
return NULL;
objArg = NULL; // no need to decref, it's borrowed
// Get the QMetaProperty for the property, so we can check
// if it's a set/enum and do name/value translation.
const QMetaObject* objmeta = obj->metaObject();
int i = objmeta->indexOfProperty(propertyName);
if (i == -1)
{
PyErr_SetString(PyExc_ValueError,
QObject::tr("Property not found").toLocal8Bit().data());
return NULL;
}
QMetaProperty propmeta = objmeta->property(i);
if (!propmeta.isValid())
{
PyErr_SetString(PyExc_ValueError,
QObject::tr("Invalid property").toLocal8Bit().data());
return NULL;
}
// Get the property value as a variant type
QVariant prop = obj->property(propertyName);
// Convert the property to an instance of the closest matching Python type.
PyObject* resultobj = NULL;
// NUMERIC TYPES
if (prop.type() == QVariant::Int)
resultobj = PyLong_FromLong(prop.toInt());
else if (prop.type() == QVariant::Double)
resultobj = PyFloat_FromDouble(prop.toDouble());
// BOOLEAN
else if (prop.type() == QVariant::Bool)
resultobj = PyBool_FromLong(prop.toBool());
// STRING TYPES
else if (prop.type() == QVariant::ByteArray)
resultobj = PyString_FromString(prop.toByteArray().data());
else if (prop.type() == QVariant::String)
resultobj = PyString_FromString(prop.toString().toUtf8().data());
// HIGHER ORDER TYPES
else if (prop.type() == QVariant::Point)
{
// Return a QPoint as an (x,y) tuple.
QPoint pt = prop.toPoint();
return Py_BuildValue("(ii)", pt.x(), pt.y());
}
else if (prop.type() == QVariant::Rect)
{
// Return a QRect as an (x,y,width,height) tuple.
// FIXME: We should really construct and return an object that
// matches the API of QRect and has properties to keep
// left/top/right/bottom and x/y/width/height in sync.
QRect r = prop.toRect();
return Py_BuildValue("(iiii)", r.x(), r.y(), r.width(), r.height());
}
else if (prop.type() == QVariant::StringList)
{
QStringList tmp = prop.toStringList();
return convert_QStringList_to_PyListObject(tmp);
}
// UNHANDLED TYPE
else
{
PyErr_SetString(PyExc_TypeError, QObject::tr("Couldn't convert result type '%1'.").arg(prop.typeName()).toLocal8Bit().constData() );
return resultobj;
}
// Return the resulting Python object
if (resultobj == NULL)
{
// An exception was set while assigning to resultobj
assert(PyErr_Occurred());
return NULL;
}
else
return resultobj;
}