// Update the database's user record void UserTable::updateSyncState(SyncState s) { NSqlQuery query(*db); query.prepare("Delete from UserTable where key=:key1 or key=:key2 or key=:key3;"); query.bindValue(":key1", USER_SYNC_UPLOADED); query.bindValue(":key2", USER_SYNC_LAST_DATE); query.bindValue(":key3", USER_SYNC_LAST_NUMBER); query.exec(); query.prepare("Insert into UserTable (key, data) values (:key, :data);"); if (s.uploaded.isSet()) { query.bindValue(":key", USER_SYNC_UPLOADED); query.bindValue(":data",qlonglong(s.uploaded)); if (!query.exec()) { QLOG_ERROR() << "Error updating USER_SYNC_UPLOADED : " << query.lastError(); } } query.prepare("Insert into UserTable (key, data) values (:key, :data);"); query.bindValue(":key", USER_SYNC_LAST_DATE); query.bindValue(":data", qlonglong(s.currentTime)); if (!query.exec()) { QLOG_ERROR() << "Error updating USER_SYNC_LAST_DATE : " << query.lastError(); } query.prepare("Insert into UserTable (key, data) values (:key, :data);"); query.bindValue(":key", USER_SYNC_LAST_NUMBER); query.bindValue(":data", s.updateCount); if (!query.exec()) { QLOG_ERROR() << "Error updating USER_SYNC_LAST_NUMBER : " << query.lastError(); } query.finish(); }
int save_toIni(QString Key, QString Device, long subdevice, long channel, long range=0) { AppSettings.setValue(QString("Analog%1_device").arg(Key),Device); AppSettings.setValue(QString("Analog%1_subdevice").arg(Key),qlonglong(subdevice)); AppSettings.setValue(QString("Analog%1_channel").arg(Key),qlonglong(channel)); AppSettings.setValue(QString("Analog%1_range").arg(Key),qlonglong(range)); return 0; }
void DB_TEST_BASE::AllocateEmptyProcessVector() { empty_process_values.push_back(QString("1")); //PROCESS_ID empty_process_values.push_back(QString("0")); //DISPUTETYPE empty_process_values.push_back(QString("2000-01-01")); //CREATIONDATE empty_process_values.push_back(QString("2000-01-01")); //UPDATEDDATE empty_process_values.push_back(QString("2000-01-01 12:00:01")); //CREATIONDATETIME empty_process_values.push_back(QString("2000-01-01 12:00:01")); //UPDATEDDATETIME empty_process_values.push_back(QString("0")); //DISPUTESTATE empty_process_values.push_back(QString("0")); //DISPUTEINTERNALSTATE empty_process_values.push_back(QString("1")); //DISPUTECOUNTY empty_process_values.push_back(QString("0")); //REFERALSOURCE empty_process_values.push_back(QString("0")); //INQUIRYTYPE empty_process_values.push_back(QString("0")); //INFOONLY empty_process_values.push_back(QString("0")); //ISCOURTCASE empty_process_values.push_back(QString("2000-01-01")); //COURTDATE empty_process_values.push_back(QString("0")); //COURTCASETYPE empty_process_values.push_back(QString("")); //COURTORDERTYPE empty_process_values.push_back(QString("0")); //TRANSLATORREQUIRED empty_process_values.push_back(QString("0")); //SESSIONTYPE empty_process_values.push_back(QString("0")); //MEDIATIONCLAUSE QVariant temp; temp = qlonglong(-1163005939); empty_process_values.push_back(QString(temp.toString())); //IndirectChildren empty_process_values.push_back(QString(temp.toString())); //DirectChildren empty_process_values.push_back(QString(temp.toString())); //IndirectAdult empty_process_values.push_back(QString(temp.toString())); //DirectAdult empty_process_values.push_back(QString("")); //Tags }
QVariantMap Mpris2::Metadata() const { QVariantMap map; if (m_trayicon->m_playIndex == -1) return map; const SongInfo& si = m_trayicon->m_playlist.at(m_trayicon->m_playIndex); map["mpris:trackid"] = "/org/mpris/MediaPlayer2/Track/" + QString::number(si.sid); map["mpris:length"] = qlonglong(si.length) * 1000 * 1000; map["mpris:artUrl"] = QString(si.picture).replace("/mpic/", "/lpic/"); map["xesam:album"] = si.albumtitle; map["xesam:artist"] = QStringList() << si.artist; map["xesam:title"] = si.title; map["xesam:url"] = si.url; // QString command = "notify-send "; // command += si.title; // command += " '" + si.artist + "-" + si.albumtitle + "'"; // command += " '-t' 5000"; //// system("notify-send 'The Message Title' 'Your Message Text' '-t' 5000"); // system(command.toUtf8().constData()); return map; }
void tst_QDjangoMetaModel::testLongLong() { QStringList sql; if (QDjango::database().driverName() == QLatin1String("QPSQL")) sql << QLatin1String("CREATE TABLE \"tst_longlong\" (\"id\" serial PRIMARY KEY, \"value\" bigint NOT NULL)"); else if (QDjango::database().driverName() == QLatin1String("QMYSQL") || QDjango::database().driverName() == QLatin1String("QMYSQL3")) sql << QLatin1String("CREATE TABLE `tst_longlong` (`id` integer NOT NULL PRIMARY KEY AUTO_INCREMENT, `value` bigint NOT NULL)"); else sql << QLatin1String("CREATE TABLE \"tst_longlong\" (\"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT, \"value\" bigint NOT NULL)"); init<tst_LongLong>(sql); setAndGet<tst_LongLong>(qlonglong(0)); setAndGet<tst_LongLong>(qlonglong(-9223372036854775807ll)); setAndGet<tst_LongLong>(qlonglong(9223372036854775807ll)); cleanup<tst_LongLong>(); }
World::World(const QString & world_name) : timeStep(0), worldName(world_name), rwLock(new QReadWriteLock()), map(new WorldMap(&world_name)), toResetDir(UP) { puts(qPrintable(tr("Loading world settings..."))); world = this; QSettings game_settings("freg.ini", QSettings::IniFormat); numShreds = game_settings.value("number_of_shreds", MIN_WORLD_SIZE). toLongLong(); if ( 1 != numShreds%2 ) { ++numShreds; fprintf(stderr, "Invalid number of shreds. Set to %hu.\n", numShreds); } if ( numShreds < MIN_WORLD_SIZE ) { fprintf(stderr, "Number of shreds: to small: %hu. Set to %hu.\n", numShreds, MIN_WORLD_SIZE); numShreds = MIN_WORLD_SIZE; } SetNumActiveShreds(game_settings.value("number_of_active_shreds", numShreds).toUInt()); game_settings.setValue("number_of_shreds", numShreds); game_settings.setValue("number_of_active_shreds", numActiveShreds); QDir::current().mkpath(worldName+"/texts"); QSettings settings(worldName+"/settings.ini", QSettings::IniFormat); time = settings.value("time", END_OF_NIGHT).toLongLong(); spawnLongi = settings.value( "spawn_longitude", int(qrand() % MapSize()) ).toLongLong(); spawnLati = settings.value( "spawn_latitude", int(qrand() % MapSize()) ).toLongLong(); settings.setValue("spawn_longitude", qlonglong(spawnLongi)); settings.setValue("spawn_latitude", qlonglong(spawnLati)); longitude = settings.value("longitude", int(spawnLongi)).toLongLong(); latitude = settings.value("latitude", int(spawnLati )).toLongLong(); shredStorage = new ShredStorage(numShreds+2, longitude, latitude); puts(qPrintable(tr("Loading world..."))); LoadAllShreds(); emit UpdatedAll(); } // World::World(const QString & world_name)
bool SecurityManager::bannedIP(const QString &ip) { QHash<QString, unsigned int>::const_iterator i = bannedIPs.find(ip); bool isBanned = (i != bannedIPs.end()); if (isBanned && i.value() != 0 && i.value() < qlonglong(QDateTime::currentDateTimeUtc().toTime_t())) { /* We expire the tempban here if we should */ unbanIP(ip); return false; } return isBanned; }
// update the last date we synchronized void UserTable::updateLastSyncDate(long date) { NSqlQuery query(*db); query.prepare("delete from UserTable where key=:key"); query.bindValue(":key", USER_SYNC_LAST_DATE); query.exec(); query.prepare("Insert into UserTable (key, data) values (:key, :data)"); query.bindValue(":key", USER_SYNC_LAST_DATE); query.bindValue(":data", qlonglong(date)); query.exec(); query.finish(); }
QVariant QFRDRTableSetCellsDialog::getValue() const { switch(ui->cmbType->currentIndex()) { case 0: return ui->edtString->text(); case 1: return ui->edtNumber->value(); case 2: return qlonglong(ui->edtNumber->value()); case 3: return ui->chkBoolean->isChecked(); case 4: return ui->edtDateTime->dateTime(); default: return QVariant(); } return QVariant(); }
void QgsServerLogger::logMessage( const QString& message, const QString& tag, QgsMessageLog::MessageLevel level ) { Q_UNUSED( tag ); if ( !mLogFile.isOpen() || mLogLevel > level ) { return; } mTextStream << ( "[" + QString::number( qlonglong( QCoreApplication::applicationPid() ) ) + "][" + QTime::currentTime().toString() + "] " + message + "\n" ); mTextStream.flush(); }
void World::CleanAll() { static bool cleaned = false; if ( cleaned ) { return; } cleaned = true; WriteLock(); quit(); wait(); Unlock(); DeleteAllShreds(); delete map; delete shredStorage; delete rwLock; QSettings settings(worldName+"/settings.ini", QSettings::IniFormat); settings.setValue("time", qlonglong(time)); settings.setValue("longitude", qlonglong(longitude)); settings.setValue("latitude", qlonglong(latitude)); }
QValidator::State QDoubleValidator::validate(QString & input, int &) const { Q_D(const QDoubleValidator); QLocalePrivate::NumberMode numMode = QLocalePrivate::DoubleStandardMode; switch (d->notation) { case StandardNotation: numMode = QLocalePrivate::DoubleStandardMode; break; case ScientificNotation: numMode = QLocalePrivate::DoubleScientificMode; break; }; QByteArray buff; if (!locale().d()->validateChars(input, numMode, &buff, dec)) { QLocale cl(QLocale::C); if (!cl.d()->validateChars(input, numMode, &buff, dec)) return Invalid; } if (buff.isEmpty()) return Intermediate; if (b >= 0 && buff.startsWith('-')) return Invalid; if (t < 0 && buff.startsWith('+')) return Invalid; bool ok, overflow; double i = QLocalePrivate::bytearrayToDouble(buff.constData(), &ok, &overflow); if (overflow) return Invalid; if (!ok) return Intermediate; if (i >= b && i <= t) return Acceptable; if (d->notation == StandardNotation) { double max = qMax(qAbs(b), qAbs(t)); if (max < LLONG_MAX) { qlonglong n = pow10(numDigits(qlonglong(max))) - 1; if (qAbs(i) > n) return Invalid; } } return Intermediate; }
void ConfigFile::setRemotePollInterval(chrono::milliseconds interval, const QString &connection) { QString con(connection); if (connection.isEmpty()) con = defaultConnection(); if (interval < chrono::seconds(5)) { qCWarning(lcConfigFile) << "Remote Poll interval of " << interval.count() << " is below five seconds."; return; } QSettings settings(configFile(), QSettings::IniFormat); settings.beginGroup(con); settings.setValue(QLatin1String(remotePollIntervalC), qlonglong(interval.count())); settings.sync(); }
//---------------------------------------------------------------------------------- void tst_QIODevice::constructing_QTcpSocket() { #if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST) QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll); #endif QTcpSocket socket; QIODevice *device = &socket; QVERIFY(!device->isOpen()); socket.connectToHost(QtNetworkSettings::serverName(), 143); QVERIFY(socket.waitForConnected(5000)); QVERIFY(device->isOpen()); while (!device->canReadLine()) QVERIFY(device->waitForReadyRead(5000)); char buf[1024]; memset(buf, 0, sizeof(buf)); qlonglong lineLength = device->readLine(buf, sizeof(buf)); QVERIFY(lineLength > 0); QCOMPARE(socket.pos(), qlonglong(0)); socket.close(); socket.connectToHost(QtNetworkSettings::serverName(), 143); QVERIFY(socket.waitForConnected(5000)); QVERIFY(device->isOpen()); while (!device->canReadLine()) QVERIFY(device->waitForReadyRead(5000)); char buf2[1024]; memset(buf2, 0, sizeof(buf2)); QCOMPARE(socket.readLine(buf2, sizeof(buf2)), lineLength); char *c1 = buf; char *c2 = buf2; while (*c1 && *c2) { QCOMPARE(*c1, *c2); ++c1; ++c2; } QCOMPARE(*c1, *c2); }
void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf, QComboBox *combo ) { module_config_t *p_config = config_FindConfig( VLC_OBJECT(p_intf), configname ); if( p_config == NULL ) return; if( (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING ) { char **values, **texts; ssize_t count = config_GetPszChoices(VLC_OBJECT(p_intf), configname, &values, &texts); for( ssize_t i = 0; i < count; i++ ) { combo->addItem( qtr(texts[i]), QVariant(qfu(values[i])) ); if( p_config->value.psz && !strcmp(p_config->value.psz, values[i]) ) combo->setCurrentIndex( i ); free( texts[i] ); free( values[i] ); } free( texts ); free( values ); } else { int64_t *values; char **texts; ssize_t count = config_GetIntChoices(VLC_OBJECT(p_intf), configname, &values, &texts); for( ssize_t i = 0; i < count; i++ ) { combo->addItem( qtr(texts[i]), QVariant(qlonglong(values[i])) ); if( p_config->value.i == values[i] ) combo->setCurrentIndex( i ); free( texts[i] ); } free( texts ); } if( p_config->psz_longtext != NULL ) combo->setToolTip( qfu( p_config->psz_longtext ) ); }
void QueryLabel::startDrag() { if ( m_query.isNull() ) return; QByteArray queryData; QDataStream queryStream( &queryData, QIODevice::WriteOnly ); QMimeData* mimeData = new QMimeData(); mimeData->setText( text() ); queryStream << qlonglong( &m_query ); mimeData->setData( "application/tomahawk.query.list", queryData ); if ( m_hoverType != None ) { QString extra; switch( m_hoverType ) { case Artist: extra = "artist"; break; case Album: extra = "album"; break; case Track: extra = "track"; break; default: break; } mimeData->setData( "application/tomahawk.dragsource.type", extra.toUtf8() ); } QDrag *drag = new QDrag( this ); drag->setMimeData( mimeData ); drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeTrack ) ); // QPoint hotSpot = event->pos() - child->pos(); // drag->setHotSpot( hotSpot ); drag->exec( Qt::CopyAction ); }
/*! \brief Add a resource to the tree \param comp the resource */ void EntitiesTreeWidget::addComputer(yarp::manager::Computer* comp) { QTreeWidgetItem *item = new QTreeWidgetItem(resourcesNode,QStringList() << comp->getName()); item->setData(0,Qt::UserRole + 1,qlonglong(comp)); item->setData(0,Qt::UserRole, yarp::manager::RESOURCE); item->setIcon(0,QIcon(":/computer22.svg")); string fname; string fpath = comp->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos){ fname = fpath.substr(pos+1); } else { fname = fpath; } fname = fname + string(" (") + fpath + string(")"); QTreeWidgetItem *xml = new QTreeWidgetItem(item,QStringList() << fname.data()); xml->setData(0,Qt::UserRole + 1,QString(fpath.data())); xml->setData(0,Qt::UserRole, yarp::manager::NODE_FILENAME); }
/*! \brief Add a module to the tree \param mod the module */ void EntitiesTreeWidget::addModule(yarp::manager::Module* mod) { QTreeWidgetItem *item = new QTreeWidgetItem(modulesNode,QStringList() << mod->getName()); item->setData(0,Qt::UserRole + 1,qlonglong(mod)); item->setData(0,Qt::UserRole, yarp::manager::MODULE); item->setIcon(0,QIcon(":/module22.svg")); string fname; string fpath = mod->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos){ fname = fpath.substr(pos+1); } else { fname = fpath; } fname = fname + string(" (") + fpath + string(")"); QTreeWidgetItem *xml = new QTreeWidgetItem(item,QStringList() << fname.data()); xml->setData(0,Qt::UserRole + 1,QString(fpath.data())); xml->setData(0,Qt::UserRole, yarp::manager::NODE_FILENAME); }
QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocaleData::NumberMode numMode, const QLocale &locale) const { Q_Q(const QDoubleValidator); QByteArray buff; if (!locale.d->m_data->validateChars(input, numMode, &buff, q->dec, locale.numberOptions() & QLocale::RejectGroupSeparator)) { return QValidator::Invalid; } if (buff.isEmpty()) return QValidator::Intermediate; if (q->b >= 0 && buff.startsWith('-')) return QValidator::Invalid; if (q->t < 0 && buff.startsWith('+')) return QValidator::Invalid; bool ok, overflow; double i = QLocaleData::bytearrayToDouble(buff.constData(), &ok, &overflow); if (overflow) return QValidator::Invalid; if (!ok) return QValidator::Intermediate; if (i >= q->b && i <= q->t) return QValidator::Acceptable; if (notation == QDoubleValidator::StandardNotation) { double max = qMax(qAbs(q->b), qAbs(q->t)); if (max < LLONG_MAX) { qlonglong n = pow10(numDigits(qlonglong(max))) - 1; if (qAbs(i) > n) return QValidator::Invalid; } } return QValidator::Intermediate; }
/*! \brief Add an application to the tree \param app the application */ void EntitiesTreeWidget::addApplication(yarp::manager::Application *app) { QTreeWidgetItem *item = new QTreeWidgetItem(applicationNode,QStringList() << app->getName()); item->setData(0,Qt::UserRole + 1,qlonglong(app)); item->setData(0,Qt::UserRole, yarp::manager::APPLICATION); item->setIcon(0,QIcon(":/images/application_ico.png")); string fname; string fpath = app->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos){ fname = fpath.substr(pos+1); } else { fname = fpath; } fname = fname + string(" (") + fpath + string(")"); QTreeWidgetItem *xml = new QTreeWidgetItem(item,QStringList() << fname.data()); xml->setData(0,Qt::UserRole + 1,QString(fpath.data())); xml->setData(0,Qt::UserRole, yarp::manager::NODE_FILENAME); }
void QueryLabel::startDrag() { if ( m_query.isNull() ) return; QByteArray queryData; QDataStream queryStream( &queryData, QIODevice::WriteOnly ); QMimeData* mimeData = new QMimeData(); mimeData->setText( text() ); queryStream << qlonglong( &m_query ); mimeData->setData( "application/tomahawk.query.list", queryData ); QDrag *drag = new QDrag( this ); drag->setMimeData( mimeData ); drag->setPixmap( TomahawkUtils::createDragPixmap() ); // QPoint hotSpot = event->pos() - child->pos(); // drag->setHotSpot( hotSpot ); drag->exec( Qt::CopyAction ); }
QValidator::State QLongDoubleValidator::validate(QString & input, int &) const { QByteArray buff; if (!validateChars(input, &buff, dec)) return QValidator::Invalid; if (buff.isEmpty()) return QValidator::Intermediate; if (q->b >= 0 && buff.startsWith('-')) return QValidator::Invalid; if (q->t < 0 && buff.startsWith('+')) return QValidator::Invalid; bool ok, overflow; long double i = bytearrayToLongDouble(buff.constData(), &ok, &overflow); if (overflow) return QValidator::Invalid; if (!ok) return QValidator::Intermediate; if (i >= q->b && i <= q->t) return QValidator::Acceptable; if (mNotation == StandardNotation) { long double max = qMax(qAbs(q->b), qAbs(q->t)); if (max < LLONG_MAX) { qlonglong n = pow10(numDigits(qlonglong(max))) - 1; if (qAbs(i) > n) return QValidator::Invalid; } } return QValidator::Intermediate; }
/* Pass the update straight on to the QSlider unless the user is moving the slider. Note, it would not be common to have a user editing a regularly updating value. However, this scenario should be allowed for. A reasonable reason for a user modified value to update on a gui is if is is written to by another user on another gui. This is the slot used to recieve data updates from a QCaObject based class. */ void QESlider::setValueIfNoFocus( const double& value, QCaAlarmInfo& alarmInfo, QCaDateTime&, const unsigned int& ) { // Do nothing if doing a single shot read (done when not subscribing to get enumeration values) if( ignoreSingleShotRead ) { ignoreSingleShotRead = false; return; } // Signal a database value change to any Link widgets emit dbValueChanged( qlonglong( value ) ); // Update the slider only if the user is not interacting with the object. if( !hasFocus() ) { updateInProgress = true; currentValue = value; int intValue = int( (value - offset) * scale ); setValue( intValue ); updateInProgress = false; } // Invoke common alarm handling processing. processAlarmInfo( alarmInfo ); }
// common function for wheel up/down and key up/down // delta is in wheel units: a delta of 120 means to increment by 1 void SpinBox::increment(int delta, int shift) // shift = 1 means to increment * 10, shift = -1 means / 10 { bool ok; QString str = text(); //qDebug() << "increment from " << str; const double oldVal = str.toDouble(&ok); if (!ok) { // Not a valid double value, don't do anything return; } bool useCursorPositionIncr = appPTR->getCurrentSettings()->useCursorPositionIncrements(); // First, treat the standard case: use the Knob increment if (!useCursorPositionIncr) { double val = oldVal; _imp->currentDelta += delta; double inc = std::pow(10., shift) * _imp->currentDelta * _imp->increment / 120.; double maxiD = 0.; double miniD = 0.; switch (_imp->type) { case eSpinBoxTypeDouble: { maxiD = _imp->maxi.toDouble(); miniD = _imp->mini.toDouble(); val += inc; _imp->currentDelta = 0; break; } case eSpinBoxTypeInt: { maxiD = _imp->maxi.toInt(); miniD = _imp->mini.toInt(); val += (int)inc; // round towards zero // Update the current delta, which contains the accumulated error _imp->currentDelta -= ( (int)inc ) * 120. / _imp->increment; assert(std::abs(_imp->currentDelta) < 120); break; } } val = std::max( miniD, std::min(val, maxiD) ); if (val != oldVal) { setValue(val); Q_EMIT valueChanged(val); } return; } // From here on, we treat the positin-based increment. if ( (str.indexOf( QLatin1Char('e') ) != -1) || (str.indexOf( QLatin1Char('E') ) != -1) ) { // Sorry, we don't handle numbers with an exponent, although these are valid doubles return; } _imp->currentDelta += delta; int inc_int = _imp->currentDelta / 120; // the number of integert increments // Update the current delta, which contains the accumulated error _imp->currentDelta -= inc_int * 120; if (inc_int == 0) { // Nothing is changed, just return return; } // Within the value, we modify: // - if there is no selection, the first digit right after the cursor (or if it is an int and the cursor is at the end, the last digit) // - if there is a selection, the first digit after the start of the selection int len = str.size(); // used for chopping spurious characters if (len <= 0) { return; // should never happen } // The position in str of the digit to modify in str() (may be equal to str.size()) int pos = ( hasSelectedText() ? selectionStart() : cursorPosition() ); //if (pos == len) { // select the last character? // pos = len - 1; //} // The position of the decimal dot int dot = str.indexOf( QLatin1Char('.') ); if (dot == -1) { dot = str.size(); } // Now, chop trailing and leading whitespace (and update len, pos and dot) // Leading whitespace while ( len > 0 && str[0].isSpace() ) { str.remove(0, 1); --len; if (pos > 0) { --pos; } --dot; assert(dot >= 0); assert(len > 0); } // Trailing whitespace while ( len > 0 && str[len - 1].isSpace() ) { str.remove(len - 1, 1); --len; if (pos > len) { --pos; } if (dot > len) { --dot; } assert(len > 0); } assert( oldVal == str.toDouble() ); // check that the value hasn't changed due to whitespace manipulation // On int types, there should not be any dot if ( (_imp->type == eSpinBoxTypeInt) && (len > dot) ) { // Remove anything after the dot, including the dot str.resize(dot); len = dot; } // Adjust pos so that it doesn't point to a dot or a sign assert( 0 <= pos && pos <= str.size() ); while ( pos < str.size() && ( pos == dot || str[pos] == QLatin1Char('+') || str[pos] == QLatin1Char('-') ) ) { ++pos; } assert(len >= pos); // Set the shift (may have to be done twice due to the dot) pos -= shift; if (pos == dot) { pos -= shift; } // Now, add leading and trailing zeroes so that pos is a valid digit position // (beware of the sign!) // Trailing zeroes: // (No trailing zeroes on int, of course) assert( len == str.size() ); if ( (_imp->type == eSpinBoxTypeInt) && (pos >= len) ) { // If this is an int and we are beyond the last position, change the last digit pos = len - 1; // also reset the shift if it was negative if (shift < 0) { shift = 0; } } while ( pos >= str.size() ) { assert(_imp->type == eSpinBoxTypeDouble); // Add trailing zero, maybe preceded by a dot if (pos == dot) { str.append( QLatin1Char('.') ); ++pos; // increment pos, because we just added a '.', and next iteration will add a '0' ++len; } else { assert(pos > dot); str.append( QLatin1Char('0') ); ++len; } assert( pos >= (str.size() - 1) ); } // Leading zeroes: bool hasSign = ( str[0] == QLatin1Char('-') || str[0] == QLatin1Char('+') ); while ( pos < 0 || ( pos == 0 && ( str[0] == QLatin1Char('-') || str[0] == QLatin1Char('+') ) ) ) { // Add leading zero str.insert( hasSign ? 1 : 0, QLatin1Char('0') ); ++pos; ++dot; ++len; } assert( len == str.size() ); assert( 0 <= pos && pos < str.size() && str[pos].isDigit() ); QString noDotStr = str; int noDotLen = len; if (dot != len) { // Remove the dot noDotStr.remove(dot, 1); --noDotLen; } assert( (_imp->type == eSpinBoxTypeInt && noDotLen == dot) || noDotLen >= dot ); double val = oldVal; // The value, as a double if ( (noDotLen > 16) && (16 >= dot) ) { // don't handle more than 16 significant digits (this causes over/underflows in the following) assert( noDotLen == noDotStr.size() ); noDotLen = 16; noDotStr.resize(noDotLen); } qlonglong llval = noDotStr.toLongLong(&ok); // The value, as a long long int if (!ok) { // Not a valid long long value, don't do anything return; } int llpowerOfTen = dot - noDotLen; // llval must be post-multiplied by this power of ten assert(llpowerOfTen <= 0); // check that val and llval*10^llPowerOfTen are close enough (relative error should be less than 1e-8) assert(std::abs(val * std::pow(10., -llpowerOfTen) - llval) / std::max( qlonglong(1), std::abs(llval) ) < 1e-8); // If pos is at the end if ( pos == str.size() ) { switch (_imp->type) { case eSpinBoxTypeDouble: if ( dot == str.size() ) { str += QString::fromUtf8(".0"); len += 2; ++pos; } else { str += QLatin1Char('0'); ++len; } break; case eSpinBoxTypeInt: // take the character before --pos; break; } } // Compute the full value of the increment assert( len == str.size() ); assert(pos != dot); assert( 0 <= pos && pos < len && str[pos].isDigit() ); int powerOfTen = dot - pos - (pos < dot); // the power of ten assert( (_imp->type == eSpinBoxTypeDouble) || ( powerOfTen >= 0 && dot == str.size() ) ); if (powerOfTen - llpowerOfTen > 16) { // too many digits to handle, don't do anything // (may overflow when adjusting llval) return; } double inc = inc_int * std::pow(10., (double)powerOfTen); // Check that we are within the authorized range double maxiD, miniD; switch (_imp->type) { case eSpinBoxTypeInt: maxiD = _imp->maxi.toInt(); miniD = _imp->mini.toInt(); break; case eSpinBoxTypeDouble: default: maxiD = _imp->maxi.toDouble(); miniD = _imp->mini.toDouble(); break; } val += inc; if ( (val < miniD) || (maxiD < val) ) { // out of the authorized range, don't do anything return; } // Adjust llval so that the increment becomes an int, and avoid rounding errors if (powerOfTen >= llpowerOfTen) { llval += inc_int * std::pow(10., powerOfTen - llpowerOfTen); } else { llval *= std::pow(10., llpowerOfTen - powerOfTen); llpowerOfTen -= llpowerOfTen - powerOfTen; llval += inc_int; } // check that val and llval*10^llPowerOfTen are still close enough (relative error should be less than 1e-8) assert(std::abs(val * std::pow(10., -llpowerOfTen) - llval) / std::max( qlonglong(1), std::abs(llval) ) < 1e-8); QString newStr; newStr.setNum(llval); bool newStrHasSign = newStr[0] == QLatin1Char('+') || newStr[0] == QLatin1Char('-'); // the position of the decimal dot int newDot = newStr.size() + llpowerOfTen; // add leading zeroes if newDot is not a valid position (beware of sign!) while ( newDot <= int(newStrHasSign) ) { newStr.insert( int(newStrHasSign), QLatin1Char('0') ); ++newDot; } assert( 0 <= newDot && newDot <= newStr.size() ); assert( newDot == newStr.size() || newStr[newDot].isDigit() ); if ( newDot != newStr.size() ) { assert(_imp->type == eSpinBoxTypeDouble); newStr.insert( newDot, QLatin1Char('.') ); } // Check that the backed string is close to the wanted value (relative error should be less than 1e-8) assert( (newStr.toDouble() - val) / std::max( 1e-8, std::abs(val) ) < 1e-8 ); // The new cursor position int newPos = newDot + (pos - dot); // Remove the shift (may have to be done twice due to the dot) newPos += shift; if (newPos == newDot) { // adjust newPos newPos += shift; } assert( 0 <= newDot && newDot <= newStr.size() ); // Now, add leading and trailing zeroes so that newPos is a valid digit position // (beware of the sign!) // Trailing zeroes: while ( newPos >= newStr.size() ) { assert(_imp->type == eSpinBoxTypeDouble); // Add trailing zero, maybe preceded by a dot if (newPos == newDot) { newStr.append( QLatin1Char('.') ); } else { assert(newPos > newDot); newStr.append( QLatin1Char('0') ); } assert( newPos >= (newStr.size() - 1) ); } // Leading zeroes: bool newHasSign = ( newStr[0] == QLatin1Char('-') || newStr[0] == QLatin1Char('+') ); while ( newPos < 0 || ( newPos == 0 && ( newStr[0] == QLatin1Char('-') || newStr[0] == QLatin1Char('+') ) ) ) { // add leading zero newStr.insert( newHasSign ? 1 : 0, QLatin1Char('0') ); ++newPos; ++newDot; } assert( 0 <= newPos && newPos < newStr.size() && newStr[newPos].isDigit() ); // Set the text and cursor position //qDebug() << "increment setting text to " << newStr; setText(newStr, newPos); // Set the selection assert( newPos + 1 <= newStr.size() ); setSelection(newPos + 1, -1); Q_EMIT valueChanged( value() ); } // increment
void Bdecoder::read(QVariant *data) { if (data == NULL) { switch (m_buf[m_pos]) { case 'd': read(static_cast<QVariantMap *>(NULL)); break; case 'l': read(static_cast<QVariantList *>(NULL)); break; case 'i': read(static_cast<qlonglong *>(NULL)); break; case 'b': read(static_cast<bool *>(NULL)); break; case 's': read(static_cast<QString *>(NULL)); break; case 'k': read(static_cast<BlobKey *>(NULL)); break; default: read(static_cast<QByteArray *>(NULL)); break; } return; } switch (m_buf[m_pos]) { case 'd': { QVariantMap map; read(&map); *data = map; } break; case 'l': { QVariantList list; read(&list); *data = list; } break; case 'i': { /*qlonglong value; read(&value); if (value >= INT_MIN && value <= INT_MAX) *data = int(value); else *data = value;*/ qulonglong value; bool bSigned = false; read(&value, bSigned); if (bSigned && qlonglong(value) >= INT_MIN && qlonglong(value) <= INT_MAX) *data = int(value); else if (qulonglong(value) <= UINT_MAX) *data = quint32(value); else *data = value; } break; case 'b': { bool value; read(&value); *data = value; } break; case 's': { QString string; read(&string); *data = string; } break; case 'k': { BlobKey key; read(&key); *data = QVariant::fromValue(key); } break; default: { QByteArray buf; read(&buf); *data = buf; } break; } }
qlonglong KMainWindowInterface::winId() { return qlonglong(m_MainWindow->winId()); }
void JSettings::setValueLong(JNIEnv*, jclass, jstring jname, jlong value) { JString name(jname); setSettingsValue(name.str(), qlonglong(value)); }
/*! \fn svn::InfoEntry::init(const svn_info_t*) */ void svn::InfoEntry::init(const svn_info_t*item,const QString&path) { if (!item) { init(); return; } m_name = path; m_last_changed_date=item->last_changed_date; m_text_time = item->text_time; m_prop_time = item->prop_time; if (item->lock) { m_Lock.init(item->lock); } else { m_Lock = LockEntry(); } m_checksum = QString::fromUtf8(item->checksum); m_conflict_new = QString::fromUtf8(item->conflict_new); m_conflict_old = QString::fromUtf8(item->conflict_old); m_conflict_wrk = QString::fromUtf8(item->conflict_wrk); m_copyfrom_url = QString::fromUtf8(item->copyfrom_url); m_last_author = QString::fromUtf8(item->last_changed_author); m_prejfile = QString::fromUtf8(item->prejfile); m_repos_root = QString::fromUtf8(item->repos_root_URL); m_url = QString::fromUtf8(item->URL); m_pUrl = prettyUrl(item->URL); m_UUID = QString::fromUtf8(item->repos_UUID); m_kind = item->kind; m_copy_from_rev = item->copyfrom_rev; m_last_changed_rev = item->last_changed_rev; m_revision = item->rev; m_hasWc = item->has_wc_info; m_schedule = item->schedule; #if ((SVN_VER_MAJOR == 1) && (SVN_VER_MINOR >= 6)) || (SVN_VER_MAJOR > 1) m_size = item->size64!=SVN_INVALID_FILESIZE?qlonglong(item->size64):SVNQT_SIZE_UNKNOWN; m_working_size = item->working_size64!=SVN_INVALID_FILESIZE?qlonglong(item->working_size64):SVNQT_SIZE_UNKNOWN; if (m_working_size == SVNQT_SIZE_UNKNOWN) { m_working_size = item->working_size!=SVN_INFO_SIZE_UNKNOWN?qlonglong(item->working_size):SVNQT_SIZE_UNKNOWN; } #elif (SVN_VER_MINOR == 5) m_size = item->size!=SVN_INFO_SIZE_UNKNOWN?qlonglong(item->size):SVNQT_SIZE_UNKNOWN; m_working_size = item->working_size!=SVN_INFO_SIZE_UNKNOWN?qlonglong(item->working_size):SVNQT_SIZE_UNKNOWN; #endif #if ((SVN_VER_MAJOR == 1) && (SVN_VER_MINOR >= 5)) || (SVN_VER_MAJOR > 1) if (item->changelist) { m_changeList = QByteArray(item->changelist,strlen(item->changelist)); } else { m_changeList=QByteArray(); } switch (item->depth) { case svn_depth_exclude: m_depth=DepthExclude; break; case svn_depth_empty: m_depth=DepthEmpty; break; case svn_depth_files: m_depth=DepthFiles; break; case svn_depth_immediates: m_depth=DepthImmediates; break; case svn_depth_infinity: m_depth=DepthInfinity; break; case svn_depth_unknown: default: m_depth=DepthUnknown; break; } #else m_size = SVNQT_SIZE_UNKNOWN; m_working_size = SVNQT_SIZE_UNKNOWN; m_changeList=QByteArray(); m_depth = DepthUnknown; #endif }
/** * \sa format() * \sa setFormat(const QString&) */ QString AbstractStringAppender::formattedString(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, const char* function, const QString& category, const QString& message) const { QString f = format(); const int size = f.size(); QString result; int i = 0; while (i < f.size()) { QChar c = f.at(i); // We will silently ignore the broken % marker at the end of string if (c != QLatin1Char(formattingMarker) || (i + 2) >= size) { result.append(c); } else { i += 2; QChar currentChar = f.at(i); QString command; int fieldWidth = 0; if (currentChar.isLetter()) { command.append(currentChar); int j = 1; while ((i + j) < size && f.at(i + j).isLetter()) { command.append(f.at(i+j)); j++; } i+=j; currentChar = f.at(i); // Check for the padding instruction if (currentChar == QLatin1Char(':')) { currentChar = f.at(++i); if (currentChar.isDigit() || currentChar.category() == QChar::Punctuation_Dash) { int j = 1; while ((i + j) < size && f.at(i + j).isDigit()) j++; fieldWidth = f.mid(i, j).toInt(); i += j; } } } // Log record chunk to insert instead of formatting instruction QString chunk; // Time stamp if (command == QLatin1String("time")) { if (f.at(i + 1) == QLatin1Char('{')) { int j = 1; while ((i + 2 + j) < size && f.at(i + 2 + j) != QLatin1Char('}')) j++; if ((i + 2 + j) < size) { chunk = timeStamp.toString(f.mid(i + 2, j)); i += j; i += 2; } } if (chunk.isNull()) chunk = timeStamp.toString(QLatin1String("HH:mm:ss.zzz")); } // Log level else if (command == QLatin1String("type")) chunk = Logger::levelToString(logLevel); // Uppercased log level else if (command == QLatin1String("Type")) chunk = Logger::levelToString(logLevel).toUpper(); // One letter log level else if (command == QLatin1String("typeOne")) chunk = Logger::levelToString(logLevel).left(1).toLower(); // One uppercase letter log level else if (command == QLatin1String("TypeOne")) chunk = Logger::levelToString(logLevel).left(1).toUpper(); // Filename else if (command == QLatin1String("File")) chunk = QLatin1String(file); // Filename without a path else if (command == QLatin1String("file")) chunk = QString(QLatin1String(file)).section('/', -1); // Source line number else if (command == QLatin1String("line")) chunk = QString::number(line); // Function name, as returned by Q_FUNC_INFO else if (command == QLatin1String("Function")) chunk = QString::fromLatin1(function); // Stripped function name else if (command == QLatin1String("function")) chunk = stripFunctionName(function); // Log message else if (command == QLatin1String("message")) chunk = message; else if (command == QLatin1String("category")) chunk = category; // Application pid else if (command == QLatin1String("pid")) chunk = QString::number(QCoreApplication::applicationPid()); // Appplication name else if (command == QLatin1String("appname")) chunk = QCoreApplication::applicationName(); // Thread ID (duplicates Qt5 threadid debbuging way) else if (command == QLatin1String("threadid")) chunk = QLatin1String("0x") + QString::number(qlonglong(QThread::currentThread()->currentThread()), 16); // We simply replace the double formatting marker (%) with one else if (command == QString(formattingMarker)) chunk = QLatin1Char(formattingMarker); // Do not process any unknown commands else { chunk = QString(formattingMarker); chunk.append(command); } result.append(QString(QLatin1String("%1")).arg(chunk, fieldWidth)); } ++i; } return result; }
inline static int F16Dot16FixedDiv(int x, int y) { if (qAbs(x) > 0x7fff) return qlonglong(x) * (1<<16) / y; return x * (1<<16) / y; }