本文整理汇总了C++中QVariantList::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantList::empty方法的具体用法?C++ QVariantList::empty怎么用?C++ QVariantList::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantList
的用法示例。
在下文中一共展示了QVariantList::empty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: errorOccured
void PlacesDataManager::
replyFinished(QNetworkReply * reply) const
{
QApplication::restoreOverrideCursor();
if( existsReplyError(reply) ) return;
QString strUrl = reply->url().toString();
QString data = reply->readAll();
//qDebug() << Q_FUNC_INFO << "\n" << reply->operation() << strUrl << "\n" << data;
QObject * origObject = reply->request().originatingObject();
//it's ok, just simple usage of QNetworkAccessManager, without DataManagerHelper
if( ! origObject ) {
//qDebug() << "empty originating Object...";
//qDebug() << "try simple work with result";
//qDebug() << data;
QJson::Parser parser;
bool ok;
// json is a QString containing the data to convert
QVariant result = parser.parse (data.toLatin1(), &ok);
if(!ok)
{
emit errorOccured(QString("Cannot convert to QJson object: %1").arg(data));
return;
}
int code = result.toMap()["Status"].toMap()["code"].toInt();
if(code != 200 && code != 0)
{
emit errorOccured(QString("Code of request is: %1").arg(code));
return;
}
QVariantList placeMarks = result.toMap()["Placemark"].toList();
if (!placeMarks.empty())
{
double east = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[0].toDouble();
double north = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[1].toDouble();
QString str = QString::number(north)+","+QString::number(east);
emit findCoordinatesByAddress(str);
}
return;
}
DataManagerHelper * helper = qobject_cast<DataManagerHelper*>(origObject);
if( ! helper ) {
//qDebug() << "empty helper Object...";
return;
}
//qDebug() << "Helper object present." ;
helper->evalData(data);
helper->deleteLater();
}
示例2: itemRemoved
void ChatList::itemRemoved(Peer* peer)
{
QVariantList it = m_model->last();
while(!it.empty())
{
Peer* contact = (Peer*)m_model->data(it).value<QObject*>();
if (peer == contact)
{
m_model->removeAt(it);
break;
}
it = m_model->before(it);
}
}
示例3: fromVariant
bool EditorWidgetState::fromVariant(const QVariant &v)
{
// Restore state. The weird thing is that QSettings might return
// a QStringList although it was saved as QVariantList<int>.
if (v.type() != QVariant::List && v.type() != QVariant::StringList)
return false;
const QVariantList vl = v.toList();
if (vl.empty())
return false;
int index = 0;
const QVariant &versionV = vl.at(index++);
if (versionV.type() != QVariant::Int && versionV.type() != QVariant::String)
return false;
if (versionV.toInt() > Version)
return false;
return variantListToIntList(vl, index, horizontalSizes) &&
variantListToIntList(vl, index, centerVerticalSizes) &&
variantListToIntList(vl, index, rightVerticalSizes);
}
示例4: childCount
// Return the number of child items contained in a given entry
// Since we only implement a flat list, we must return 0 for any sub item.
int PokemonList::childCount(const QVariantList& indexPath) {
// For indexPath, See http://developer.blackberry.com/native/reference/cascades/bb__cascades__datamodel.html
// Return the item count if asking for top level count
if (indexPath.empty()){
static int ind = 0;
QFile file("app/native/assets/data/pokemon_species_names.csv");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
while (!in.atEnd() && ind!=719) {
QStringList line = in.readLine().split(","); // Read a line as a QStringList and split it where ever a "," exists
if((line[0]).toInt()==(ind+1) && line[1]=="9") ind++; //incrementing 'ind' every time an english pokemon is found
}
}
else cerr << "Failed to open types.csv: " << file.error() << endl;
return ind; // TODO: Return the correct number of pokemon
}
// No sub levels
return 0;
}
示例5: foreach
foreach(QString property, mProperties) {
this->measures[property] = QPair <double, double> (0, 0);
if (m.keys().contains(property)) {
if (m.value(property).canConvert(QVariant::List)) {
QVariantList list = m[property].toList();
if (list.length() > 2 || list.empty())
continue;
int index = 0;
foreach(QVariant value, list) {
if (value.canConvert(QVariant::Double)) {
if (!index)
this->measures[property].first = value.toDouble();
else
this->measures[property].second = value.toDouble();
}
index++;
}
}
}
示例6: toOSArgument
OSArgument toOSArgument(const QVariant& variant, const VersionString& version) {
QVariantMap map = variant.toMap();
OSArgumentType type(map["type"].toString().toStdString());
QVariant value, defaultValue;
OS_ASSERT(value.isNull() && defaultValue.isNull());
if (map.contains("value")) {
if (type == OSArgumentType::Quantity) {
value = toQuantityQVariant(map,"value","value_units");
}
else {
value = map["value"];
}
}
if (map.contains("default_value")) {
if (type == OSArgumentType::Quantity) {
defaultValue = toQuantityQVariant(map,"default_value","default_value_units");
}
else {
defaultValue = map["default_value"];
}
}
std::vector<QVariant> domain;
if (map.contains("domain")) {
if (type == OSArgumentType::Quantity) {
domain = deserializeOrderedVector(
map["domain"].toList(),
"domain_value_index",
std::function<QVariant (QVariant*)>(std::bind(
toQuantityQVariant,
std::bind(&QVariant::toMap,std::placeholders::_1),
"value",
"units")));
}
else {
domain = deserializeOrderedVector(
map["domain"].toList(),
"value",
"domain_value_index",
std::function<QVariant (const QVariant&)>(std::bind(boost::value_factory<QVariant>(),std::placeholders::_1)));
}
}
StringVector choices, choiceDisplayNames;
if (map.contains("choices")) {
QVariantList choicesList = map["choices"].toList();
choices = deserializeOrderedVector(
choicesList,
"value",
"choice_index",
std::function<std::string (QVariant*)>(std::bind(&QString::toStdString,
std::bind(&QVariant::toString,std::placeholders::_1))));
if (!choicesList.empty() && choicesList[0].toMap().contains("display_name")) {
try {
choiceDisplayNames = deserializeOrderedVector(
choicesList,
"display_name",
"choice_index",
std::function<std::string (QVariant*)>(std::bind(&QString::toStdString,
std::bind(&QVariant::toString,std::placeholders::_1))));
}
catch (...) {
LOG_FREE(Warn,"openstudio.ruleset.OSArgument","Unable to deserialize partial list of choice display names.");
}
}
}
return OSArgument(toUUID(map["uuid"].toString().toStdString()),
toUUID(map["version_uuid"].toString().toStdString()),
map["name"].toString().toStdString(),
map.contains("display_name") ? map["display_name"].toString().toStdString() : std::string(),
map.contains("description") ? map["description"].toString().toStdString() : boost::optional<std::string>(),
type,
map.contains("units") ? map["units"].toString().toStdString() : boost::optional<std::string>(),
map["required"].toBool(),
map["modelDependent"].toBool(),
value,
defaultValue,
OSDomainType(map["domain_type"].toString().toStdString()),
domain,
choices,
choiceDisplayNames,
map.contains("is_read") ? map["is_read"].toBool() : false,
map.contains("extension") ? map["extension"].toString().toStdString() : std::string());
}
示例7: updateThread
//.........这里部分代码省略.........
htmlTemplate.replace("font-size: 28px;", "font-size: " + QString::number(settings.value("fontSize").value<int>()) + "px;");
}
// -----------------------------------------------------------------------------------------------
// choose background image
{
QString directory = QDir::homePath() + QLatin1String("/ApplicationData/Customization");
QString filename;
if(QFile::exists(directory + "/" + ConversationManager::get()->getAdressee() + ".xml")) {
filename = directory + "/" + ConversationManager::get()->getAdressee() + ".xml";
} else {
if(QFile::exists(directory +"/default.xml")) {
filename = directory + "/default.xml";
}
}
filename.replace(".xml", ".css");
if(QFile::exists(filename)) {
QFile file(filename);
if (file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
QString themeSettings = stream.readAll();
file.close();
QString suffix;
if(bb::cascades::Application::instance()->themeSupport()->theme()->colorTheme()->style() == bb::cascades::VisualStyle::Dark) {
suffix = "_black";
}
htmlTemplate.replace("</style><link rel=\"stylesheet\" href=\"bubble" + suffix + ".css\">", themeSettings + "\n\r</style>");
}
}
}
// -----------------------------------------------------------------------------------------------
// preload history
QVariantList list = qtData.toMap()["messages"].toList();
bool fistInsertDone = false;
QString body;
QString prevFrom;
for(int i = 0 ; i < list.size() ; ++i) {
QVariantMap map = list.at(i).toMap();
QVariantList headers = map["payload"].toMap()["headers"].toList();
QString contact;
if(!headers.isEmpty())
contact = headers.at(0).toMap()["value"].toString();
QString from;
QString dstName;
QRegExp fromRegExp("(.*) <(.*)>");
if(fromRegExp.indexIn(contact) != -1) {
from = fromRegExp.cap(2);
dstName = fromRegExp.cap(1);
}
QString vCardsDir = QDir::homePath() + QLatin1String("/vCards");
QString dstAvatar(vCardsDir + "/" + from + ".png");
if(i > 0 && prevFrom == from && fistInsertDone) {
body += "<li><p>" + renderMessage(map["snippet"].toString()) + "</p></li>";
} else {
fistInsertDone = true;
if(i != std::max(0, list.size()))
body += "</ul></div><br/>";
if(isOwnMessage(from)) {
body += QString("<div class=\"bubble-left\"><div class=\"bubble-left-avatar\"><img src=\"file:///" + ownAvatar + ".square.png" + "\" /><div class=\"author-left\"><p>" + tr("Me") +"</p></div><div class=\"time-left\"><p>" + "</p></div></div><br/><br/><br/>")
+ "<ul><li><p>" + renderMessage(map["snippet"].toString()) + "</p></li>";
} else {
body += QString("<div class=\"bubble-right\"><div class=\"bubble-right-avatar\"><img src=\"file:///" + dstAvatar + ".square.png" + "\" /><div class=\"author-right\"><p>" + dstName +"</p></div><div class=\"time-right\"><p>" + "</p></div></div><br/><br/><br/>")
+ "<ul><li><p>" + renderMessage(map["snippet"].toString()) + "</p></li>";
}
}
prevFrom = from;
}
if(!list.empty()) {
body += "</ul></div><br/>";
}
m_WebView->setHtml(htmlTemplate + body + endTemplate, "file:///" + QDir::homePath() + "/../app/native/assets/");
}
emit threadLoaded();
}
示例8: formatPreviewString
QString QgsExpression::formatPreviewString( const QVariant &value, const bool htmlOutput )
{
static const int MAX_PREVIEW = 60;
const QString startToken = htmlOutput ? QStringLiteral( "<i><" ) : QStringLiteral( "<" );
const QString endToken = htmlOutput ? QStringLiteral( "></i>" ) : QStringLiteral( ">" );
if ( value.canConvert<QgsGeometry>() )
{
//result is a geometry
QgsGeometry geom = value.value<QgsGeometry>();
if ( geom.isNull() )
return startToken + tr( "empty geometry" ) + endToken;
else
return startToken + tr( "geometry: %1" ).arg( QgsWkbTypes::displayString( geom.constGet()->wkbType() ) )
+ endToken;
}
else if ( value.value< QgsWeakMapLayerPointer >().data() )
{
return startToken + tr( "map layer" ) + endToken;
}
else if ( !value.isValid() )
{
return htmlOutput ? tr( "<i>NULL</i>" ) : QString();
}
else if ( value.canConvert< QgsFeature >() )
{
//result is a feature
QgsFeature feat = value.value<QgsFeature>();
return startToken + tr( "feature: %1" ).arg( feat.id() ) + endToken;
}
else if ( value.canConvert< QgsInterval >() )
{
//result is a feature
QgsInterval interval = value.value<QgsInterval>();
return startToken + tr( "interval: %1 days" ).arg( interval.days() ) + endToken;
}
else if ( value.canConvert< QgsGradientColorRamp >() )
{
return startToken + tr( "gradient ramp" ) + endToken;
}
else if ( value.type() == QVariant::Date )
{
QDate dt = value.toDate();
return startToken + tr( "date: %1" ).arg( dt.toString( QStringLiteral( "yyyy-MM-dd" ) ) ) + endToken;
}
else if ( value.type() == QVariant::Time )
{
QTime tm = value.toTime();
return startToken + tr( "time: %1" ).arg( tm.toString( QStringLiteral( "hh:mm:ss" ) ) ) + endToken;
}
else if ( value.type() == QVariant::DateTime )
{
QDateTime dt = value.toDateTime();
return startToken + tr( "datetime: %1" ).arg( dt.toString( QStringLiteral( "yyyy-MM-dd hh:mm:ss" ) ) ) + endToken;
}
else if ( value.type() == QVariant::String )
{
const QString previewString = value.toString();
if ( previewString.length() > MAX_PREVIEW + 3 )
{
return tr( "'%1…'" ).arg( previewString.left( MAX_PREVIEW ) );
}
else
{
return '\'' + previewString + '\'';
}
}
else if ( value.type() == QVariant::Map )
{
QString mapStr = QStringLiteral( "{" );
const QVariantMap map = value.toMap();
QString separator;
for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
{
mapStr.append( separator );
if ( separator.isEmpty() )
separator = QStringLiteral( "," );
mapStr.append( QStringLiteral( " '%1': %2" ).arg( it.key(), formatPreviewString( it.value(), htmlOutput ) ) );
if ( mapStr.length() > MAX_PREVIEW - 3 )
{
mapStr = tr( "%1…" ).arg( mapStr.left( MAX_PREVIEW - 2 ) );
break;
}
}
if ( !map.empty() )
mapStr += QStringLiteral( " " );
mapStr += QStringLiteral( "}" );
return mapStr;
}
else if ( value.type() == QVariant::List || value.type() == QVariant::StringList )
{
QString listStr = QStringLiteral( "[" );
const QVariantList list = value.toList();
QString separator;
for ( const QVariant &arrayValue : list )
{
listStr.append( separator );
if ( separator.isEmpty() )
//.........这里部分代码省略.........
示例9: toVariant
//.........这里部分代码省略.........
addProperties(tilesetVariant, tileset.properties());
const QPoint offset = tileset.tileOffset();
if (!offset.isNull()) {
QVariantMap tileOffset;
tileOffset[QLatin1String("x")] = offset.x();
tileOffset[QLatin1String("y")] = offset.y();
tilesetVariant[QLatin1String("tileoffset")] = tileOffset;
}
if (tileset.orientation() != Tileset::Orthogonal || tileset.gridSize() != tileset.tileSize()) {
QVariantMap grid;
grid[QLatin1String("orientation")] = Tileset::orientationToString(tileset.orientation());
grid[QLatin1String("width")] = tileset.gridSize().width();
grid[QLatin1String("height")] = tileset.gridSize().height();
tilesetVariant[QLatin1String("grid")] = grid;
}
// Write the image element
const QUrl &imageSource = tileset.imageSource();
if (!imageSource.isEmpty()) {
const QString rel = toFileReference(imageSource, mMapDir);
tilesetVariant[QLatin1String("image")] = rel;
const QColor transColor = tileset.transparentColor();
if (transColor.isValid())
tilesetVariant[QLatin1String("transparentcolor")] = transColor.name();
tilesetVariant[QLatin1String("imagewidth")] = tileset.imageWidth();
tilesetVariant[QLatin1String("imageheight")] = tileset.imageHeight();
}
// Write the properties, terrain, external image, object group and
// animation for those tiles that have them.
QVariantList tilesVariant;
for (const Tile *tile : tileset.tiles()) {
const Properties properties = tile->properties();
QVariantMap tileVariant;
addProperties(tileVariant, properties);
if (!tile->type().isEmpty())
tileVariant[QLatin1String("type")] = tile->type();
if (tile->terrain() != 0xFFFFFFFF) {
QVariantList terrainIds;
for (int j = 0; j < 4; ++j)
terrainIds << QVariant(tile->cornerTerrainId(j));
tileVariant[QLatin1String("terrain")] = terrainIds;
}
if (tile->probability() != 1.0)
tileVariant[QLatin1String("probability")] = tile->probability();
if (!tile->imageSource().isEmpty()) {
const QString rel = toFileReference(tile->imageSource(), mMapDir);
tileVariant[QLatin1String("image")] = rel;
const QSize tileSize = tile->size();
if (!tileSize.isNull()) {
tileVariant[QLatin1String("imagewidth")] = tileSize.width();
tileVariant[QLatin1String("imageheight")] = tileSize.height();
}
}
if (tile->objectGroup())
tileVariant[QLatin1String("objectgroup")] = toVariant(*tile->objectGroup());
if (tile->isAnimated()) {
QVariantList frameVariants;
for (const Frame &frame : tile->frames()) {
QVariantMap frameVariant;
frameVariant[QLatin1String("tileid")] = frame.tileId;
frameVariant[QLatin1String("duration")] = frame.duration;
frameVariants.append(frameVariant);
}
tileVariant[QLatin1String("animation")] = frameVariants;
}
if (!tileVariant.empty()) {
tileVariant[QLatin1String("id")] = tile->id();
tilesVariant << tileVariant;
}
}
if (!tilesVariant.empty())
tilesetVariant[QLatin1String("tiles")] = tilesVariant;
// Write terrains
if (tileset.terrainCount() > 0) {
QVariantList terrainsVariant;
for (int i = 0; i < tileset.terrainCount(); ++i) {
Terrain *terrain = tileset.terrain(i);
const Properties &properties = terrain->properties();
QVariantMap terrainVariant;
terrainVariant[QLatin1String("name")] = terrain->name();
terrainVariant[QLatin1String("tile")] = terrain->imageTileId();
addProperties(terrainVariant, properties);
terrainsVariant << terrainVariant;
}
tilesetVariant[QLatin1String("terrains")] = terrainsVariant;
}
return tilesetVariant;
}
示例10: updateContent
void ChatList::updateContent()
{
m_model->clear();
if (m_filter & 1)
{
for (int i = 0; i < m_dialogs->size(); i++)
{
//Chat* chat = m_dialogs->value(i);
m_model->insert(m_dialogs->value(i));
}
}
if ((m_filter & 2) && m_model->size() && m_searchText.size())
{
QVariantList it = m_model->last();
while(!it.empty())
{
Peer* contact = (Peer*)m_model->data(it).value<QObject*>();
if (contact->title().indexOf(m_searchText) == -1)
{
QVariantList toRemove = it;
it = m_model->before(it);
m_model->removeAt(toRemove);
continue;
}
else
it = m_model->before(it);
}
}
/*if ((m_filter & 4) && m_model->size() && m_searchText.size())
{
QVariantList it = m_model->last();
while(!it.empty())
{
Chat* contact = (Chat*)m_model->data(it).value<QObject*>();
GroupDataModel* messages = (GroupDataModel*)contact->messages();
bool found = false;
for (QVariantList indexPath = messages->first(); !indexPath.isEmpty(); indexPath = messages->after(indexPath))
{
Message* message = (Message*)messages->data(indexPath).value<QObject*>();
if (message->text().indexOf(m_searchText) != -1)
{
found = true;
break;
}
}
if(!found)
{
QVariantList toRemove = it;
it = m_model->before(it);
m_model->removeAt(toRemove);
Storage::instance()->searchMessage(contact, 0, contact->lastMessageDate().toTime_t(), 1, 0, m_searchText.toUtf8().data());
}
else
it = m_model->before(it);
}
}*/
emit contentUpdated();
}
示例11: hasChildren
// Used for displaying multi-level lists
bool PokemonList::hasChildren(const QVariantList& indexPath) {
if (indexPath.empty())
return true; // The root node always has children
else
return false; //d
}