Пример #1
0
/*!
    \since 5.10

    Returns the file time specified by \a time. If the time cannot be
    determined, an invalid date time is returned.

    \sa QFile::FileTime, QDateTime::isValid()
*/
QDateTime QFileInfo::fileTime(QFile::FileTime time) const
{
    Q_STATIC_ASSERT(int(QFile::FileAccessTime) == int(QAbstractFileEngine::AccessTime));
    Q_STATIC_ASSERT(int(QFile::FileBirthTime) == int(QAbstractFileEngine::BirthTime));
    Q_STATIC_ASSERT(int(QFile::FileMetadataChangeTime) == int(QAbstractFileEngine::MetadataChangeTime));
    Q_STATIC_ASSERT(int(QFile::FileModificationTime) == int(QAbstractFileEngine::ModificationTime));

    Q_D(const QFileInfo);
    auto fetime = QAbstractFileEngine::FileTime(time);
    QFileSystemMetaData::MetaDataFlags flag;
    switch (time) {
    case QFile::FileAccessTime:
        flag = QFileSystemMetaData::AccessTime;
        break;
    case QFile::FileBirthTime:
        flag = QFileSystemMetaData::BirthTime;
        break;
    case QFile::FileMetadataChangeTime:
        flag = QFileSystemMetaData::MetadataChangeTime;
        break;
    case QFile::FileModificationTime:
        flag = QFileSystemMetaData::ModificationTime;
        break;
    }

    return d->checkAttribute<QDateTime>(
                flag,
                [=]() { return d->metaData.fileTime(fetime).toLocalTime(); },
                [=]() { return d->getFileTime(fetime).toLocalTime(); });
}
Пример #2
0
void tst_QAtomicIntegerXX::static_checks()
{
    Q_STATIC_ASSERT(sizeof(QAtomicInteger<T>) == sizeof(T));
    Q_STATIC_ASSERT(Q_ALIGNOF(QAtomicInteger<T>) == Q_ALIGNOF(TypeInStruct));

    // statements with no effect
    (void) QAtomicInteger<T>::isReferenceCountingNative();
    (void) QAtomicInteger<T>::isReferenceCountingWaitFree();
    (void) QAtomicInteger<T>::isTestAndSetNative();
    (void) QAtomicInteger<T>::isTestAndSetWaitFree();
    (void) QAtomicInteger<T>::isFetchAndStoreNative();
    (void) QAtomicInteger<T>::isFetchAndStoreWaitFree();
    (void) QAtomicInteger<T>::isFetchAndAddNative();
    (void) QAtomicInteger<T>::isFetchAndAddWaitFree();

#ifdef Q_COMPILER_CONSTEXPR
    // this is a compile-time test only
    booleanHelper<QAtomicInteger<T>::isReferenceCountingNative()>();
    booleanHelper<QAtomicInteger<T>::isReferenceCountingWaitFree()>();
    booleanHelper<QAtomicInteger<T>::isTestAndSetNative()>();
    booleanHelper<QAtomicInteger<T>::isTestAndSetWaitFree()>();
    booleanHelper<QAtomicInteger<T>::isFetchAndStoreNative()>();
    booleanHelper<QAtomicInteger<T>::isFetchAndStoreWaitFree()>();
    booleanHelper<QAtomicInteger<T>::isFetchAndAddNative()>();
    booleanHelper<QAtomicInteger<T>::isFetchAndAddWaitFree()>();
#endif
}
Пример #3
0
void tst_QFlags::signedness()
{
    // these are all 'true' on GCC, but since the std says the
    // underlying type is implementation-defined, we need to allow for
    // a different signedness, so we only check that the relative
    // signedness of the types matches:
    Q_STATIC_ASSERT((QtPrivate::is_unsigned<Qt::MouseButton>::value ==
                     QtPrivate::is_unsigned<Qt::MouseButtons::Int>::value));

    Q_STATIC_ASSERT((QtPrivate::is_signed<Qt::AlignmentFlag>::value ==
                     QtPrivate::is_signed<Qt::Alignment::Int>::value));
}
Пример #4
0
void tst_QHashFunctions::range()
{
    static const int ints[] = {0, 1, 2, 3, 4, 5};
    static const size_t numInts = sizeof ints / sizeof *ints;

    // empty range just gives the seed:
    QCOMPARE(qHashRange(ints, ints, 0xdeadbeefU), 0xdeadbeefU);
    // verify that order matters:
    QVERIFY(qHashRange(ints, ints + numInts) !=
            qHashRange(std::reverse_iterator<const int*>(ints + numInts), std::reverse_iterator<const int*>(ints)));

    {
        // verify that the input iterator category suffices:
        std::stringstream sstream;
        Q_STATIC_ASSERT((QtPrivate::is_same<std::input_iterator_tag, std::istream_iterator<int>::iterator_category>::value));
        std::copy(ints, ints + numInts, std::ostream_iterator<int>(sstream, " "));
        sstream.seekg(0);
        std::istream_iterator<int> it(sstream), end;
        QCOMPARE(qHashRange(ints, ints + numInts), qHashRange(it, end));
    }

    SomeNamespace::Hashable hashables[] = {{0}, {1}, {2}, {3}, {4}, {5}};
    static const size_t numHashables = sizeof hashables / sizeof *hashables;
    // compile check: is qHash() found using ADL?
    (void)qHashRange(hashables, hashables + numHashables);
}
Пример #5
0
static int checkFutexPrivateSupport()
{
    int value = 0;
#if defined(FUTEX_PRIVATE_FLAG)
    // check if the kernel supports extra futex flags
    // FUTEX_PRIVATE_FLAG appeared in v2.6.22
    Q_STATIC_ASSERT(FUTEX_PRIVATE_FLAG != 0x80000000);

    // try an operation that has no side-effects: wake up 42 threads
    // futex will return -1 (errno==ENOSYS) if the flag isn't supported
    // there should be no other error conditions
    value = syscall(__NR_futex, &futexFlagSupport,
                    FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
                    42, 0, 0, 0);
    if (value != -1)
        value = FUTEX_PRIVATE_FLAG;
    else
        value = 0;

#else
    value = 0;
#endif
    futexFlagSupport.store(value);
    return value;
}
Пример #6
0
int main(int argc, char *argv[])
    {
    //set global names
    QApplication::setOrganizationName   (QLatin1Literal("Advance"));
    QApplication::setApplicationName    (QLatin1Literal("Timer"));
    QApplication::setApplicationVersion (QLatin1Literal("0.1"));
    QApplication::setOrganizationDomain (QLatin1Literal("http://www.advance-club.ru/"));
    qDebug() << QApplication::applicationName() + QLatin1Literal(" starts.");

    QApplication app(argc, argv);
#ifdef Q_OS_WIN
    QApplication::addLibraryPath(QLatin1Literal("plugins"));
#elif defined Q_OS_MAC
    QDir dir(QApplication::applicationDirPath());
    dir.cdUp();
    dir.cd("Plugins");
    QApplication::addLibraryPath(dir.absolutePath());
#else
    Q_STATIC_ASSERT("not implemented for this platform");
#endif
    app.setWindowIcon(QIcon(":/icon.ico"));
    QTranslator ru_translation;
    if(!ru_translation.load("Timer_ru", ":/"))
        qWarning() << "no ru transaltion";
    app.installTranslator(&ru_translation);
    TimerMainWindow w;
    w.showMaximized ();
    return app.exec();
    }
