本文整理汇总了C++中QVariant::canConvert方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::canConvert方法的具体用法?C++ QVariant::canConvert怎么用?C++ QVariant::canConvert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::canConvert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: quotedValue
QString QgsOracleConn::quotedValue( const QVariant &value, QVariant::Type type )
{
if ( value.isNull() )
return "NULL";
if ( type == QVariant::Invalid )
type = value.type();
if ( value.canConvert( type ) )
{
switch ( type )
{
case QVariant::Int:
case QVariant::LongLong:
case QVariant::Double:
return value.toString();
case QVariant::DateTime:
{
QDateTime datetime( value.toDateTime() );
if ( datetime.isValid() )
return QString( "TO_DATE('%1','YYYY-MM-DD HH24:MI:SS')" ).arg( datetime.toString( "yyyy-MM-dd hh:mm:ss" ) );
break;
}
case QVariant::Date:
{
QDate date( value.toDate() );
if ( date.isValid() )
return QString( "TO_DATE('%1','YYYY-MM-DD')" ).arg( date.toString( "yyyy-MM-dd" ) );
break;
}
case QVariant::Time:
{
QDateTime datetime( value.toDateTime() );
if ( datetime.isValid() )
return QString( "TO_DATE('%1','HH24:MI:SS')" ).arg( datetime.toString( "hh:mm:ss" ) );
break;
}
default:
break;
}
}
QString v = value.toString();
v.replace( "'", "''" );
v.replace( "\\\"", "\\\\\"" );
return v.prepend( "'" ).append( "'" );
}
示例2: mafMemento
mafMementoObject::mafMementoObject(const mafObject *obj, const QString code_location) : mafMemento(obj, code_location) {
mafMementoPropertyList *list = mementoPropertyList();
int i = 0;
const QMetaObject *meta = obj->metaObject();
int num = meta->propertyCount();
for ( ; i < num; ++i) {
mafMementoPropertyItem item;
const QMetaProperty qmp = meta->property(i);
QString propName = qmp.name();
QVariant value = obj->property(propName.toAscii());
if (value.canConvert(QVariant::List)) {
item.m_Multiplicity = value.toList().count();
} else if(value.canConvert(QVariant::Map)) {
item.m_Multiplicity = value.toMap().count();
} else if(value.canConvert(QVariant::Hash)) {
item.m_Multiplicity = value.toHash().count();
} else {
item.m_Multiplicity = 1;
}
item.m_Name = qmp.name();
item.m_Value = value;
list->append(item);
}
mafMementoPropertyItem itemTagList;
itemTagList.m_Multiplicity = obj->tagList()->count();
itemTagList.m_Name = "TagList";
itemTagList.m_Value = *obj->tagList();
list->append(itemTagList);
mafMementoPropertyItem itemDic;
itemDic.m_Multiplicity = obj->dictionary()->count();
itemDic.m_Name = "dictionary";
itemDic.m_Value = *(obj->dictionary());
list->append(itemDic);
}
示例3: QVBoxLayout
DefaultDataForm::DefaultDataForm(const DataItem &item) :
m_widget(0),
m_isChanged(false),
m_incompleteWidgets(0),
m_buttonsBox(0),
m_hasSubitems(item.hasSubitems() || item.isAllowedModifySubitems())
{
DataLayout *dataLayout = 0;
QVBoxLayout *layout = 0;
setObjectName(item.name());
setWindowTitle(item.title());
if (item.isAllowedModifySubitems()) {
layout = new QVBoxLayout(this);
ModifiableWidget *w = new ModifiableWidget(item, this, this);
m_widget = w;
layout->addWidget(w);
if (!w->isExpandable()) {
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout->addItem(spacer);
}
} else {
dataLayout = new DataLayout(item, this, item.property<quint16>("columns", 1), this);
QVariant spacing = item.property("horizontalSpacing");
if (spacing.canConvert(QVariant::Int))
dataLayout->setHorizontalSpacing(spacing.toInt());
spacing = item.property("verticalSpacing");
if (spacing.canConvert(QVariant::Int))
dataLayout->setVerticalSpacing(spacing.toInt());
m_widget = dataLayout;
if (item.hasSubitems())
dataLayout->addDataItems(item.subitems());
else
dataLayout->addDataItem(item);
if (!dataLayout->isExpandable())
dataLayout->addSpacer();
}
}
示例4: changeProperty
bool QAbstractDiagramGraphicsItem::changeProperty(const QString & name, const QVariant & value)
{
QDiagramMetaProperty metaProperty = m_metadata->property(m_metadata->indexOfProperty(name));
// Check if property is dynamic
if (!metaProperty.isValid()){
// Check if dynamic property has changed
if (m_dynamicProperties.value(name) != value){
m_dynamicProperties[name] = value;
itemPropertyHasChanged(name, value);
}
return false;
}
// Check if static property is read only
if (metaProperty.isReadOnly()){
// Property is read only
return false;
}
QVariant currentValue = m_properties.value(name);
if (currentValue != value){
if (name == "brush"){
m_brush = brush(value.toString());
} else if (name == "geometry"){
if (value.canConvert(QVariant::RectF)){
prepareGeometryChange();
setPos(value.toRectF().x(), value.toRectF().y());
} else if (value.canConvert(QVariant::Map)){
prepareGeometryChange();
setPos(value.toMap().value("x").toDouble(), value.toMap().value("y").toDouble());
}
m_properties[name] = value;
itemGeometryHasChanged(value);
} else {
m_properties[name] = value;
}
itemPropertyHasChanged(name, value);
}
return true;
}
示例5: _phoneState
void DbusAdapter::_phoneState(QDBusMessage msg) {
qDebug() << "Got phone call state dbus message:" << msg;
QList<QVariant> outArgs = msg.arguments();
QVariant state = outArgs.at(0);
if (state.canConvert(QVariant::String) && state.toString() == "State") {
qDebug() <<"Phone Call State";
QVariant argument = outArgs.at(1);
const QVariant v = qvariant_cast<QDBusVariant>(argument).variant();
if (v.canConvert(QVariant::String)) {
if (v.toString() == "active"){
emit phoneCallStart();
qDebug() << v.toString();
}
if (v.toString() == "disconnected"){
emit phoneCallEnd();
qDebug() << v.toString();
}
}
}else{
qDebug() <<"No State ";
}
}
示例6: isDuplicate
bool TreeModel::isDuplicate(TreeItem *item, QString str)
{
QList<TreeItem*> items = item->childItems;
int count = items.count();
for(int n = 0; n < count; n++)
{
QVariant qv = items.at(n)->data(0);
if(qv.canConvert(QVariant::String)) {
if(qv.toString() == str)
return true;
}
}
return false;
}
示例7: valueChanged
void
LineStyleEdit::setValue(const QVariant &value, bool emitChange)
{
if (!value.canConvert(QVariant::Int))
return;
if ((value.toInt() > 5) || (value.toInt() < 0))
return;
m_edit->blockSignals(true);
m_edit->setCurrentIndex(value.toInt());
m_edit->blockSignals(false);
if (emitChange)
emit valueChanged(this);
}
示例8: if
inline KData::ContentType guessType(const QVariant & v) {
KData::ContentType t;
if (!v.isValid())
t = KData::Undefined;
else if (v.type() == QVariant::Bool)
t = KData::Boolean;
else if (v.type() == QVariant::String)
t = KData::Text;
else if (v.canConvert(QVariant::Double))
t = KData::Numeric;
else
t = KData::Object;
return t;
}
示例9: filePath
QString Hdd::filePath(const Plasma::DataEngine::Data &data)
{
QString label = data["File Path"].toString();
QVariant accessible = data["Accessible"];
if (accessible.isValid()) {
if (accessible.canConvert(QVariant::Bool)) {
if (!accessible.toBool()) {
label = i18nc("hard disk label (not mounted or accessible)",
"%1 (not accessible)", label);
}
}
}
return label;
}
示例10: convertArgs
bool JsonRpcServer::convertArgs(const QMetaMethod& meta_method,
const QVariantMap& args,
QVariantList& converted_args)
{
QList<QByteArray> param_types = meta_method.parameterTypes();
if (args.size() != param_types.size()) {
logError(QString("wrong number of arguments to method %1 -- "
"expected %2 arguments, but got %3")
.arg(QString(meta_method.methodSignature()))
.arg(meta_method.parameterCount())
.arg(args.size()));
return false;
}
for (int i = 0; i < param_types.size(); i++) {
QByteArray param_name = meta_method.parameterNames().at(i);
if (args.find(param_name) == args.end()) {
// no arg with param name found
return false;
}
const QVariant& arg = args.value(param_name);
if (!arg.isValid()) {
logError(QString("argument %1 of %2 to method %3 is invalid")
.arg(i + 1)
.arg(param_types.size())
.arg(QString(meta_method.methodSignature())));
return false;
}
QByteArray arg_type_name = arg.typeName();
QByteArray param_type_name = param_types.at(i);
QVariant::Type param_type = QVariant::nameToType(param_type_name);
QVariant copy = QVariant(arg);
if (copy.type() != param_type) {
if (copy.canConvert(param_type)) {
if (!copy.convert(param_type)) {
// qDebug() << "cannot convert" << arg_type_name
// << "to" << param_type_name;
return false;
}
}
}
converted_args << copy;
}
return true;
}
示例11: loadBoards
/*
* load board from xbasic config file using xBasicConfig
*/
void Hardware::loadBoards()
{
QSettings settings(publisherKey, xBasicGuiKey, this);
QVariant sv = settings.value(configFileKey);
if(sv.canConvert(QVariant::String))
xBasicCfgFile = sv.toString();
sv = settings.value(separatorKey);
if(sv.canConvert(QVariant::String))
xBasicSeparator = sv.toString();
if(xBasicConfig->loadBoards(xBasicCfgFile) == 0)
return;
/* get board types */
QStringList boards = xBasicConfig->getBoardNames();
ui->comboBoxBoard->clear();
for(int n = 0; n < boards.count(); n++) {
ui->comboBoxBoard->addItem(boards.at(n));
}
/* load first board info */
XBasicBoard *brd = xBasicConfig->getBoardData(ui->comboBoxBoard->itemText(0));
setDialogBoardInfo(brd);
}
示例12: setupOptions
void Properties::setupOptions()
{
QFrame *frame = new QFrame(this);
QHBoxLayout *hlayout = new QHBoxLayout();
QFormLayout *edlayout = new QFormLayout(this);
QGroupBox *editor = new QGroupBox(tr("Editor Settings"));
editor->setLayout(edlayout);
QFormLayout *otlayout = new QFormLayout(this);
QGroupBox *other = new QGroupBox(tr("Other Settings"));
other->setLayout(otlayout);
hlayout->addWidget(editor);
hlayout->addWidget(other);
frame->setLayout(hlayout);
tabWidget.addTab(frame,"General");
QSettings settings(publisherKey, PropellerIdeGuiKey,this);
QVariant enac = settings.value(enableAutoComplete,true);
QVariant enss = settings.value(enableSpinSuggest,true);
autoCompleteEnable.setChecked(enac.toBool());
edlayout->addRow(new QLabel(tr("Enable AutoComplete")), &autoCompleteEnable);
spinSuggestEnable.setChecked(enss.toBool());
edlayout->addRow(new QLabel(tr("Enable Code Suggestion")), &spinSuggestEnable);
#if ENABLE_PORT_BOARD_NAMES
portBoardNameEnable.setChecked(false);
portBoardNameEnable.setDisabled(true);
otlayout->addRow(new QLabel(tr("Enable Port Board Names")), &portBoardNameEnable);
#endif
QVariant tabsv = settings.value(tabSpacesKey,"4");
if(tabsv.canConvert(QVariant::String)) {
tabspaceLedit.setText(tabsv.toString());
}
else {
tabspaceLedit.setText("4");
}
edlayout->addRow(new QLabel(tr("Editor Tab Space Count")), &tabspaceLedit);
clearSettingsButton.setText("Clear Settings");
clearSettingsButton.setToolTip(tr("Clear Settings on Exit"));
connect(&clearSettingsButton,SIGNAL(clicked()), this, SLOT(cleanSettings()));
otlayout->addRow(new QLabel(tr("Clear Settings on Exit")), &clearSettingsButton);
fontButton.setText(tr("Set Editor Font"));
connect(&fontButton,SIGNAL(clicked()),this,SLOT(showFontDialog()));
edlayout->addRow(new QLabel(tr("Set Editor Font")), &fontButton);
}
示例13: testMoreIndex_MovieSortModels
void DropDownModelTest::testMoreIndex_MovieSortModels()
{
//GIVEN
QVariant dataModel;
MovieSortModels movieSortModels;
QString msg;
int countRow = movieSortModels.rowCount();
//WHEN
QModelIndex indx = movieSortModels.index(countRow, 0, QModelIndex());
dataModel = movieSortModels.data(indx, MovieSortModels :: SortingFieldRole);
//EXPECTED
//msg = QString("countRow - %1, indx.row() - %2").arg(countRow).arg(indx.row());
//QWARN (msg.toLocal8Bit().constData());
QCOMPARE(dataModel.canConvert(QVariant::Int), false);
}
示例14: testMoreIndex_TVCategoryModel
void DropDownModelTest::testMoreIndex_TVCategoryModel()
{
//GIVEN
QVariant dataModel;
TVCategoryModel tvCategoryModel;
QString msg;
int countRow = tvCategoryModel.rowCount();
//WHEN
QModelIndex indx = tvCategoryModel.index(countRow, 0, QModelIndex());
dataModel = tvCategoryModel.data(indx, TVCategoryModel :: IdRole);
//EXPECTED
//msg = QString("countRow - %1, indx.row() - %2").arg(countRow).arg(indx.row());
//QWARN (msg.toLocal8Bit().constData());
QCOMPARE(dataModel.canConvert(QVariant::Int), false);
}
示例15: toValue
inline optional<Value> toValue(const QVariant& value) {
if (value.type() == QVariant::Bool) {
return { value.toBool() };
} else if (value.type() == QVariant::String) {
return { value.toString().toStdString() };
} else if (value.type() == QVariant::Color) {
return { value.value<QColor>().name().toStdString() };
} else if (value.type() == QVariant::Int) {
return { value.toInt() };
} else if (value.canConvert(QVariant::Double)) {
return { value.toFloat() };
} else {
return {};
}
}