本文整理汇总了C++中QVariant::toInt方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toInt方法的具体用法?C++ QVariant::toInt怎么用?C++ QVariant::toInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
enum SetResponse accountingPeriod::set(const ParameterList &pParams)
{
XDialog::set(pParams);
QVariant param;
bool valid;
param = pParams.value("period_id", &valid);
if (valid)
{
_periodid = param.toInt();
populate();
}
param = pParams.value("mode", &valid);
if (valid)
{
if (param.toString() == "new")
{
_mode = cNew;
_name->setFocus();
q.exec("SELECT period_id "
"FROM period "
"WHERE (period_closed); ");
if (q.first())
_startDate->setEnabled(false);
q.exec("SELECT (LAST(period_end) + 1) AS start_date "
"FROM (SELECT period_end "
" FROM period "
" ORDER BY period_end) AS data; ");
if (q.first())
{
_startDate->setDate(q.value("start_date").toDate());
int pmonth = _startDate->date().month();
QDate pdate = _startDate->date();
while (pmonth == _startDate->date().month())
{
_endDate->setDate(pdate);
pdate = pdate.addDays(1);
pmonth = pdate.month();
}
}
}
else if (param.toString() == "edit")
{
_mode = cEdit;
_startDate->setFocus();
}
else if (param.toString() == "view")
{
_mode = cView;
_name->setEnabled(FALSE);
_startDate->setEnabled(FALSE);
_endDate->setEnabled(FALSE);
_closed->setEnabled(FALSE);
_frozen->setEnabled(FALSE);
_close->setText(tr("&Close"));
_save->hide();
_close->setFocus();
}
}
return NoError;
}
示例2: functionSelect
void PlotDataSelectWidget::functionSelect() {
PlotDataSelect* plotDataSelect = dynamic_cast<PlotDataSelect*>(processor_);
QVariant x = dynamic_cast<QAction*>(sender())->data();
plotDataSelect->selectFunctionalityType(static_cast<FunctionLibrary::ProcessorFunctionalityType>(x.toInt()));
}
示例3: loadSettings
/*
* loads the parameters from the QSettings into the 2 lats tabs
*/
void MainWindow::loadSettings()
{
QSettings settings;
QVariant var;
ui->comboBox_language->setCurrentIndex (settings.value("LANGUAGE").toInt());
QString computer_path = settings.value("COMPUTER_PATH").toString();
if (computer_path.isEmpty())
{
computer_path = QString(DEFAULT_COMPUTER_PATH);
settings.setValue("COMPUTER_PATH", computer_path);
}
ui->LineEdit_computer->setText(computer_path);
if((var = settings.value("LAST_PATH")) == QVariant())
currentWorkingDir = QString();
else
currentWorkingDir = var.toString();
ui->radioButtonStones_real->setChecked(true);
ui->radioButtonStones_2D->setChecked((settings.value("STONES_LOOK")==1));
ui->radioButtonStones_3D->setChecked((settings.value("STONES_LOOK")==2));
ui->radioButton_allGameSound->setChecked(true);
ui->radioButton_noSound->setChecked((settings.value("SOUND")==1));
ui->radioButton_myGamesSound->setChecked((settings.value("SOUND")==2));
ui->LineEdit_goban->setText(settings.value("SKIN").toString());
ui->LineEdit_table->setText(settings.value("SKIN_TABLE").toString());
ui->timerComboBox->setCurrentIndex(settings.value("TIMER_INTERVAL").toInt());
ui->komarkerCB->setChecked((settings.value("KOMARKER") == 1));
ui->numberCurrentMoveCB->setChecked((settings.value("NUMBER_CURRENT_MOVE") == 1));
#ifdef UNNECESSARY
ui->warnOnCloseEditedCB->setChecked((settings.value("WARNONCLOSEEDITED") == 1));
ui->warnOnCloseEngineCB->setChecked((settings.value("WARNONCLOSENGINE") == 1));
#endif //UNNECESSARY
if(settings.value("TERR_STONE_MARK").toBool())
ui->terrStoneRB->setChecked(true);
else
ui->terrCrossRB->setChecked(true);
ui->simplePlayerNamesCB->setChecked((settings.value("SIMPLEPLAYERNAMES") == 1));
ui->observeOutsideCB->setChecked((settings.value("OBSERVEOUTSIDE") == 1));
bool b = (settings.value("ALTERNATELISTCOLORS") == 1);
ui->alternateListColorsCB->setChecked(b);
ui->connectionWidget->slot_alternateListColorsCB(b);
//ui->connectionWidget->ui->serverComboBox->setCurrentIndex(settings.value("ACCOUNT").toInt());
//server games default values
if((var = settings.value("DEFAULT_KOMI")) == QVariant())
var = 5.5;
ui->komiSpinDefault->setValue(var.toInt());
if((var = settings.value("DEFAULT_SIZE")) == QVariant())
var = 19;
ui->boardSizeSpin->setValue(var.toInt());
ui->timeSpin->setValue(settings.value("DEFAULT_TIME").toInt());
ui->BYSpin->setValue(settings.value("DEFAULT_BY").toInt());
ui->checkBox_Nmatch_Black->setChecked(settings.value("NMATCH_BLACK", QVariant(true)).toBool());
ui->checkBox_Nmatch_White->setChecked(settings.value("NMATCH_WHITE", QVariant(true)).toBool());
ui->checkBox_Nmatch_Nigiri->setChecked(settings.value("NMATCH_NIGIRI", QVariant(true)).toBool());
ui->HandicapSpin_Nmatch->setValue(settings.value("NMATCH_HANDICAP", QVariant(8)).toInt());
ui->timeSpin_Nmatch->setValue(settings.value("NMATCH_MAIN_TIME", QVariant(99)).toInt());
ui->BYSpin_Nmatch->setValue(settings.value("NMATCH_BYO_TIME", QVariant(60)).toInt());
ui->CheckBox_autoSave->setChecked(settings.value("AUTOSAVE").toBool());
ui->CheckBox_autoSave_Played->setChecked(settings.value("AUTOSAVE_PLAYED").toBool());
//server byo yomi warning
ui->ByoSoundWarning->setChecked(settings.value("BYO_SOUND_WARNING").toBool());
ui->ByoSecWarning->setValue(settings.value("BYO_SEC_WARNING").toInt());
preferences.fill();
}
示例4: qwtBorderMask
static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )
{
const QRect r( 0, 0, size.width(), size.height() );
QPainterPath borderPath;
( void )QMetaObject::invokeMethod(
const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,
Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) );
if ( borderPath.isEmpty() )
{
if ( canvas->contentsRect() == canvas->rect() )
return QBitmap();
QBitmap mask( size );
mask.fill( Qt::color0 );
QPainter painter( &mask );
painter.fillRect( canvas->contentsRect(), Qt::color1 );
return mask;
}
QImage image( size, QImage::Format_ARGB32_Premultiplied );
image.fill( Qt::color0 );
QPainter painter( &image );
painter.setClipPath( borderPath );
painter.fillRect( r, Qt::color1 );
// now erase the frame
painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );
if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
{
QStyleOptionFrame opt;
opt.initFrom(canvas);
opt.rect = r;
canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas );
}
else
{
const QVariant borderRadius = canvas->property( "borderRadius" );
const QVariant frameWidth = canvas->property( "frameWidth" );
if ( borderRadius.type() == QVariant::Double
&& frameWidth.type() == QVariant::Int )
{
const double br = borderRadius.toDouble();
const int fw = frameWidth.toInt();
if ( br > 0.0 && fw > 0 )
{
painter.setPen( QPen( Qt::color1, fw ) );
painter.setBrush( Qt::NoBrush );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.drawPath( borderPath );
}
}
}
painter.end();
const QImage mask = image.createMaskFromColor(
QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );
return QBitmap::fromImage( mask );
}
示例5: updateStatus
void ProgressInformationWidget::updateStatus(WebWidget::PageInformation key, const QVariant &value)
{
switch (m_type)
{
case DocumentProgressType:
if (key == WebWidget::DocumentLoadingProgressInformation)
{
const bool isValid(value.toInt() >= 0);
m_progressBar->setFormat(isValid ? tr("Document: %p%") : tr("Document: ?"));
m_progressBar->setValue(isValid ? value.toInt() : 0);
}
break;
case TotalProgressType:
if (key == WebWidget::TotalLoadingProgressInformation)
{
m_progressBar->setFormat((value.toInt() < 0) ? tr("Total: ?") : tr("Total: %p%"));
m_progressBar->setValue(value.toInt());
}
break;
case TotalSizeType:
if (key == WebWidget::BytesReceivedInformation)
{
m_label->setText(tr("Total: %1").arg(Utils::formatUnit(value.toULongLong(), false, 1)));
}
break;
case ElementsType:
if (key == WebWidget::RequestsFinishedInformation)
{
m_label->setText(tr("Elements: %1/%2").arg(value.toInt()).arg(m_window ? m_window->getContentsWidget()->getPageInformation(WebWidget::RequestsStartedInformation).toInt() : 0));
}
break;
case SpeedType:
if (key == WebWidget::LoadingSpeedInformation)
{
m_label->setText(tr("Speed: %1").arg(Utils::formatUnit(value.toULongLong(), true, 1)));
}
break;
case ElapsedTimeType:
if (key == WebWidget::LoadingTimeInformation)
{
int minutes(value.toInt() / 60);
int seconds(value.toInt() - (minutes * 60));
m_label->setText(tr("Time: %1").arg(QStringLiteral("%1:%2").arg(minutes).arg(seconds, 2, 10, QLatin1Char('0'))));
}
break;
case MessageType:
if (key == WebWidget::LoadingMessageInformation)
{
m_label->setText(value.toString());
}
break;
default:
break;
}
}
示例6: neededRect
QRect KisFilterWave::neededRect(const QRect& rect, const KisFilterConfiguration* config) const
{
QVariant value;
int horizontalamplitude = (config && config->getProperty("horizontalamplitude", value)) ? value.toInt() : 4;
int verticalamplitude = (config && config->getProperty("verticalamplitude", value)) ? value.toInt() : 4;
return rect.adjusted(-horizontalamplitude, -verticalamplitude, horizontalamplitude, verticalamplitude);
}
示例7: setDataDefinedValues
void QgsLabelPropertyDialog::setDataDefinedValues( QgsVectorLayer *vlayer )
{
//loop through data defined properties and set all the GUI widget values. We can do this
//even if the data defined property is set to an expression, as it's useful to show
//users what the evaluated property is...
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( QgsProject::instance() )
<< QgsExpressionContextUtils::atlasScope( nullptr )
<< QgsExpressionContextUtils::mapSettingsScope( QgisApp::instance()->mapCanvas()->mapSettings() )
<< QgsExpressionContextUtils::layerScope( vlayer );
context.setFeature( mCurLabelFeat );
Q_FOREACH ( int key, mDataDefinedProperties.propertyKeys() )
{
if ( !mDataDefinedProperties.isActive( key ) )
continue;
//TODO - pass expression context
QVariant result = mDataDefinedProperties.value( key, context );
if ( !result.isValid() || result.isNull() )
{
//could not evaluate data defined value
continue;
}
bool ok = false;
switch ( key )
{
case QgsPalLayerSettings::Show:
{
int showLabel = result.toInt( &ok );
mShowLabelChkbx->setChecked( !ok || showLabel != 0 );
break;
}
case QgsPalLayerSettings::AlwaysShow:
mAlwaysShowChkbx->setChecked( result.toBool() );
break;
case QgsPalLayerSettings::MinimumScale:
{
double minScale = result.toDouble( &ok );
if ( ok )
{
mMinScaleWidget->setScale( minScale );
}
break;
}
case QgsPalLayerSettings::MaximumScale:
{
double maxScale = result.toDouble( &ok );
if ( ok )
{
mMaxScaleWidget->setScale( maxScale );
}
break;
}
case QgsPalLayerSettings::BufferSize:
{
double bufferSize = result.toDouble( &ok );
if ( ok )
{
mBufferSizeSpinBox->setValue( bufferSize );
}
break;
}
case QgsPalLayerSettings::PositionX:
{
double posX = result.toDouble( &ok );
if ( ok )
{
mXCoordSpinBox->setValue( posX );
}
break;
}
case QgsPalLayerSettings::PositionY:
{
double posY = result.toDouble( &ok );
if ( ok )
{
mYCoordSpinBox->setValue( posY );
}
break;
}
case QgsPalLayerSettings::LabelDistance:
{
double labelDist = result.toDouble( &ok );
if ( ok )
{
mLabelDistanceSpinBox->setValue( labelDist );
}
break;
}
case QgsPalLayerSettings::Hali:
mHaliComboBox->setCurrentIndex( mHaliComboBox->findData( result.toString() ) );
break;
case QgsPalLayerSettings::Vali:
mValiComboBox->setCurrentIndex( mValiComboBox->findData( result.toString() ) );
break;
case QgsPalLayerSettings::BufferColor:
//.........这里部分代码省略.........
示例8: macValue
static QCFType<CFPropertyListRef> macValue(const QVariant &value)
{
CFPropertyListRef result = 0;
switch (value.type()) {
case QVariant::ByteArray:
{
QByteArray ba = value.toByteArray();
result = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(ba.data()),
CFIndex(ba.size()));
}
break;
// should be same as below (look for LIST)
case QVariant::List:
case QVariant::StringList:
case QVariant::Polygon:
result = macList(value.toList());
break;
case QVariant::Map:
{
/*
QMap<QString, QVariant> is potentially a multimap,
whereas CFDictionary is a single-valued map. To allow
for multiple values with the same key, we store
multiple values in a CFArray. To avoid ambiguities,
we also wrap lists in a CFArray singleton.
*/
QMap<QString, QVariant> map = value.toMap();
QMap<QString, QVariant>::const_iterator i = map.constBegin();
int maxUniqueKeys = map.size();
int numUniqueKeys = 0;
QVarLengthArray<QCFType<CFPropertyListRef> > cfkeys(maxUniqueKeys);
QVarLengthArray<QCFType<CFPropertyListRef> > cfvalues(maxUniqueKeys);
while (i != map.constEnd()) {
const QString &key = i.key();
QList<QVariant> values;
do {
values << i.value();
++i;
} while (i != map.constEnd() && i.key() == key);
bool singleton = (values.count() == 1);
if (singleton) {
switch (values.first().type()) {
// should be same as above (look for LIST)
case QVariant::List:
case QVariant::StringList:
case QVariant::Polygon:
singleton = false;
default:
;
}
}
cfkeys[numUniqueKeys] = QCFString::toCFStringRef(key);
cfvalues[numUniqueKeys] = singleton ? macValue(values.first()) : macList(values);
++numUniqueKeys;
}
result = CFDictionaryCreate(kCFAllocatorDefault,
reinterpret_cast<const void **>(cfkeys.data()),
reinterpret_cast<const void **>(cfvalues.data()),
CFIndex(numUniqueKeys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
break;
case QVariant::DateTime:
{
/*
CFDate, unlike QDateTime, doesn't store timezone information.
*/
QDateTime dt = value.toDateTime();
if (dt.timeSpec() == Qt::LocalTime) {
QDateTime reference;
reference.setTime_t((uint)kCFAbsoluteTimeIntervalSince1970);
result = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTime(reference.secsTo(dt)));
} else {
goto string_case;
}
}
break;
case QVariant::Bool:
result = value.toBool() ? kCFBooleanTrue : kCFBooleanFalse;
break;
case QVariant::Int:
case QVariant::UInt:
{
int n = value.toInt();
result = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n);
}
break;
case QVariant::Double:
{
double n = value.toDouble();
result = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &n);
}
//.........这里部分代码省略.........
示例9: variantToPythonLiteral
QString QgsProcessingUtils::variantToPythonLiteral( const QVariant &value )
{
if ( !value.isValid() )
return QStringLiteral( "None" );
if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
else if ( value.canConvert<QgsCoordinateReferenceSystem>() )
{
if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
return QStringLiteral( "QgsCoordinateReferenceSystem()" );
else
return QStringLiteral( "QgsCoordinateReferenceSystem('%1')" ).arg( value.value< QgsCoordinateReferenceSystem >().authid() );
}
else if ( value.canConvert< QgsRectangle >() )
{
QgsRectangle r = value.value<QgsRectangle>();
return QStringLiteral( "'%1, %3, %2, %4'" ).arg( qgsDoubleToString( r.xMinimum() ),
qgsDoubleToString( r.yMinimum() ),
qgsDoubleToString( r.xMaximum() ),
qgsDoubleToString( r.yMaximum() ) );
}
else if ( value.canConvert< QgsReferencedRectangle >() )
{
QgsReferencedRectangle r = value.value<QgsReferencedRectangle>();
return QStringLiteral( "'%1, %3, %2, %4 [%5]'" ).arg( qgsDoubleToString( r.xMinimum() ),
qgsDoubleToString( r.yMinimum() ),
qgsDoubleToString( r.xMaximum() ),
qgsDoubleToString( r.yMaximum() ), r.crs().authid() );
}
else if ( value.canConvert< QgsPointXY >() )
{
QgsPointXY r = value.value<QgsPointXY>();
return QStringLiteral( "'%1,%2'" ).arg( qgsDoubleToString( r.x() ),
qgsDoubleToString( r.y() ) );
}
else if ( value.canConvert< QgsReferencedPointXY >() )
{
QgsReferencedPointXY r = value.value<QgsReferencedPointXY>();
return QStringLiteral( "'%1,%2 [%3]'" ).arg( qgsDoubleToString( r.x() ),
qgsDoubleToString( r.y() ),
r.crs().authid() );
}
switch ( value.type() )
{
case QVariant::Bool:
return value.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
case QVariant::Double:
return QString::number( value.toDouble() );
case QVariant::Int:
case QVariant::UInt:
return QString::number( value.toInt() );
case QVariant::LongLong:
case QVariant::ULongLong:
return QString::number( value.toLongLong() );
case QVariant::List:
{
QStringList parts;
const QVariantList vl = value.toList();
for ( const QVariant &v : vl )
{
parts << variantToPythonLiteral( v );
}
return parts.join( ',' ).prepend( '[' ).append( ']' );
}
default:
break;
}
return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
}
示例10: accept
bool DlgFilletEdges::accept()
{
if (!d->object) {
QMessageBox::warning(this, tr("No shape selected"),
tr("No valid shape is selected.\n"
"Please select a valid shape in the drop-down box first."));
return false;
}
App::Document* activeDoc = App::GetApplication().getActiveDocument();
QAbstractItemModel* model = ui->treeView->model();
bool end_radius = !ui->treeView->isColumnHidden(2);
bool todo = false;
QString shape, type, name;
std::string fillet = getFilletType();
int index = ui->shapeObject->currentIndex();
shape = ui->shapeObject->itemData(index).toString();
type = QString::fromAscii("Part::%1").arg(QString::fromAscii(fillet.c_str()));
if (d->fillet)
name = QString::fromAscii(d->fillet->getNameInDocument());
else
name = QString::fromAscii(activeDoc->getUniqueObjectName(fillet.c_str()).c_str());
activeDoc->openTransaction(fillet.c_str());
QString code;
if (!d->fillet) {
code = QString::fromAscii(
"FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
"FreeCAD.ActiveDocument.%2.Base = FreeCAD.ActiveDocument.%3\n")
.arg(type).arg(name).arg(shape);
}
code += QString::fromAscii("__fillets__ = []\n");
for (int i=0; i<model->rowCount(); ++i) {
QVariant value = model->index(i,0).data(Qt::CheckStateRole);
Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
// is item checked
if (checkState & Qt::Checked) {
// the index value of the edge
int id = model->index(i,0).data(Qt::UserRole).toInt();
double r1 = model->index(i,1).data().toDouble();
double r2 = r1;
if (end_radius)
r2 = model->index(i,2).data().toDouble();
code += QString::fromAscii(
"__fillets__.append((%1,%2,%3))\n")
.arg(id).arg(r1,0,'f',2).arg(r2,0,'f',2);
todo = true;
}
}
if (!todo) {
QMessageBox::warning(this, tr("No edge selected"),
tr("No edge entity is checked to fillet.\n"
"Please check one or more edge entities first."));
return false;
}
Gui::WaitCursor wc;
code += QString::fromAscii(
"FreeCAD.ActiveDocument.%1.Edges = __fillets__\n"
"del __fillets__\n"
"FreeCADGui.ActiveDocument.%2.Visibility = False\n")
.arg(name).arg(shape);
Gui::Application::Instance->runPythonCode((const char*)code.toAscii());
activeDoc->commitTransaction();
activeDoc->recompute();
if (d->fillet) {
Gui::ViewProvider* vp;
vp = Gui::Application::Instance->getViewProvider(d->fillet);
if (vp) vp->show();
}
QByteArray to = name.toAscii();
QByteArray from = shape.toAscii();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from);
return true;
}
示例11: 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();
}
示例12: renderCanvas
/*!
Render the canvas into a given rectangle.
\param plot Plot widget
\param painter Painter
\param map Maps mapping between plot and paint device coordinates
\param canvasRect Canvas rectangle
*/
void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,
QPainter *painter, const QRectF &canvasRect,
const QwtScaleMapTable &mapTable ) const
{
const QWidget *canvas = plot->canvas();
QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
if ( d_data->layoutFlags & FrameWithScales )
{
painter->save();
r.adjust( -1.0, -1.0, 1.0, 1.0 );
painter->setPen( QPen( Qt::black ) );
if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
{
const QBrush bgBrush =
canvas->palette().brush( plot->backgroundRole() );
painter->setBrush( bgBrush );
}
QwtPainter::drawRect( painter, r );
painter->restore();
painter->save();
painter->setClipRect( canvasRect );
plot->drawItems( painter, canvasRect, mapTable );
painter->restore();
}
else if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
{
QPainterPath clipPath;
painter->save();
if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
{
QwtPainter::drawBackgound( painter, r, canvas );
clipPath = qwtCanvasClip( canvas, canvasRect );
}
painter->restore();
painter->save();
if ( clipPath.isEmpty() )
painter->setClipRect( canvasRect );
else
painter->setClipPath( clipPath );
plot->drawItems( painter, canvasRect, mapTable );
painter->restore();
}
else
{
QPainterPath clipPath;
int frameWidth = 0;
if ( !( d_data->discardFlags & DiscardCanvasFrame ) )
{
const QVariant fw = canvas->property( "frameWidth" );
if ( fw.type() == QVariant::Int )
frameWidth = fw.toInt();
clipPath = qwtCanvasClip( canvas, canvasRect );
}
QRectF innerRect = canvasRect.adjusted(
frameWidth, frameWidth, -frameWidth, -frameWidth );
painter->save();
if ( clipPath.isEmpty() )
{
painter->setClipRect( innerRect );
}
else
{
painter->setClipPath( clipPath );
}
if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
{
QwtPainter::drawBackgound( painter, innerRect, canvas );
}
plot->drawItems( painter, innerRect, mapTable );
//.........这里部分代码省略.........
示例13: if
static QVariantList
qml_from_dbus(QVariant v)
{
QVariantList r;
const char *type=v.typeName();
switch (v.type()) {
case QVariant::ULongLong:
r.append("uint64");
r.append(v.toULongLong());
break;
case QVariant::UInt:
r.append("uint32");
r.append(v.toUInt());
break;
case QVariant::Int:
r.append("int32");
r.append(v.toInt());
break;
case QMetaType::UShort:
r.append("uint16");
r.append(v.toUInt());
break;
case QMetaType::UChar:
r.append("uint8");
r.append(v.toUInt());
break;
case QVariant::String:
r.append("string");
r.append(v.toString());
break;
case QVariant::Bool:
r.append("bool");
r.append(v.toBool());
break;
case QVariant::Double:
r.append("double");
r.append(v.toDouble());
break;
case QVariant::UserType:
if (!strcmp(type,"QDBusArgument")) {
const QDBusArgument arg=v.value < QDBusArgument>();
QVariantList rl;
switch(arg.currentType()) {
case QDBusArgument::ArrayType:
r.append("array");
arg.beginArray();
while (!arg.atEnd()) {
rl.append(qml_from_dbus(arg.asVariant()));
}
r.append(QVariant(rl));
break;
case QDBusArgument::StructureType:
r.append("structure");
arg.beginStructure();
while (!arg.atEnd()) {
rl.append(qml_from_dbus(arg.asVariant()));
}
arg.endStructure();
r.append(QVariant(rl));
break;
case QDBusArgument::MapType:
r.append("map");
arg.beginMap();
while (!arg.atEnd()) {
arg.beginMapEntry();
rl.append(qml_from_dbus(arg.asVariant()));
rl.append(qml_from_dbus(arg.asVariant()));
arg.endMapEntry();
}
arg.endMap();
r.append(QVariant(rl));
break;
case QDBusArgument::UnknownType:
break;
default:
printf("Unknown type %d\n",arg.currentType());
break;
}
} else if (!strcmp(type,"QDBusVariant")) {
const QDBusVariant arg=v.value < QDBusVariant>();
QVariantList rl;
r.append("variant");
rl.append(qml_from_dbus(arg.variant()));
r.append(QVariant(rl));
} else {
printf("User type %s\n",v.typeName());
}
break;
default:
fprintf(stderr,"Unsupported Arg %s(%d)\n",type,v.type());
}
return r;
}
示例14: setData
// write QSettings values
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
QSettings settings;
switch(index.row())
{
case StartAtStartup:
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
break;
case MinimizeToTray:
fMinimizeToTray = value.toBool();
settings.setValue("fMinimizeToTray", fMinimizeToTray);
break;
case MapPortUPnP: // core option - can be changed on-the-fly
settings.setValue("fUseUPnP", value.toBool());
MapPort(value.toBool());
break;
case MinimizeOnClose:
fMinimizeOnClose = value.toBool();
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
break;
// default proxy
case ProxyUse:
if (settings.value("fUseProxy") != value) {
settings.setValue("fUseProxy", value.toBool());
setRestartRequired(true);
}
break;
case ProxyIP: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
settings.setValue("addrProxy", strNewValue);
setRestartRequired(true);
}
}
break;
case ProxyPort: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed port
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
settings.setValue("addrProxy", strNewValue);
setRestartRequired(true);
}
}
break;
// separate Tor proxy
case ProxyUseTor:
if (settings.value("fUseSeparateProxyTor") != value) {
settings.setValue("fUseSeparateProxyTor", value.toBool());
setRestartRequired(true);
}
break;
case ProxyIPTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
settings.setValue("addrSeparateProxyTor", strNewValue);
setRestartRequired(true);
}
}
break;
case ProxyPortTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed port
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
settings.setValue("addrSeparateProxyTor", strNewValue);
setRestartRequired(true);
}
}
break;
#ifdef ENABLE_WALLET
case SpendZeroConfChange:
if (settings.value("bSpendZeroConfChange") != value) {
settings.setValue("bSpendZeroConfChange", value);
setRestartRequired(true);
}
break;
#endif
case AdvertisedBalance:
nAdvertisedBalance = value.toInt();
settings.setValue("nAdvertisedBalance", (int) nAdvertisedBalance);
emit advertisedBalanceChanged(nAdvertisedBalance);
//.........这里部分代码省略.........
示例15: variantToElement
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
bool ok = true;
clearAttributes(e);
switch (v.type())
{
case QVariant::String:
e.setTagName("string");
e.setAttribute("value", v.toString().utf8());
break;
case QVariant::CString:
e.setTagName("string");
e.setAttribute("value", v.toCString());
break;
case QVariant::Int:
e.setTagName("int");
e.setAttribute("value", v.toInt());
break;
case QVariant::UInt:
e.setTagName("uint");
e.setAttribute("value", v.toUInt());
break;
case QVariant::Double:
e.setTagName("double");
e.setAttribute("value", v.toDouble());
break;
case QVariant::Bool:
e.setTagName("bool");
e.setAttribute("value", boolString(v.toBool()));
break;
case QVariant::Color:
{
e.setTagName("color");
QColor color = v.toColor();
e.setAttribute("red", color.red());
e.setAttribute("green", color.green());
e.setAttribute("blue", color.blue());
}
break;
case QVariant::Point:
{
e.setTagName("point");
QPoint point = v.toPoint();
e.setAttribute("x", point.x());
e.setAttribute("y", point.y());
}
break;
case QVariant::Rect:
{
e.setTagName("rect");
QRect rect = v.toRect();
e.setAttribute("x", rect.x());
e.setAttribute("y", rect.y());
e.setAttribute("width", rect.width());
e.setAttribute("height", rect.height());
}
break;
case QVariant::Size:
{
e.setTagName("size");
QSize qsize = v.toSize();
e.setAttribute("width", qsize.width());
e.setAttribute("height", qsize.height());
}
break;
case QVariant::Font:
{
e.setTagName("font");
QFont f(v.toFont());
e.setAttribute("family", f.family());
e.setAttribute("pointsize", f.pointSize());
e.setAttribute("bold", boolString(f.bold()));
e.setAttribute("italic", boolString(f.italic()));
e.setAttribute("underline", boolString(f.underline()));
e.setAttribute("strikeout", boolString(f.strikeOut()));
}
break;
case QVariant::SizePolicy:
{
e.setTagName("sizepolicy");
QSizePolicy sp(v.toSizePolicy());
e.setAttribute("hsizetype", sp.horData());
e.setAttribute("vsizetype", sp.verData());
#if (QT_VERSION >= 300)
e.setAttribute("horstretch", sp.horStretch());
e.setAttribute("verstretch", sp.verStretch());
#endif
}
break;
case QVariant::Cursor:
e.setTagName("cursor");
e.setAttribute("shape", v.toCursor().shape());
break;
case QVariant::StringList:
{
e.setTagName("stringlist");
uint j;
//.........这里部分代码省略.........