Пример #7
0
/*!
    Returns the number of representable floating-point numbers between \a a and \a b.

    This function serves the same purpose as \c{qFloatDistance(float, float)}, but
    returns the distance between two \c double numbers. Since the range is larger
    than for two \c float numbers (\c{[-DBL_MAX,DBL_MAX]}), the return type is quint64.


    \sa qFuzzyCompare()
    \since 5.2
    \relates <QtGlobal>
*/
Q_CORE_EXPORT quint64 qFloatDistance(double a, double b)
{
    static const quint64 smallestPositiveFloatAsBits = 0x1;  // denormalized, (SMALLEST)
    /* Assumes:
       * IEE754 format double precision
       * Integers and floats have the same endian
    */
    Q_STATIC_ASSERT(sizeof(quint64) == sizeof(double));
    Q_ASSERT(qIsFinite(a) && qIsFinite(b));
    if (a == b)
        return 0;
    if ((a < 0) != (b < 0)) {
        // if they have different signs
        if (a < 0)
            a = -a;
        else /*if (b < 0)*/
            b = -b;
        return qFloatDistance(0.0, a) + qFloatDistance(0.0, b);
    }
    if (a < 0) {
        a = -a;
        b = -b;
    }
    // at this point a and b should not be negative

    // 0 is special
    if (!a)
        return d2i(b) - smallestPositiveFloatAsBits + 1;
    if (!b)
        return d2i(a) - smallestPositiveFloatAsBits + 1;

    // finally do the common integer subtraction
    return a > b ? d2i(a) - d2i(b) : d2i(b) - d2i(a);
}
Пример #8
0
/*!
    Returns the number of representable floating-point numbers between \a a and \a b.

    This function provides an alternative way of doing approximated comparisons of floating-point
    numbers similar to qFuzzyCompare(). However, it returns the distance between two numbers, which
    gives the caller a possibility to choose the accepted error. Errors are relative, so for
    instance the distance between 1.0E-5 and 1.00001E-5 will give 110, while the distance between
    1.0E36 and 1.00001E36 will give 127.

    This function is useful if a floating point comparison requires a certain precision.
    Therefore, if \a a and \a b are equal it will return 0. The maximum value it will return for 32-bit
    floating point numbers is 4,278,190,078. This is the distance between \c{-FLT_MAX} and
    \c{+FLT_MAX}.

    The function does not give meaningful results if any of the arguments are \c Infinite or \c NaN.
    You can check for this by calling qIsFinite().

    The return value can be considered as the "error", so if you for instance want to compare
    two 32-bit floating point numbers and all you need is an approximated 24-bit precision, you can
    use this function like this:

    \code
    if (qFloatDistance(a, b) < (1 << 7)) {   // The last 7 bits are not
                                            // significant
        // precise enough
    }
    \endcode

    \sa qFuzzyCompare()
    \since 5.2
    \relates <QtGlobal>
*/
Q_CORE_EXPORT quint32 qFloatDistance(float a, float b)
{
    static const quint32 smallestPositiveFloatAsBits = 0x00000001;  // denormalized, (SMALLEST), (1.4E-45)
    /* Assumes:
       * IEE754 format.
       * Integers and floats have the same endian
    */
    Q_STATIC_ASSERT(sizeof(quint32) == sizeof(float));
    Q_ASSERT(qIsFinite(a) && qIsFinite(b));
    if (a == b)
        return 0;
    if ((a < 0) != (b < 0)) {
        // if they have different signs
        if (a < 0)
            a = -a;
        else /*if (b < 0)*/
            b = -b;
        return qFloatDistance(0.0F, a) + qFloatDistance(0.0F, b);
    }
    if (a < 0) {
        a = -a;
        b = -b;
    }
    // at this point a and b should not be negative

    // 0 is special
    if (!a)
        return f2i(b) - smallestPositiveFloatAsBits + 1;
    if (!b)
        return f2i(a) - smallestPositiveFloatAsBits + 1;

    // finally do the common integer subtraction
    return a > b ? f2i(a) - f2i(b) : f2i(b) - f2i(a);
}
SixPointCalibrationModel::SixPointCalibrationModel(QObject *parent) :
    QObject(parent),
    calibratingMag(false),
    calibratingAuxMag(false),
    calibratingAccel(false),
    calibrationStepsMag(),
    calibrationStepsAccelOnly(),
    currentSteps(0),
    position(-1),
    collectingData(false),
    m_dirty(false)
{
    calibrationStepsMag.clear();
    calibrationStepsMag
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_NED,
                           tr("Place horizontally, nose pointing north and press Save Position..."))
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_DWN,
                       tr("Place with nose down, right side west and press Save Position..."))
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_WDS,
                       tr("Place right side down, nose west and press Save Position..."))
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_ENU,
                       tr("Place upside down, nose east and press Save Position..."))
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_USE,
                       tr("Place with nose up, left side north and press Save Position..."))
        << CalibrationStep(CALIBRATION_HELPER_IMAGE_SUW,
                       tr("Place with left side down, nose south and press Save Position..."));

    // All mag calibration matrices have the same structure, this is also used when calculating bias/transforms
    // this is enforced using assert.
    Q_STATIC_ASSERT((int)RevoCalibration::MAG_TRANSFORM_R0C0 == (int)AuxMagSettings::MAG_TRANSFORM_R0C0 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R1C0 == (int)AuxMagSettings::MAG_TRANSFORM_R1C0 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R2C0 == (int)AuxMagSettings::MAG_TRANSFORM_R2C0 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R0C1 == (int)AuxMagSettings::MAG_TRANSFORM_R0C1 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R1C1 == (int)AuxMagSettings::MAG_TRANSFORM_R1C1 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R2C1 == (int)AuxMagSettings::MAG_TRANSFORM_R2C1 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R0C2 == (int)AuxMagSettings::MAG_TRANSFORM_R0C2 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R1C2 == (int)AuxMagSettings::MAG_TRANSFORM_R1C2 &&
                    (int)RevoCalibration::MAG_TRANSFORM_R2C2 == (int)AuxMagSettings::MAG_TRANSFORM_R2C2 &&
                    (int)RevoCalibration::MAG_BIAS_X == (int)AuxMagSettings::MAG_BIAS_X &&
                    (int)RevoCalibration::MAG_BIAS_Y == (int)AuxMagSettings::MAG_BIAS_Y &&
                    (int)RevoCalibration::MAG_BIAS_Z == (int)AuxMagSettings::MAG_BIAS_Z);

    calibrationStepsAccelOnly.clear();
    calibrationStepsAccelOnly << CalibrationStep(CALIBRATION_HELPER_IMAGE_NED,
                                                 tr("Place horizontally and press Save Position..."))
                              << CalibrationStep(CALIBRATION_HELPER_IMAGE_DWN,
                       tr("Place with nose down and press Save Position..."))
                              << CalibrationStep(CALIBRATION_HELPER_IMAGE_WDS,
                       tr("Place right side down and press Save Position..."))
                              << CalibrationStep(CALIBRATION_HELPER_IMAGE_ENU,
                       tr("Place upside down and press Save Position..."))
                              << CalibrationStep(CALIBRATION_HELPER_IMAGE_USE,
                       tr("Place with nose up and press Save Position..."))
                              << CalibrationStep(CALIBRATION_HELPER_IMAGE_SUW,
                       tr("Place with left side down and press Save Position..."));

    revoCalibration   = RevoCalibration::GetInstance(getObjectManager());
    Q_ASSERT(revoCalibration);

    auxMagSettings    = AuxMagSettings::GetInstance(getObjectManager());
    Q_ASSERT(auxMagSettings);

    accelGyroSettings = AccelGyroSettings::GetInstance(getObjectManager());
    Q_ASSERT(accelGyroSettings);

    accelState   = AccelState::GetInstance(getObjectManager());
    Q_ASSERT(accelState);

    magSensor    = MagSensor::GetInstance(getObjectManager());
    Q_ASSERT(magSensor);

    auxMagSensor = AuxMagSensor::GetInstance(getObjectManager());
    Q_ASSERT(auxMagSensor);

    homeLocation = HomeLocation::GetInstance(getObjectManager());
    Q_ASSERT(homeLocation);
}