void KCoreConfigSkeleton::ItemDateTime::setProperty(const QVariant & p)
{
  mReference = p.toDateTime();
}
Example #2
0
QVariant QSystemLocale::query(QueryType type, QVariant in) const
{
    QBBSystemLocaleData *d = bbSysLocaleData();

    QReadLocker locker(&d->lock);

    const QLocale &lc_language = d->languageLocale();
    const QLocale &lc_region = d->regionLocale();

    switch (type) {
    case DecimalPoint:
        return lc_region.decimalPoint();
    case GroupSeparator:
        return lc_region.groupSeparator();
    case NegativeSign:
        return lc_region.negativeSign();
    case PositiveSign:
        return lc_region.positiveSign();
    case DateFormatLong:
        return lc_region.dateFormat(QLocale::LongFormat);
    case DateFormatShort:
        return lc_region.dateFormat(QLocale::ShortFormat);
    case TimeFormatLong:
        return d->timeFormat(QLocale::LongFormat);
    case TimeFormatShort:
        return d->timeFormat(QLocale::ShortFormat);
    case DateTimeFormatLong:
        return d->dateTimeFormat(QLocale::LongFormat);
    case DateTimeFormatShort:
        return d->dateTimeFormat(QLocale::ShortFormat);
    case DayNameLong:
        return lc_language.dayName(in.toInt(), QLocale::LongFormat);
    case DayNameShort:
        return lc_language.dayName(in.toInt(), QLocale::ShortFormat);
    case MonthNameLong:
        return lc_language.monthName(in.toInt(), QLocale::LongFormat);
    case MonthNameShort:
        return lc_language.monthName(in.toInt(), QLocale::ShortFormat);
    case DateToStringLong:
        return lc_region.toString(in.toDate(), QLocale::LongFormat);
    case DateToStringShort:
        return lc_region.toString(in.toDate(), QLocale::ShortFormat);
    case TimeToStringLong:
        return lc_region.toString(in.toTime(), QLocale::LongFormat);
    case TimeToStringShort:
        return lc_region.toString(in.toTime(), QLocale::ShortFormat);
    case DateTimeToStringShort:
        return lc_region.toString(in.toDateTime(), d->dateTimeFormat(QLocale::ShortFormat).toString());
    case DateTimeToStringLong:
        return lc_region.toString(in.toDateTime(), d->dateTimeFormat(QLocale::LongFormat).toString());
    case MeasurementSystem:
        return d->measurementSystem();
    case ZeroDigit:
        return lc_region.zeroDigit();
    case CountryId:
        return lc_region.country();
    case LanguageId:
        return lc_language.language();
    case AMText:
        return lc_language.amText();
    case PMText:
        return lc_language.pmText();
    default:
        break;
    }
    return QVariant();
}
Example #3
0
void QDateTimeAxisPrivate::setMin(const QVariant &min)
{
    Q_Q(QDateTimeAxis);
    if (min.canConvert(QVariant::DateTime))
        q->setMin(min.toDateTime());
}
Example #4
0
void XMLRPC::marshall(QXmlStreamWriter *writer, const QVariant &value)
{
    writer->writeStartElement("value");
    switch( value.type() )
    {
        case QVariant::Int:
        case QVariant::UInt:
        case QVariant::LongLong:
        case QVariant::ULongLong:
            writer->writeTextElement("i4", value.toString());
            break;
        case QVariant::Double:
            writer->writeTextElement("double", value.toString());
            break;
        case QVariant::Bool:
            writer->writeTextElement("boolean", value.toBool() ? "1" : "0");
            break;
        case QVariant::Date:
            writer->writeTextElement("dateTime.iso8601", value.toDate().toString( Qt::ISODate ) );
            break;
        case QVariant::DateTime:
            writer->writeTextElement("dateTime.iso8601", value.toDateTime().toString( Qt::ISODate ) );
            break;
        case QVariant::Time:
            writer->writeTextElement("dateTime.iso8601", value.toTime().toString( Qt::ISODate ) );
            break;
        case QVariant::StringList:
        case QVariant::List:
        {
            writer->writeStartElement("array");
            writer->writeStartElement("data");
            foreach(const QVariant &item, value.toList())
                marshall(writer, item);
            writer->writeEndElement();
            writer->writeEndElement();
            break;
        }
        case QVariant::Map:
        {
            writer->writeStartElement("struct");
            QMap<QString, QVariant> map = value.toMap();
            QMap<QString, QVariant>::ConstIterator index = map.begin();
            while( index != map.end() )
            {
                writer->writeStartElement("member");
                writer->writeTextElement("name", index.key());
                marshall( writer, *index );
                writer->writeEndElement();
                ++index;
            }
            writer->writeEndElement();
            break;
        }
        case QVariant::ByteArray:
        {
            writer->writeTextElement("base64", value.toByteArray().toBase64() );
            break;
        }
        default:
        {
            if (value.isNull())
                writer->writeEmptyElement("nil");
            else if( value.canConvert(QVariant::String) )
            {
                writer->writeTextElement("string", value.toString() );
            }
            break;
        }
    }
    writer->writeEndElement();
}
Example #5
0
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);
        }
        break;
    case QVariant::LongLong:
    case QVariant::ULongLong:
        {
            qint64 n = value.toLongLong();
            result = CFNumberCreate(0, kCFNumberLongLongType, &n);
        }
        break;
    case QVariant::String:
    string_case:
    default:
        result = QCFString::toCFStringRef(QSettingsPrivate::variantToString(value));
    }
    return result;
}
int
MarkerRetracement::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m)
{
  Marker *ret = (Marker *) m;
  Entity *e = ret->settings();
  
  QVariant *date = e->get(QString("date"));
  if (! date)
    return 0;
  
  QVariant *date2 = e->get(QString("date2"));
  if (! date2)
    return 0;

  QVariant *high = e->get(QString("high"));
  if (! high)
    return 0;

  QVariant *low = e->get(QString("low"));
  if (! low)
    return 0;

  QVariant *tset = e->get(QString("color"));
  if (! tset)
    return 0;
  QColor color(tset->toString());

  QVariant *extend = e->get(QString("extend"));
  if (! extend)
    return 0;

  QVariant *l1 = e->get(QString("level1"));
  if (! l1)
    return 0;

  QVariant *l2 = e->get(QString("level2"));
  if (! l2)
    return 0;

  QVariant *l3 = e->get(QString("level3"));
  if (! l3)
    return 0;

  QVariant *l4 = e->get(QString("level4"));
  if (! l4)
    return 0;

  QVariant *l5 = e->get(QString("level5"));
  if (! l5)
    return 0;

  QVariant *l6 = e->get(QString("level6"));
  if (! l6)
    return 0;
  
  PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) ret->plot()->axisScaleDraw(QwtPlot::xBottom);
  int x = xMap.transform(dsd->dateToX(date->toDateTime()));

  QDateTime dt = date2->toDateTime();
  if (extend->toBool())
  {
    int s, e;
    g_symbol->startEndRange(s, e);
    Bar *bar = g_symbol->bar(e);
    if (! bar)
      return 0;
    
    dt = bar->date();
  }

  int x2 = xMap.transform(dsd->dateToX(dt));

  p->setPen(color);

  ret->clearSelectionArea();

  QList<double> lineList;
  lineList.append(l1->toDouble());
  lineList.append(l2->toDouble());
  lineList.append(l3->toDouble());
  lineList.append(l4->toDouble());
  lineList.append(l5->toDouble());
  lineList.append(l6->toDouble());

  for (int loop = 0; loop < lineList.size(); loop++)
  {
    double td = lineList.at(loop);
    if (td != 0)
    {
      double range = high->toDouble() - low->toDouble();
      double r = 0;
      if (td < 0)
        r = low->toDouble() + (range * td);
      else
      {
        if (td > 0)
          r = low->toDouble() + (range * td);
        else
        {
          if (td < 0)
            r = high->toDouble();
          else
            r = low->toDouble();
        }
      }

      int y = yMap.transform(r);
      p->drawLine (x, y, x2, y);
      p->drawText(x, y - 1, QString::number(td * 100) + "% - " + QString::number(r));

      QPolygon array;
      array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4);
      ret->appendSelectionArea(QRegion(array));
    }
  }

  // draw the low line
  int y = yMap.transform(low->toDouble());
  p->drawLine (x, y, x2, y);
  
  Strip strip;
  QString ts;
  strip.strip(low->toDouble(), 4, ts);
  p->drawText(x, y - 1, "0% - " + ts);

  // store the selectable area the low line occupies
  QPolygon array;
  array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4);
  ret->appendSelectionArea(QRegion(array));

  // draw the high line
  int y2 = yMap.transform(high->toDouble());
  p->drawLine (x, y2, x2, y2);
  
  strip.strip(high->toDouble(), 4, ts);
  p->drawText(x, y2 - 1, "100% - " + ts);

  // store the selectable area the high line occupies
  array.clear();
  array.putPoints(0, 4, x, y2 - 4, x, y2 + 4, x2, y2 + 4, x2, y2 - 4);
  ret->appendSelectionArea(QRegion(array));

  if (ret->selected())
  {
    int handleWidth = ret->handleWidth();
    
    ret->clearGrabHandles();

    //top left corner
    ret->appendGrabHandle(QRegion(x, y2 - (handleWidth / 2),
                          handleWidth,
                          handleWidth,
                          QRegion::Rectangle));

    p->fillRect(x,
                y2 - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);

    //bottom right corner
    ret->appendGrabHandle(QRegion(x2, y - (handleWidth / 2),
                          handleWidth,
                          handleWidth,
                          QRegion::Rectangle));

    p->fillRect(x2,
                y - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);
  }
  
  return 1;
}
enum SetResponse issueLineToShipping::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("transTS", &valid);
  if (valid)
    _transTS = param.toDateTime();

  param = pParams.value("order_type", &valid);
  if (valid)
  {
    _ordertype = param.toString();
    if (_ordertype == "SO")
      _orderNumberLit->setText(tr("Sales Order #:"));
    else if (_ordertype == "TO")
      _orderNumberLit->setText(tr("Transfer Order #:"));
  }

  param = pParams.value("order_id", &valid);
  if (valid)
  {
    _itemid = param.toInt();
    populate();
  }

  // TODO: deprecate by remoing from salesOrder and transferOrder windows
  param = pParams.value("soitem_id", &valid);
  if (valid)
  {
    _itemid = param.toInt();
    _ordertype = "SO";
    _orderNumberLit->setText(tr("Sales Order #:"));
    populate();
  }

  // TODO: deprecate by remoing from salesOrder and transferOrder windows
  param = pParams.value("toitem_id", &valid);
  if (valid)
  {
    _itemid = param.toInt();
    _ordertype = "TO";
    _orderNumberLit->setText(tr("Transfer Order #:"));
    populate();
  }

  if (pParams.inList("requireInventory"))
    _requireInventory = true;

  param = pParams.value("qty", &valid);
  if (valid)
    _qtyToIssue->setDouble(param.toDouble());

  _snooze = pParams.inList("snooze");

  if(pParams.inList("issue"))
    sIssue();

  return NoError;
}
Example #8
0
bool PSV_Public::getLabels(QVariant &maxValue, QVariant &minValue, QPair<double, double> &range, QList<QPair<QVariant, QString> > &labelList)
{
    if(maxValue.type() != minValue.type())
    {
        return false;
    }
    QVariant::Type type = maxValue.type();
    switch(type)
    {
    case QVariant::Double:
    case QVariant::Int:
    case QVariant::UInt:
    {
        double max = maxValue.toDouble();
        double min = minValue.toDouble();
        int numTick = getNumTicks(max, min);
        if(numTick <= 0)
        {
            return false;
        }
        adjustRange(max, min);
        labelList.clear();
        for(int i = 0; i <= numTick; ++i)
        {
            double value = min + 1.0 * (max - min) * i / numTick;
            QString str = QObject::tr("%1").arg(value);
            labelList.append(QPair<QVariant, QString>(value, str));
        }
        maxValue = max;
        minValue = min;
        range = QPair<double,double>(min,max);
        return true;
    }
        break;
    case QVariant::Date:
    {
        QDate maxDate = maxValue.toDate();
        QDate minDate = minValue.toDate();
        bool isOk = getDateLabels(maxDate, minDate, labelList);
        maxValue = maxDate;
        minValue = minDate;
        range = QPair<double,double>(0.0, 1.0 * minDate.daysTo(maxDate));
        return isOk;
    }
        break;
    case QVariant::Time:
    {
        QTime maxTime = maxValue.toTime();
        QTime minTime = minValue.toTime();
        bool isOk = getTimeLabels(maxTime, minTime, labelList);
        maxValue = maxTime;
        minValue = minTime;
        range = QPair<double,double>(0.0, 86400.0/*1.0 * minTime.secsTo(maxTime)*/);
        return isOk;
    }
        break;
    case QVariant::DateTime:
    {
        QDateTime maxTime = maxValue.toDateTime();
        QDateTime minTime = minValue.toDateTime();
        //        PSV_Public::printMes(maxTime,"1maxTime");
        //        PSV_Public::printMes(minTime,"1minTime");
        bool isOk = getDateTimeLabels(maxTime, minTime, labelList);
        maxValue = maxTime;
        minValue = minTime;
        //        PSV_Public::printMes(maxTime,"2maxTime");
        //        PSV_Public::printMes(minTime,"2minTime");

        range = QPair<double,double>(PSV_BEGIN_DATETIME.secsTo(minValue.toDateTime()),PSV_BEGIN_DATETIME.secsTo(maxValue.toDateTime()));
        return isOk;
    }
        break;
    default:
        break;
    }
    return false;
}
static QString variantToTextValue(const QVariant& value, const QString& typeNs, const QString& type)
{
    switch (value.userType())
    {
    case QVariant::Char:
        // fall-through
    case QVariant::String:
        return value.toString();
    case QVariant::Url:
        // xmlpatterns/data/qatomicvalue.cpp says to do this:
        return value.toUrl().toString();
    case QVariant::ByteArray:
    {
        const QByteArray data = value.toByteArray();
        if (typeNs == KDSoapNamespaceManager::xmlSchema1999() || typeNs == KDSoapNamespaceManager::xmlSchema2001()) {
            if (type == QLatin1String("hexBinary")) {
                const QByteArray hb = data.toHex();
                return QString::fromLatin1(hb.constData(), hb.size());
            }
        }
        // default to base64Binary, like variantToXMLType() does.
        const QByteArray b64 = value.toByteArray().toBase64();
        return QString::fromLatin1(b64.constData(), b64.size());
    }
    case QVariant::Int:
        // fall-through
    case QVariant::LongLong:
        // fall-through
    case QVariant::UInt:
        return QString::number(value.toLongLong());
    case QVariant::ULongLong:
        return QString::number(value.toULongLong());
    case QVariant::Bool:
    case QMetaType::Float:
    case QVariant::Double:
        return value.toString();
    case QVariant::Time:
    {
        const QTime time = value.toTime();
        if (time.msec()) {
            // include milli-seconds
            return time.toString(QLatin1String("hh:mm:ss.zzz"));
        } else {
            return time.toString(Qt::ISODate);
        }
    }
    case QVariant::Date:
        return value.toDate().toString(Qt::ISODate);
    case QVariant::DateTime: // http://www.w3.org/TR/xmlschema-2/#dateTime
        return KDDateTime(value.toDateTime()).toDateString();
    case QVariant::Invalid:
        qDebug() << "ERROR: Got invalid QVariant in a KDSoapValue";
        return QString();
    default:
        if (value.canConvert<KDDateTime>()) {
            return value.value<KDDateTime>().toDateString();
        }

        if (value.userType() == qMetaTypeId<float>())
            return QString::number(value.value<float>());

        qDebug() << QString::fromLatin1("QVariants of type %1 are not supported in "
                                        "KDSoap, see the documentation").arg(QLatin1String(value.typeName()));
        return value.toString();
    }
}
Example #10
0
void KConfigBase::writeEntry(const char *pKey, const QVariant &prop, bool bPersistent, bool bGlobal, bool bNLS)
{
    switch(prop.type())
    {
        case QVariant::Invalid:
            writeEntry(pKey, "", bPersistent, bGlobal, bNLS);
            return;
        case QVariant::String:
            writeEntry(pKey, prop.toString(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::StringList:
            writeEntry(pKey, prop.toStringList(), ',', bPersistent, bGlobal, bNLS);
            return;
        case QVariant::List:
        {
            QValueList< QVariant > list = prop.toList();
            QValueList< QVariant >::ConstIterator it = list.begin();
            QValueList< QVariant >::ConstIterator end = list.end();
            QStringList strList;

            for(; it != end; ++it)
                strList.append((*it).toString());

            writeEntry(pKey, strList, ',', bPersistent, bGlobal, bNLS);

            return;
        }
        case QVariant::Font:
            writeEntry(pKey, prop.toFont(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Point:
            writeEntry(pKey, prop.toPoint(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Rect:
            writeEntry(pKey, prop.toRect(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Size:
            writeEntry(pKey, prop.toSize(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Color:
            writeEntry(pKey, prop.toColor(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Int:
            writeEntry(pKey, prop.toInt(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::UInt:
            writeEntry(pKey, prop.toUInt(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::LongLong:
            writeEntry(pKey, prop.toLongLong(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::ULongLong:
            writeEntry(pKey, prop.toULongLong(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Bool:
            writeEntry(pKey, prop.toBool(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Double:
            writeEntry(pKey, prop.toDouble(), bPersistent, bGlobal, 'g', 6, bNLS);
            return;
        case QVariant::DateTime:
            writeEntry(pKey, prop.toDateTime(), bPersistent, bGlobal, bNLS);
            return;
        case QVariant::Date:
            writeEntry(pKey, QDateTime(prop.toDate()), bPersistent, bGlobal, bNLS);
            return;

        case QVariant::Pixmap:
        case QVariant::Image:
        case QVariant::Brush:
        case QVariant::Palette:
        case QVariant::ColorGroup:
        case QVariant::Map:
        case QVariant::IconSet:
        case QVariant::CString:
        case QVariant::PointArray:
        case QVariant::Region:
        case QVariant::Bitmap:
        case QVariant::Cursor:
        case QVariant::SizePolicy:
        case QVariant::Time:
        case QVariant::ByteArray:
        case QVariant::BitArray:
        case QVariant::KeySequence:
        case QVariant::Pen:
            break;
    }

    Q_ASSERT(0);
}
Example #11
0
void PSV_Public::printMes(const QVariant &mes, const QString &frefix)
{    
    QString message;
    int type = mes.type();
    switch(type)
    {
    case QVariant::Bool :
        message = mes.toBool() ? "true":"false";
        break;
    case QVariant::Color :
    {
        QColor color = mes.value<QColor>();
        message = QObject::tr("colorname:%1,r=%2,g=%3,b=%4")
                .arg(color.name())
                .arg(color.red())
                .arg(color.green())
                .arg(color.blue());
    }
        break;
    case QVariant::Date:
        message = mes.toDate().toString("yyyy-MM-dd");
        break;
    case QVariant::DateTime:
        message = mes.toDateTime().toString("yyyy-MM-dd hh:mm:ss");
        break;
    case QVariant::Double:
        message = QString::number(mes.toDouble());
        break;
    case QVariant::UInt:
    case QVariant::Int:
        message = QString::number(mes.toInt());
        break;
    case QVariant::ULongLong:
    case QVariant::LongLong:
        message = QString::number(mes.toLongLong());
        break;
    case QVariant::Line:
    {
        QLine line = mes.toLine();
        message = QObject::tr("Line x1=%1,y1=%2,x2=%3,y2=%4")
                .arg(line.x1()).arg(line.y1()).arg(line.x2()).arg(line.y2());
    }
        break;
    case QVariant::LineF:
    {
        QLineF lineF = mes.toLineF();
        message = QObject::tr("LineF x1=%1,y1=%2,x2=%3,y2=%4")
                .arg(lineF.x1()).arg(lineF.y1()).arg(lineF.x2()).arg(lineF.y2());
    }
        break;
    case QVariant::Point:
    {
        QPoint point = mes.toPoint();
        message = QObject::tr("point x=%1,y=%2")
                .arg(point.x()).arg(point.y());
    }
        break;
    case QVariant::PointF:
    {
        QPointF pointF = mes.toPointF();
        message = QObject::tr("pointF x=%1,y=%2")
                .arg(pointF.x()).arg(pointF.y());
    }
        break;
    case QVariant::Rect:
    {
        QRect rect = mes.toRect();
        message = QObject::tr("rect x=%1,y=%2,width=%3,height=%4")
                .arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height());
    }
        break;
    case QVariant::RectF:
    {
        QRectF rectF = mes.toRect();
        message = QObject::tr("rectF x=%1,y=%2,width=%3,height=%4")
                .arg(rectF.x()).arg(rectF.y()).arg(rectF.width()).arg(rectF.height());
    }
        break;

    default:
        message = QObject::tr("type = %1,<%2>").arg(type).arg(mes.toString());
        break;
    }
    QString outMes = QObject::tr("%1 %2").arg(frefix).arg(message);

    qDebug()<<QObject::tr("PSV_LIB:<%1>%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")).arg(outMes);
}
Example #12
0
QDateTime HAudioBook::date() const
{
    QVariant value;
    getCdsProperty(HCdsProperties::dc_date, &value);
    return value.toDateTime();
}
Example #13
0
int
MarkerTLine::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m)
{
  Marker *tline = (Marker *) m;
  
  Entity *e = tline->settings();
  
  QVariant *date = e->get(QString("date"));
  if (! date)
    return 0;
  
  QVariant *date2 = e->get(QString("date2"));
  if (! date2)
    return 0;

  QVariant *price = e->get(QString("price"));
  if (! price)
    return 0;

  QVariant *price2 = e->get(QString("price2"));
  if (! price2)
    return 0;

  QVariant *tset = e->get(QString("color"));
  if (! tset)
    return 0;
  QColor color(tset->toString());

  QVariant *extend = e->get(QString("extend"));
  if (! extend)
    return 0;

  PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) tline->plot()->axisScaleDraw(QwtPlot::xBottom);
  int x = xMap.transform(dsd->dateToX(date->toDateTime()));
  int x2 = xMap.transform(dsd->dateToX(date2->toDateTime()));
  int y = yMap.transform(price->toDouble());
  int y2 = yMap.transform(price2->toDouble());

  p->setPen(color);

  p->drawLine (x, y, x2, y2);

  // save old values;
  int tx2 = x2;
  int ty2 = y2;
  int tx = x;
  int ty = y;

  if (extend->toBool())
  {
    int ydiff = y - y2;
    int xdiff = x2 - x;
    if (xdiff > 0)
    {
      while (x2 < p->window().width())
      {
        x = x2;
        y = y2;
        x2 = x2 + xdiff;
        y2 = y2 - ydiff;
        p->drawLine (x, y, x2, y2);
      }
    }
  }

  // store the selectable area the line occupies
  tline->clearSelectionArea();

  QPolygon array;
  array.putPoints(0, 4, tx, ty - 4, tx, ty + 4, x2, y2 + 4, x2, y2 - 4);
  tline->appendSelectionArea(QRegion(array));

  if (tline->selected())
  {
    int handleWidth = tline->handleWidth();
    
    tline->clearGrabHandles();

    tline->appendGrabHandle(QRegion(tx,
                            ty - (handleWidth / 2),
                            handleWidth,
                            handleWidth,
                            QRegion::Rectangle));

    p->fillRect(tx,
                ty - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);

    tline->appendGrabHandle(QRegion(tx2,
                            ty2 - (handleWidth / 2),
                            handleWidth,
                            handleWidth,
                            QRegion::Rectangle));

    p->fillRect(tx2,
                ty2 - (handleWidth / 2),
                handleWidth,
                handleWidth,
                color);
  }
  
  return 1;
}
bool KCoreConfigSkeleton::ItemDateTime::isEqual(const QVariant &v) const
{
    return mReference == v.toDateTime();
}
QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const
{
    QSystemLocalePrivate *d = systemLocalePrivate();
    switch(type) {
    case DecimalPoint:
        return d->decimalPoint();
    case GroupSeparator:
        return d->groupSeparator();
    case NegativeSign:
        return d->negativeSign();
    case PositiveSign:
        return d->positiveSign();
    case DateFormatLong:
        return d->dateFormat(QLocale::LongFormat);
    case DateFormatShort:
        return d->dateFormat(QLocale::ShortFormat);
    case TimeFormatLong:
        return d->timeFormat(QLocale::LongFormat);
    case TimeFormatShort:
        return d->timeFormat(QLocale::ShortFormat);
    case DateTimeFormatLong:
        return d->dateTimeFormat(QLocale::LongFormat);
    case DateTimeFormatShort:
        return d->dateTimeFormat(QLocale::ShortFormat);
    case DayNameLong:
        return d->dayName(in.toInt(), QLocale::LongFormat);
    case DayNameShort:
        return d->dayName(in.toInt(), QLocale::ShortFormat);
    case MonthNameLong:
    case StandaloneMonthNameLong:
        return d->monthName(in.toInt(), QLocale::LongFormat);
    case MonthNameShort:
    case StandaloneMonthNameShort:
        return d->monthName(in.toInt(), QLocale::ShortFormat);
    case DateToStringShort:
        return d->toString(in.toDate(), QLocale::ShortFormat);
    case DateToStringLong:
        return d->toString(in.toDate(), QLocale::LongFormat);
    case TimeToStringShort:
        return d->toString(in.toTime(), QLocale::ShortFormat);
    case TimeToStringLong:
        return d->toString(in.toTime(), QLocale::LongFormat);
    case DateTimeToStringShort:
        return d->toString(in.toDateTime(), QLocale::ShortFormat);
    case DateTimeToStringLong:
        return d->toString(in.toDateTime(), QLocale::LongFormat);
    case ZeroDigit:
        return d->zeroDigit();
    case LanguageId:
    case ScriptId:
    case CountryId: {
        QString locale = QString::fromLatin1(getWinLocaleName());
        QLocale::Language lang;
        QLocale::Script script;
        QLocale::Country cntry;
        QLocalePrivate::getLangAndCountry(locale, lang, script, cntry);
        if (type == LanguageId)
            return lang;
        if (type == ScriptId)
            return script == QLocale::AnyScript ? fallbackUiLocale().script() : script;
        if (cntry == QLocale::AnyCountry)
            return fallbackUiLocale().country();
        return cntry;
    }
    case MeasurementSystem:
        return d->measurementSystem();
    case AMText:
        return d->amText();
    case PMText:
        return d->pmText();
    case FirstDayOfWeek:
        return d->firstDayOfWeek();
    case CurrencySymbol:
        return d->currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()));
    case CurrencyToString:
        return d->toCurrencyString(in.value<QSystemLocale::CurrencyToStringArgument>());
    case UILanguages:
        return d->uiLanguages();
    case LocaleChanged:
        d->update();
        break;
    case NativeLanguageName:
        return d->nativeLanguageName();
    case NativeCountryName:
        return d->nativeCountryName();
    default:
        break;
    }
    return QVariant();
}
Example #16
0
QDomElement MaiaObject::toXml(QVariant arg) {
	
	//dummy document
	QDomDocument doc;
	//value element, we need this in each case
	QDomElement tagValue = doc.createElement("value");

	/* qDebug("type: %d (%s)", arg.type(), arg.typeName()); */

	switch(arg.type()) {
	case QVariant::String: {

		QDomElement tagString = doc.createElement("string"); 
		QDomText textString = doc.createTextNode(arg.toString());
		
		tagValue.appendChild(tagString);
		tagString.appendChild(textString);

		return tagValue;

	} case QVariant::Int: {

		QDomElement tagInt = doc.createElement("int"); 
		QDomText textInt = doc.createTextNode(QString::number(arg.toInt()));
		
		tagValue.appendChild(tagInt);
		tagInt.appendChild(textInt);

		return tagValue;

	} case QVariant::Double: {

		QDomElement tagDouble = doc.createElement("double"); 
		QDomText textDouble = doc.createTextNode(QString::number(arg.toDouble()));
		
		tagValue.appendChild(tagDouble);
		tagDouble.appendChild(textDouble);

		return tagValue;

	} case QVariant::Bool: {
	
		QString textValue = arg.toBool() ? "1" : "0";

		QDomElement tag = doc.createElement("boolean"); 
		QDomText text = doc.createTextNode(textValue);
		
		tagValue.appendChild(tag);
		tag.appendChild(text);

		return tagValue;

	} case QVariant::ByteArray: {

		QString textValue = arg.toByteArray().toBase64();

		QDomElement tag = doc.createElement("base64"); 
		QDomText text = doc.createTextNode(textValue);
		
		tagValue.appendChild(tag);
		tag.appendChild(text);

		return tagValue;

	} case QVariant::DateTime: {
	
		QString textValue = arg.toDateTime().toString("yyyyMMddThh:mm:ss");

		QDomElement tag = doc.createElement("datetime.iso8601"); 
		QDomText text = doc.createTextNode(textValue);
		
		tagValue.appendChild(tag);
		tag.appendChild(text);

		return tagValue;

	} case QVariant::List: {

		QDomElement tagArray = doc.createElement("array");
		QDomElement tagData = doc.createElement("data");
		tagArray.appendChild(tagData);
		tagValue.appendChild(tagArray);

		const QList<QVariant> args = arg.toList();
		for(int i = 0; i < args.size(); ++i) {
			tagData.appendChild(toXml(args.at(i)));
		}
	
		return tagValue;

	} case QVariant::Map: {

		QDomElement tagStruct = doc.createElement("struct");
		QDomElement member;
		QDomElement name;

		tagValue.appendChild(tagStruct);

		QMap<QString, QVariant> map = arg.toMap();
		QMapIterator<QString, QVariant> i(map);
		while(i.hasNext()) {
			i.next();

			member = doc.createElement("member");
			name = doc.createElement("name");

			// (key) -> name -> member -> struct
			tagStruct.appendChild(member);
			member.appendChild(name);
			name.appendChild(doc.createTextNode(i.key()));

			// add variables by recursion
			member.appendChild(toXml(i.value()));
		}

		return tagValue;

	} default:
		qDebug() << "Failed to marshal unknown variant type: " << arg.type() << endl;
	}
	return QDomElement(); //QString::null;
}
int
MarkerRetracement::info (PluginData *pd)
{
  if (! pd->data)
    return 0;
  
  Marker *m = (Marker *) pd->data;
  
  Entity *e = m->settings();

  QVariant *date = e->get(QString("date"));
  if (! date)
    return 0;
  
  QVariant *date2 = e->get(QString("date2"));
  if (! date2)
    return 0;

  QVariant *high = e->get(QString("high"));
  if (! high)
    return 0;

  QVariant *low = e->get(QString("low"));
  if (! low)
    return 0;

  QVariant *l1 = e->get(QString("level1"));
  if (! l1)
    return 0;

  QVariant *l2 = e->get(QString("level2"));
  if (! l2)
    return 0;

  QVariant *l3 = e->get(QString("level3"));
  if (! l3)
    return 0;

  QVariant *l4 = e->get(QString("level4"));
  if (! l4)
    return 0;

  QVariant *l5 = e->get(QString("level5"));
  if (! l5)
    return 0;

  QVariant *l6 = e->get(QString("level6"));
  if (! l6)
    return 0;
  
  pd->info << tr("Retracement");

  QDateTime dt = date->toDateTime();
  pd->info << tr("Start Date") + "=" + dt.toString("yyyy-MM-dd");
  pd->info << tr("Start Time") + "=" + dt.toString("HH:mm:ss");

  dt = date2->toDateTime();
  pd->info << tr("End Date") + "=" + dt.toString("yyyy-MM-dd");
  pd->info << tr("End Time") + "=" + dt.toString("HH:mm:ss");

  Strip strip;
  QString ts;
  strip.strip(high->toDouble(), 4, ts);
  pd->info << tr("High") + "=" + ts;
  
  strip.strip(low->toDouble(), 4, ts);
  pd->info << tr("Low") + "=" + ts;
  
  strip.strip(l1->toDouble(), 4, ts);
  pd->info << tr("Level 1") + "=" + ts;
  
  strip.strip(l2->toDouble(), 4, ts);
  pd->info << tr("Level 2") + "=" + ts;
  
  strip.strip(l3->toDouble(), 4, ts);
  pd->info << tr("Level 3") + "=" + ts;
  
  strip.strip(l4->toDouble(), 4, ts);
  pd->info << tr("Level 4") + "=" + ts;
  
  strip.strip(l5->toDouble(), 4, ts);
  pd->info << tr("Level 5") + "=" + ts;
  
  strip.strip(l6->toDouble(), 4, ts);
  pd->info << tr("Level 6") + "=" + ts;
  
  return 1;
}
QString QgsExpression::formatPreviewString( const QVariant &value, const bool htmlOutput )
{
  static const int MAX_PREVIEW = 60;

  const QString startToken = htmlOutput ? QStringLiteral( "<i>&lt;" ) : QStringLiteral( "<" );
  const QString endToken = htmlOutput ? QStringLiteral( "&gt;</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() )
        separator = QStringLiteral( "," );

      listStr.append( " " );
      listStr.append( formatPreviewString( arrayValue, htmlOutput ) );
      if ( listStr.length() > MAX_PREVIEW - 3 )
      {
        listStr = QString( tr( "%1…" ) ).arg( listStr.left( MAX_PREVIEW - 2 ) );
        break;
      }
    }
    if ( !list.empty() )
      listStr += QStringLiteral( " " );
    listStr += QStringLiteral( "]" );
    return listStr;
  }
  else
  {
    return value.toString();
  }
}
void UIPropertySetters::DefaultSetter(QWidget* editor, SettingsPropertyMapper::WidgetType editorType, SettingsPropertyMapper::PropertyType propertyType, QVariant propertyValue)
{
	switch (editorType)
	{
		case SettingsPropertyMapper::CHECKBOX:
		{
			QCheckBox* pCheckBox = qobject_cast<QCheckBox*>(editor);
			if (pCheckBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pCheckBox->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::RADIOBUTTON:
		{
			QRadioButton* pRadioButton = qobject_cast<QRadioButton*>(editor);
			if (pRadioButton == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pRadioButton->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::CHECKABLE_GROUPBOX:
		{
			QGroupBox* pGroupBox = qobject_cast<QGroupBox*>(editor);
			if (pGroupBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (!pGroupBox->isCheckable())
			{
				qCritical() << "Given QGroupBox is not checkable";
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pGroupBox->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::LINE_EDIT:
		{
			QLineEdit* pLineEdit = qobject_cast<QLineEdit*>(editor);
			if (pLineEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType == SettingsPropertyMapper::STRING || propertyType == SettingsPropertyMapper::INT)
			{
				pLineEdit->setText(propertyValue.toString());
			}
			else
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
			}
			break;
		}
		case SettingsPropertyMapper::TEXT_EDIT:
		{
			QTextEdit* pTextEdit = qobject_cast<QTextEdit*>(editor);
			if (pTextEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::STRING)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pTextEdit->setText(propertyValue.toString());
			break;
		}
		case SettingsPropertyMapper::COMBOBOX:
		{
			QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
			if (pComboBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::INT)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pComboBox->setCurrentIndex(propertyValue.toInt());
			break;
		}
		case SettingsPropertyMapper::SPINBOX:
		{
			QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(editor);
			if (pSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::INT)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pSpinBox->setValue(propertyValue.toInt());
			break;
		}
		case SettingsPropertyMapper::DOUBLE_SPINBOX:
		{
			QDoubleSpinBox* pDoubleSpinBox = qobject_cast<QDoubleSpinBox*>(editor);
			if (pDoubleSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::DOUBLE)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pDoubleSpinBox->setValue(propertyValue.toDouble());
			break;
		}
		case SettingsPropertyMapper::TIME_EDIT:
		{
			QTimeEdit* pTimeEdit = qobject_cast<QTimeEdit*>(editor);
			if (pTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::TIME)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pTimeEdit->setTime(propertyValue.toTime());
			break;
		}
		case SettingsPropertyMapper::DATETIME_EDIT:
		{
			QDateTimeEdit* pDateTimeEdit = qobject_cast<QDateTimeEdit*>(editor);
			if (pDateTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::DATETIME)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pDateTimeEdit->setDateTime(propertyValue.toDateTime());
			break;
		}
		default: break;
	}
}
Example #20
0
File: qgis.cpp Project: GeoCat/QGIS
uint qHash( const QVariant &variant )
{
  if ( !variant.isValid() || variant.isNull() )
    return std::numeric_limits<uint>::max();

  switch ( variant.type() )
  {
    case QVariant::Int:
      return qHash( variant.toInt() );
    case QVariant::UInt:
      return qHash( variant.toUInt() );
    case QVariant::Bool:
      return qHash( variant.toBool() );
    case QVariant::Double:
      return qHash( variant.toDouble() );
    case QVariant::LongLong:
      return qHash( variant.toLongLong() );
    case QVariant::ULongLong:
      return qHash( variant.toULongLong() );
    case QVariant::String:
      return qHash( variant.toString() );
    case QVariant::Char:
      return qHash( variant.toChar() );
    case QVariant::List:

#if QT_VERSION >= 0x050600
      return qHash( variant.toList() );
#else
      {
        QVariantList list = variant.toList();
        if ( list.isEmpty() )
          return -1;
        else
          return qHash( list.at( 0 ) );
      }
#endif
    case QVariant::StringList:
#if QT_VERSION >= 0x050600
      return qHash( variant.toStringList() );
#else
      {
        QStringList list = variant.toStringList();
        if ( list.isEmpty() )
          return -1;
        else
          return qHash( list.at( 0 ) );
      }
#endif
    case QVariant::ByteArray:
      return qHash( variant.toByteArray() );
    case QVariant::Date:
      return qHash( variant.toDate() );
    case QVariant::Time:
      return qHash( variant.toTime() );
    case QVariant::DateTime:
      return qHash( variant.toDateTime() );
    case QVariant::Url:
    case QVariant::Locale:
    case QVariant::RegExp:
      return qHash( variant.toString() );
    default:
      break;
  }

  return std::numeric_limits<uint>::max();
}
Example #21
0
bool Timestamp::fromVariant(const QVariant v)
{
    mT=v.toDateTime().toTime_t();
    emit dataChanged();
    return true;
}
Example #22
0
void MVariant::tostring(QVariant params )
{
    
//    qDebug()<<"\n"<<params.type()<<"\n"<<params;
    switch ( params.type() ) {
    case QVariant::Int:
    case QVariant::UInt:
        this->items << QString::number( params.toInt() );
      this->ret<<this->items;
      //this->items.clear();
        break;

    case QVariant::String:
        this->items <<params.toString();
        this->ret<<this->items;
       //this->items.clear();
        break;

    case QVariant::Double:
        this->items << QString::number( params.toDouble() );
        this->ret<<this->items;
        //this->items.clear();
        break;

    case QVariant::DateTime:
        this->items << params.toDateTime().toString();
		this->ret<<this->items;
        //this->items.clear();
          break;

    case QVariant::Bool:
        this->items << ( params.toBool() ? "true" : "false" );
        this->ret<<this->items;
        //this->items.clear();
        break;

    case QVariant::ByteArray:
        {
            QString data = params.toByteArray().toBase64();
            if ( data.length() > 128 ) {
                data = data.left(64)+"...";
            }
            this->items << data;
          this->ret<<this->items;
          // this->items.clear();
            break;
        }

    case QVariant::StringList:
    case QVariant::List:
        {   //this->items.clear();    
            QListIterator<QVariant> it( params.toList() );
            while( it.hasNext() ) {
				//it.next();
                this->tostring(it.next());
            }
            break;
        }
    case QVariant::Map:
        {
			
			//QStringList item;
            QMapIterator<QString,QVariant> it( params.toMap());
            while( it.hasNext() ) {
               it.next();
               //this->items.clear();
				this->items<<it.key();		
				this->tostring(it.value());
				//this->ret<<this->items;
				this->items.clear();
            }
            
            break;
        }
      default:
			break;
    
    }
   
}
Example #23
0
bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs )
{
  // invalid < NULL < any value
  if ( !lhs.isValid() )
    return rhs.isValid();
  else if ( lhs.isNull() )
    return rhs.isValid() && !rhs.isNull();
  else if ( !rhs.isValid() || rhs.isNull() )
    return false;

  switch ( lhs.type() )
  {
    case QVariant::Int:
      return lhs.toInt() < rhs.toInt();
    case QVariant::UInt:
      return lhs.toUInt() < rhs.toUInt();
    case QVariant::LongLong:
      return lhs.toLongLong() < rhs.toLongLong();
    case QVariant::ULongLong:
      return lhs.toULongLong() < rhs.toULongLong();
    case QVariant::Double:
      return lhs.toDouble() < rhs.toDouble();
    case QVariant::Char:
      return lhs.toChar() < rhs.toChar();
    case QVariant::Date:
      return lhs.toDate() < rhs.toDate();
    case QVariant::Time:
      return lhs.toTime() < rhs.toTime();
    case QVariant::DateTime:
      return lhs.toDateTime() < rhs.toDateTime();
    case QVariant::Bool:
      return lhs.toBool() < rhs.toBool();

    case QVariant::List:
    {
      const QList<QVariant> &lhsl = lhs.toList();
      const QList<QVariant> &rhsl = rhs.toList();

      int i, n = qMin( lhsl.size(), rhsl.size() );
      for ( i = 0; i < n && lhsl[i].type() == rhsl[i].type() && lhsl[i].isNull() == rhsl[i].isNull() && lhsl[i] == rhsl[i]; i++ )
        ;

      if ( i == n )
        return lhsl.size() < rhsl.size();
      else
        return qgsVariantLessThan( lhsl[i], rhsl[i] );
    }

    case QVariant::StringList:
    {
      const QStringList &lhsl = lhs.toStringList();
      const QStringList &rhsl = rhs.toStringList();

      int i, n = qMin( lhsl.size(), rhsl.size() );
      for ( i = 0; i < n && lhsl[i] == rhsl[i]; i++ )
        ;

      if ( i == n )
        return lhsl.size() < rhsl.size();
      else
        return lhsl[i] < rhsl[i];
    }

    default:
      return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
  }
}
QString QGalleryTrackerDateTimeColumn::toString(const QVariant &variant) const
{
    return variant.toDateTime().toString(Qt::ISODate);
}
Example #25
0
    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
      }
    }
Example #26
0
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;
}
Example #27
0
void IxValidator::validateDateFuture(const QVariant & v, QxInvalidValueX & lstInvalidValues) const
{
   QDateTime dt = v.toDateTime();
   if (! dt.isValid() || (dt < QDateTime::currentDateTime())) { lstInvalidValues.insert(this); }
}
Example #28
0
QVariant QSystemLocale::query(QueryType type, QVariant in) const
{
    QSystemLocaleData *d = qSystemLocaleData();
#if defined(Q_OS_QNX)
    QBBLocaleData *bbd = qbbLocaleData();
#endif
    const QLocale &lc_numeric = d->lc_numeric;
    const QLocale &lc_time = d->lc_time;
    const QLocale &lc_monetary = d->lc_monetary;
    const QLocale &lc_messages = d->lc_messages;

    switch (type) {
    case DecimalPoint:
        return lc_numeric.decimalPoint();
    case GroupSeparator:
        return lc_numeric.groupSeparator();
    case ZeroDigit:
        return lc_numeric.zeroDigit();
    case NegativeSign:
        return lc_numeric.negativeSign();
    case DateFormatLong:
        return lc_time.dateFormat(QLocale::LongFormat);
    case DateFormatShort:
        return lc_time.dateFormat(QLocale::ShortFormat);
    case TimeFormatLong:
        return lc_time.timeFormat(QLocale::LongFormat);
    case TimeFormatShort:
        return lc_time.timeFormat(QLocale::ShortFormat);
    case DayNameLong:
        return lc_time.dayName(in.toInt(), QLocale::LongFormat);
    case DayNameShort:
        return lc_time.dayName(in.toInt(), QLocale::ShortFormat);
    case MonthNameLong:
        return lc_time.monthName(in.toInt(), QLocale::LongFormat);
    case MonthNameShort:
        return lc_time.monthName(in.toInt(), QLocale::ShortFormat);
    case DateToStringLong:
        return lc_time.toString(in.toDate(), QLocale::LongFormat);
    case DateToStringShort:
        return lc_time.toString(in.toDate(), QLocale::ShortFormat);
    case TimeToStringLong:
        return lc_time.toString(in.toTime(), QLocale::LongFormat);
    case TimeToStringShort:
        return lc_time.toString(in.toTime(), QLocale::ShortFormat);
    case DateTimeFormatLong:
        return lc_time.dateTimeFormat(QLocale::LongFormat);
    case DateTimeFormatShort:
        return lc_time.dateTimeFormat(QLocale::ShortFormat);
    case DateTimeToStringLong:
        return lc_time.toString(in.toDateTime(), QLocale::LongFormat);
    case DateTimeToStringShort:
        return lc_time.toString(in.toDateTime(), QLocale::ShortFormat);
    case PositiveSign:
        return lc_numeric.positiveSign();
    case AMText:
        return lc_time.amText();
    case PMText:
        return lc_time.pmText();
    case FirstDayOfWeek:
        return lc_time.firstDayOfWeek();
    case CurrencySymbol:
        return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()));
    case CurrencyToString: {
        switch (in.type()) {
        case QVariant::Int:
            return lc_monetary.toCurrencyString(in.toInt());
        case QVariant::UInt:
            return lc_monetary.toCurrencyString(in.toUInt());
        case QVariant::Double:
            return lc_monetary.toCurrencyString(in.toDouble());
        case QVariant::LongLong:
            return lc_monetary.toCurrencyString(in.toLongLong());
        case QVariant::ULongLong:
            return lc_monetary.toCurrencyString(in.toULongLong());
        default:
            break;
        }
        return QString();
    }
    case MeasurementSystem: {
        const QString meas_locale = QString::fromLatin1(d->lc_measurement_var.constData(), d->lc_measurement_var.size());
        if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0)
            return QLocale::MetricSystem;
        if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0)
            return QLocale::MetricSystem;
#if defined(Q_OS_QNX)
        return bbd->ppsMeasurement;
#endif
        return QVariant((int)QLocale(meas_locale).measurementSystem());
    }
    case UILanguages: {
        static QString languages = QString::fromLatin1(qgetenv("LANGUAGE"));
        if (!languages.isEmpty()) {
            QStringList lst = languages.split(QLatin1Char(':'));
            for (int i = 0; i < lst.size();) {
                const QString &name = lst.at(i);
                QString lang, script, cntry;
                if (name.isEmpty() || !qt_splitLocaleName(name, lang, script, cntry))
                    lst.removeAt(i);
                else
                    ++i;
            }
            return lst;
        }
        if (!d->lc_messages_var.isEmpty()) {
            QString lang, script, cntry;
            if (qt_splitLocaleName(QString::fromLatin1(d->lc_messages_var.constData(), d->lc_messages_var.size()),
                                lang, script, cntry)) {
                if (!cntry.length() && lang.length())
                    return QStringList(lang);
                return QStringList(lang % QLatin1Char('-') % cntry);
            }
        }
        return QVariant();
    }
    case StringToStandardQuotation:
        return lc_messages.quoteString(in.value<QStringRef>());
    case StringToAlternateQuotation:
        return lc_messages.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation);
    case ListToSeparatedString:
        return lc_messages.createSeparatedList(in.value<QStringList>());
    case LocaleChanged:
        d->updateLocale();
        break;
    default:
        break;
    }
    return QVariant();
}
Example #29
0
void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
{
    Q_Q(QDateTimeAxis);
    if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
        q->setRange(min.toDateTime(), max.toDateTime());
}
Example #30
0
QVariant TableModel::data(const QModelIndex &index, int role) const
{
	QVariant ret;
	if(!index.isValid())
		return ret;
	if(role == RawValueRole) {
		ret = value(index.row(), index.column());
	}
	else if(role == ValueIsDirtyRole) {
		ret = isDirty(index.row(), index.column());
	}
	else if(role == SortRole) {
		int type = columnType(index.column());
		if(type == QVariant::Bool)
			ret = value(index.row(), index.column()).toBool();
		else
			ret = data(index, Qt::DisplayRole);
	}
	else if(role == Qt::DisplayRole) {
		ColumnDefinition cd = m_columns.value(index.column());
		if(cd.isNull()) {
			return QString("!%1").arg(index.column());
		}
		if(data(index, ValueIsNullRole).toBool()) {
			if(isNullReportedAsString())
				return QStringLiteral("null");
			return QVariant();
		}
		ret = data(index, Qt::EditRole);
		int type = columnType(index.column());
		if(type == QVariant::Invalid)
			type = ret.type(); /// pokud jsou sloupce virtualni (sloupce se pocitaji, nemusi byt pro ne definovan typ)
		if(type == QVariant::ByteArray) {
			const static QString blob_string = "{blob %1%2}";
			int size = ret.toByteArray().size();
			if(size < 1024) ret = blob_string.arg(size).arg(" B");
			else ret = blob_string.arg(size/1024).arg("kB");
		}
		else if(type == QVariant::Bool) {
			/// display check
			ret = QString();
		}
		QString format = cd.format();
		if(format.isEmpty()) {
			if(type == QVariant::Date) {
				format = m_defaultDateFormat;
			}
			else if(type == QVariant::Time) {
				format = m_defaultTimeFormat;
				//qfInfo() << "format" << format;
			}
			else if(type == QVariant::DateTime) {
				format = m_defaultDateTimeFormat;
				//qfInfo() << "format" << format;
			}
		}
		if(!format.isEmpty()) {
			if(type == QVariant::Time) {
				QTime t = ret.toTime();
				ret = t.toString(format);
			}
			else if(type == QVariant::Date) {
				QDate d = ret.toDate();
				ret = d.toString(format);
			}
			else if(type == QVariant::DateTime) {
				QDateTime dt = ret.toDateTime();
				ret = dt.toString(format);
			}
		}
	}
	else if(role == Qt::EditRole) {
		ret = data(index, RawValueRole);
		ret = rawValueToEdit(index.column(), ret);
	}
	else if (role == ValueIsNullRole) {
		ret = data(index, RawValueRole);
		return ret.isNull() && ret.isValid();
	}
	else if (role == Qt::TextAlignmentRole) {
		const ColumnDefinition cd = m_columns.value(index.column());
		Qt::Alignment al = cd.alignment();
		if(!!al)
			ret = (int)al;
		else {
			if(!data(index, ValueIsNullRole).toBool()) {
				ret = data(index, RawValueRole);
				if(ret.type() > QVariant::Bool && ret.type() <= QVariant::Double)
					ret = Qt::AlignRight;
				else
					ret = Qt::AlignLeft;
			}
		}
	}
	else if(role == Qt::TextColorRole) {
		int type = columnType(index.column());
		if(type == QVariant::ByteArray)
			return QColor(Qt::blue);
		if(data(index, ValueIsNullRole).toBool()) {
			return QColor(Qt::blue);
		}
		ret = QVariant();
	}
	else if (role == Qt::BackgroundColorRole) {
		/// delegate does it
	}
	else if (role == Qt::CheckStateRole) {
		int type = columnType(index.column());
		if(type == QVariant::Bool) {
			//qfInfo() << "BOOL";
			return (data(index, Qt::EditRole).toBool()? Qt::Checked: Qt::Unchecked);
		}
		return QVariant();
	}
	else if (role == Qt::ToolTipRole) {
		QString s = data(index, Qt::DisplayRole).toString();
		//s = "<pre>" + s + "</pre>"; /// kvuli chybe v Qt 4.6.3, kdy aplikace pada pokud je v textu za sebou 0x09 0x0A
		s.replace("\t\n", "\n");
		ret = s;
		//ret = data(index, Qt::DisplayRole);
		//qfInfo() << ret.toString();
	}
	return ret;
}