Пример #1
0
void MainWindow::setContextSMS()
{
    QDateTime dateTime;
    QString nullStr = "";

    smsTxt = "";
    //if(this->ui->smsTab->currentTabText EQ )
    int index = this->ui->smsTab->currentIndex();
    if(index EQ SET_SMS_INDEX)
    {
        smsTxt += "#@";
        smsTxt += num2str(this->ui->spinBox->value(), 2) + "0";

        smsTxt.append(index2asc(ui->comboBox->currentIndex())); //进入特效
        smsTxt.append(index2asc(ui->comboBox_2->currentIndex())); //退出特效
        smsTxt.append(index2asc(ui->comboBox_4->currentIndex())); //特效速度

        int stayTime = ui->spinBox_5->value();

        if(stayTime < 10)
            smsTxt.append(index2asc(stayTime)); //停留时间
        else if(stayTime < 10 + 26 * 5)
            smsTxt.append((stayTime - 10) / 5 + 'a');
        else if(stayTime < 140 + 26 * 5)
            smsTxt.append((stayTime - 140) / 5 + 'A');
        else
            smsTxt.append("10");

        smsTxt.append(index2asc(ui->comboBox_5->currentIndex())); //字体大小
        smsTxt.append(index2asc(ui->comboBox_7->currentIndex() + 1)); //颜色
        smsTxt.append(borderIndex2asc(ui->comboBox_3->currentIndex())); //边框特效

        smsTxt.append('+'); //颜色

        if(ui->textEdit_2->toPlainText().size() EQ 0)
        {
            nullStr = tr("(注意:显示内容为空)");
            //QMessageBox::information(0, QObject::tr("提示"),QObject::tr("增加的显示内容为空!"));
        }
        smsTxt.append(ui->textEdit_2->toPlainText()); //颜色
    }
    else if(index EQ ADD_SMS_INDEX) //追加短信
    {
        smsTxt += "#@";
        smsTxt += num2str(this->ui->spinBox_2->value(), 2);// + "0";
        smsTxt += num2str(this->ui->comboBox_8->currentIndex() + 1, 1);

        smsTxt.append('+'); //颜色
        if(ui->textEdit_3->toPlainText().size() EQ 0)
        {
            nullStr = tr("(注意:显示内容为空)");
            //QMessageBox::information(0, QObject::tr("提示"),QObject::tr("追加的显示内容为空!"));
        }
        smsTxt.append(ui->textEdit_3->toPlainText()); //颜色
    }
    else if(index EQ DEL_SMS_INDEX) //删除短信
    {
        smsTxt += "#DEL";
        smsTxt += num2str(this->ui->spinBox_3->value(), 2);// + "0";
    }
    else if(index EQ RD_SMS_IDEX) //读取短信内容
    {
        smsTxt += "?@";
        smsTxt += num2str(this->ui->spinBox_4->value(), 2);// + "0";

        if(ui->groupBox->isChecked())
          smsTxt += num2str(this->ui->comboBox_6->currentIndex() + 1, 1);
        else
          smsTxt += '0';
    }
    else if(index EQ ADJ_TIME_INDEX) //校准时间
    {
        //CadjTimeProperty::getDateTime()

        if(ui->radioButton->isChecked())
        {
          dateTime = QDateTime::currentDateTime();
        }
        else
        {
          dateTime = ui->dateTimeEdit->dateTime();
        }

        smsTxt += "#TIM";
        smsTxt.append(num2str(dateTime.date().year() - 2000, 2));
        smsTxt.append(num2str(dateTime.date().month(), 2));
        smsTxt.append(num2str(dateTime.date().day(), 2));
        smsTxt.append(num2str(dateTime.time().hour(), 2));
        smsTxt.append(num2str(dateTime.time().minute(), 2));
        smsTxt.append(num2str(dateTime.time().second(), 2));

        int week = dateTime.date().dayOfWeek();
        if(week EQ 7)
            week = 0;

        smsTxt.append(num2str(week, 1));
    }
    else if(index EQ CALL_SMS_INDEX)
    {
        smsTxt += "#@";
        smsTxt += num2str(this->ui->spinBox_6->value(), 2) + "!";
        smsTxt += num2str(this->ui->spinBox_7->value(), 2);
    }
    else if(index EQ ADD_PHN_INDEX) //增加过滤号码
    {
        smsTxt += "#MPN";
        smsTxt += num2str(this->ui->comboBox_11->currentIndex() + 1, 1);
        smsTxt += this->ui->lineEdit_2->text();
    }
    else if(index EQ DEL_PHN_INDEX) //删除过滤号码
    {
        smsTxt += "#MPN0";
        smsTxt += num2str(this->ui->comboBox_12->currentIndex(), 1);
    }
    else if(index EQ SET_SCREEN_PARA_INDEX) //设置屏幕参数
    {
        smsTxt += "#SCN";
        smsTxt += num2str(this->ui->spinBox_8->value(), 4);
        smsTxt += "X";
        smsTxt += num2str(this->ui->spinBox_9->value(), 3);
        smsTxt += ",";
        smsTxt += num2str(this->ui->comboBox_9->currentIndex() + 1, 1);
        smsTxt += num2str(this->ui->comboBox_10->currentIndex(), 1);
        smsTxt += num2str(this->ui->comboBox_13->currentIndex(), 1);
        smsTxt += ",";

        if(this->ui->comboBox_14->currentIndex() EQ 0)
            smsTxt +="0200";
        else if(this->ui->comboBox_14->currentIndex() EQ 1)
            smsTxt += "2213";
        else
            smsTxt += "1200";

    }
    else if(index EQ RD_OTHER_PARA_INDEX) //读取其他参数
    {
        if(ui->radioButton_3->isChecked())
        {
            smsTxt += "?MPN";
            nullStr = tr("(过滤号码)");
        }
        else if(ui->radioButton_4->isChecked())
        {
            smsTxt += "?SCN";
            nullStr = tr("(屏幕参数)");
        }
        else if(ui->radioButton_5->isChecked())
        {
            smsTxt += "?VER";
            nullStr = tr("(固件版本)");
        }
    }
    else
        return;


    //dateTime = currentDateTime();
    //dateTime.toString()
    if(smsTxt.size() > 70)
        smsTxt.truncate(70);

    if(ui->action->isChecked() EQ false)
      ;//ui->textEdit->setText(this->ui->smsTab->tabText(index) + nullStr + ":" + smsTxt);
    else
    {
        if(smsTxt.at(0) EQ '#')
            smsTxt.replace(0, 1, "*");
    }

    ui->textEdit->setText(this->ui->smsTab->tabText(index) + nullStr + ":" + smsTxt);

}
void RollingFileAppender::computeRollOverTime()
{
  Q_ASSERT_X(!m_datePatternString.isEmpty(), "DailyRollingFileAppender::computeRollOverTime()", "No active date pattern");

  QDateTime now = QDateTime::currentDateTime();
  QDate nowDate = now.date();
  QTime nowTime = now.time();
  QDateTime start;

  switch (m_frequency)
  {
    case MinutelyRollover:
    {
      start = QDateTime(nowDate, QTime(nowTime.hour(), nowTime.minute(), 0, 0));
      m_rollOverTime = start.addSecs(60);
    }
    break;
    case HourlyRollover:
    {
      start = QDateTime(nowDate, QTime(nowTime.hour(), 0, 0, 0));
      m_rollOverTime = start.addSecs(60*60);
    }
    break;
    case HalfDailyRollover:
    {
      int hour = nowTime.hour();
      if (hour >=  12)
        hour = 12;
      else
        hour = 0;
      start = QDateTime(nowDate, QTime(hour, 0, 0, 0));
      m_rollOverTime = start.addSecs(60*60*12);
    }
    break;
    case DailyRollover:
    {
      start = QDateTime(nowDate, QTime(0, 0, 0, 0));
      m_rollOverTime = start.addDays(1);
    }
    break;
    case WeeklyRollover:
    {
      // Qt numbers the week days 1..7. The week starts on Monday.
      // Change it to being numbered 0..6, starting with Sunday.
      int day = nowDate.dayOfWeek();
      if (day == Qt::Sunday)
        day = 0;
      start = QDateTime(nowDate, QTime(0, 0, 0, 0)).addDays(-1 * day);
      m_rollOverTime = start.addDays(7);
    }
    break;
    case MonthlyRollover:
    {
      start = QDateTime(QDate(nowDate.year(), nowDate.month(), 1), QTime(0, 0, 0, 0));
      m_rollOverTime = start.addMonths(1);
    }
    break;
    default:
      Q_ASSERT_X(false, "DailyRollingFileAppender::computeInterval()", "Invalid datePattern constant");
      m_rollOverTime = QDateTime::fromTime_t(0);
  }

  m_rollOverSuffix = start.toString(m_datePatternString);
  Q_ASSERT_X(now.toString(m_datePatternString) == m_rollOverSuffix,
      "DailyRollingFileAppender::computeRollOverTime()", "File name changes within interval");
  Q_ASSERT_X(m_rollOverSuffix != m_rollOverTime.toString(m_datePatternString),
      "DailyRollingFileAppender::computeRollOverTime()", "File name does not change with rollover");
}
Пример #3
0
TodoEditDialog::TodoEditDialog(QWidget *parent, CTodo *todo) :
    ComponentEditDialog(parent),
    ui(new Ui::TodoEditDialog),
    saveDue(true)
{
    ui->setupUi(this);

    if (todo && !todo->getId().empty()) {
        todo = CWrapper::details(todo);

        this->setWindowTitle(tr("Edit task"));
        this->setupDeleteButton(ui->buttonBox, SLOT(deleteTodo()));
    } else {
        this->setWindowTitle(tr("New task"));
    }

    QSettings settings;

    // Set up date picker
    DatePickSelector *dps = new DatePickSelector();
    ui->dateButton->setPickSelector(dps);

    // Set up time zone picker
    ZonePickSelector *zps;
    if (settings.value("TimeZones", false).toBool()) {
        zps = new ZonePickSelector();
        ui->zoneButton->setPickSelector(zps);
    } else {
        zps = NULL;
        ui->zoneButton->hide();
    }

    // Set up calendar picker
    CalendarPickSelector *cps = new CalendarPickSelector();
    ui->calendarButton->setPickSelector(cps);

    // Set up alarm picker
    AlarmPickSelector *aps = new AlarmPickSelector(E_AM_EXACTDATETIME);
    ui->alarmButton->setPickSelector(aps);

    // Make sure that AlarmPickSelector's reference date is set
    onDateChanged();

    connect(dps, SIGNAL(selected(QString)), this, SLOT(onDateChanged()));

    if (todo) {
        // Do not change the default settings when editing an existing todo
        saveDefaults = false;

        // Configure time
        QString zone;
        QDateTime due;
        if (zps) {
            // Display time in the selected time zone
            zone = todo->getTzid().c_str();
            due = Date::toRemote(todo->getDue(), zone);
            zps->setCurrentZone(todo->getTzid().c_str());
        } else {
            // Display local time
            due = QDateTime::fromTime_t(todo->getDue());
        }

        ui->summaryEdit->setText(QString::fromUtf8(todo->getSummary().c_str()));
        ui->descriptionEdit->setPlainText(QString::fromUtf8(todo->getDescription().c_str()));
        ui->doneBox->setChecked(todo->getStatus());
        dps->setCurrentDate(due.date());
        cps->setCalendar(todo->getCalendarId());
        aps->setAlarm(todo->getAlarm(), zone);
    } else {
        todo = new CTodo();

        saveDefaults = true;

        // Load last used settings
        settings.beginGroup("TodoEditDialog");
        cps->setCalendar(settings.value("Calendar", 1).toInt());
        aps->setSecondsBefore(settings.value("Alarm", -1).toInt());

        // Prepre to calculate the due date
        const time_t dueOffset = settings.value("DueOffset", 0).toInt() * 24*60*60;
        time_t currentStamp = QDateTime::currentDateTime().toTime_t();
        QDateTime due;

        // Some additional processing for time zones
        if (zps) {
            const QString zone = settings.value("TimeZone", QString()).toString();
            if (!zone.isEmpty()) {
                // Display time in the selected time zone
                currentStamp = Date::toRemote(currentStamp, zone).toTime_t();

                // Load last used setting
                zps->setCurrentZone(zone);
            }
        }

        // Calculate the due date in an under/overflow-proof way
        if (dueOffset > 0) {
            due = QDateTime::fromTime_t(currentStamp > std::numeric_limits<time_t>::max() - dueOffset
                                      ? std::numeric_limits<time_t>::max()
                                      : currentStamp + dueOffset);
        } else {
            due = QDateTime::fromTime_t(currentStamp < -dueOffset
                                      ? 0
                                      : currentStamp + dueOffset);
        }
        dps->setCurrentDate(due.date());

        ui->doneBox->hide();

        ui->summaryEdit->setFocus();
    }

    this->setupSaveButton(ui->buttonBox, SLOT(saveTodo()));

    ui->editArea->widget()->layout()->activate();

    this->setFeatures(ui->dialogLayout, ui->buttonBox);

    this->todo = todo;
}
static QwtScaleDiv qwtDivideToYears(
    const QDateTime &minDate, const QDateTime &maxDate,
    double stepSize, int maxMinSteps )
{
    QList<double> majorTicks;
    QList<double> mediumTicks;
    QList<double> minorTicks;

    double minStepSize = 0.0;

    if ( maxMinSteps > 1 )
    {
        minStepSize = qwtDivideMajorStep(
            stepSize, maxMinSteps, QwtDate::Year );
    }

    int numMinorSteps = 0;
    if ( minStepSize > 0.0 )
        numMinorSteps = qwtFloor( stepSize / minStepSize );

    bool dateBC = minDate.date().year() < -1;

    for ( QDateTime dt = minDate; dt <= maxDate;
        dt = dt.addYears( stepSize ) )
    {
        if ( dateBC && dt.date().year() > 1 )
        {
            // there is no year 0 in the Julian calendar
            dt = dt.addYears( -1 );
            dateBC = false;
        }

        if ( !dt.isValid() )
            break;

        majorTicks += QwtDate::toDouble( dt );

        for ( int i = 1; i < numMinorSteps; i++ )
        {
            QDateTime tickDate;

            const double years = qRound( i * minStepSize );
            if ( years >= std::numeric_limits<int>::max() / 12 )
            {
                tickDate = dt.addYears( years );
            }
            else
            {
                tickDate = dt.addMonths( qRound( years * 12 ) );
            }

            const bool isMedium = ( numMinorSteps > 2 ) &&
                ( numMinorSteps % 2 == 0 ) && ( i == numMinorSteps / 2 );

            const double minorValue = QwtDate::toDouble( tickDate );
            if ( isMedium )
                mediumTicks += minorValue;
            else
                minorTicks += minorValue;
        }

        if ( QwtDate::maxDate().addYears( -stepSize ) < dt.date() )
        {
            break;
        }
    }

    QwtScaleDiv scaleDiv;
    scaleDiv.setInterval( QwtDate::toDouble( minDate ),
        QwtDate::toDouble( maxDate ) );

    scaleDiv.setTicks( QwtScaleDiv::MajorTick, majorTicks );
    scaleDiv.setTicks( QwtScaleDiv::MediumTick, mediumTicks );
    scaleDiv.setTicks( QwtScaleDiv::MinorTick, minorTicks );

    return scaleDiv;
}
Пример #5
0
void MainWindow::setSunRiseAndSetVectors(const QDateTime &dateTime)
{
    struct ln_equ_posn equ;
    struct ln_rst_time rst;
    struct ln_zonedate rise, set, transit;
    struct ln_lnlat_posn observer;

    struct ln_hrz_posn hpos;

    double JD;

    observer.lat = ui->latEdit->text().toFloat();
    observer.lng = ui->lngEdit->text().toFloat();

    ln_date date;
    date.years = dateTime.date().year();
    date.months = dateTime.date().month();
    date.days = dateTime.date().day();
    date.hours = dateTime.time().hour();
    date.minutes = dateTime.time().minute();
    date.seconds = dateTime.time().second();

    JD = ln_get_julian_day(&date);

    /* ra, dec */
    ln_get_solar_equ_coords (JD, &equ);


    ln_get_hrz_from_equ(&equ, &observer, JD, &hpos);

    double a = ln_range_degrees(hpos.az - 180);

    QString s;
    s.sprintf("Azimut: %0.3f", a);
    ui->listWidget->addItem(s);
    s.sprintf("Evaluation: %0.3f", hpos.alt);
    ui->listWidget->addItem(s);

    /* rise, set and transit */
    if (ln_get_solar_rst (JD, &observer, &rst) == 1) {
        ui->listWidget->addItem(QString("Zirkumpolar"));
    } else {
        ln_get_local_date (rst.rise, &rise);
        ln_get_local_date (rst.transit, &transit);
        ln_get_local_date (rst.set, &set);
        s.sprintf("Aufgang: %02d:%02d:%02d", rise.hours, rise.minutes, (int)rise.seconds);
        ui->listWidget->addItem(s);
        s.sprintf("Transit: %02d:%02d:%02d", transit.hours, transit.minutes, (int)transit.seconds);
        ui->listWidget->addItem(s);
        s.sprintf("Untergang: %02d:%02d:%02d", set.hours, set.minutes, (int)set.seconds);
        ui->listWidget->addItem(s);

    }

    //sunHeading->setVisible(false);

    setSunVectors(&rise, &observer, sunRise);
    setSunVectors(&set, &observer, sunSet);

    mc->setView(QPointF(observer.lng, observer.lat));

    //overlay->addGeometry();
}
Пример #6
0
// Apply a simple variant type to a DOM property
static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop)
{
    switch (v.type()) {
    case QVariant::String: {
        DomString *str = new DomString();
        str->setText(v.toString());
        if (!translateString)
            str->setAttributeNotr(QLatin1String("true"));
        dom_prop->setElementString(str);
    }
    return true;

    case QVariant::ByteArray:
        dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray()));
        return true;

    case QVariant::Int:
        dom_prop->setElementNumber(v.toInt());
        return true;

    case QVariant::UInt:
        dom_prop->setElementUInt(v.toUInt());
        return true;

    case QVariant::LongLong:
        dom_prop->setElementLongLong(v.toLongLong());
        return true;

    case QVariant::ULongLong:
        dom_prop->setElementULongLong(v.toULongLong());
        return true;

    case QVariant::Double:
        dom_prop->setElementDouble(v.toDouble());
        return true;

    case QVariant::Bool:
        dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue);
        return true;

    case QVariant::Char: {
        DomChar *ch = new DomChar();
        const QChar character = v.toChar();
        ch->setElementUnicode(character.unicode());
        dom_prop->setElementChar(ch);
    }
    return true;

    case QVariant::Point: {
        DomPoint *pt = new DomPoint();
        const QPoint point = v.toPoint();
        pt->setElementX(point.x());
        pt->setElementY(point.y());
        dom_prop->setElementPoint(pt);
    }
    return true;

    case QVariant::PointF: {
        DomPointF *ptf = new DomPointF();
        const QPointF pointf = v.toPointF();
        ptf->setElementX(pointf.x());
        ptf->setElementY(pointf.y());
        dom_prop->setElementPointF(ptf);
    }
    return true;

    case QVariant::Color: {
        DomColor *clr = new DomColor();
        const QColor color = qvariant_cast<QColor>(v);
        clr->setElementRed(color.red());
        clr->setElementGreen(color.green());
        clr->setElementBlue(color.blue());
        const int alphaChannel = color.alpha();
        if (alphaChannel != 255)
            clr->setAttributeAlpha(alphaChannel);
        dom_prop->setElementColor(clr);
    }
    return true;

    case QVariant::Size: {
        DomSize *sz = new DomSize();
        const QSize size = v.toSize();
        sz->setElementWidth(size.width());
        sz->setElementHeight(size.height());
        dom_prop->setElementSize(sz);
    }
    return true;

    case QVariant::SizeF: {
        DomSizeF *szf = new DomSizeF();
        const QSizeF sizef = v.toSizeF();
        szf->setElementWidth(sizef.width());
        szf->setElementHeight(sizef.height());
        dom_prop->setElementSizeF(szf);
    }
    return true;

    case QVariant::Rect: {
        DomRect *rc = new DomRect();
        const QRect rect = v.toRect();
        rc->setElementX(rect.x());
        rc->setElementY(rect.y());
        rc->setElementWidth(rect.width());
        rc->setElementHeight(rect.height());
        dom_prop->setElementRect(rc);
    }
    return true;

    case QVariant::RectF: {
        DomRectF *rcf = new DomRectF();
        const QRectF rectf = v.toRectF();
        rcf->setElementX(rectf.x());
        rcf->setElementY(rectf.y());
        rcf->setElementWidth(rectf.width());
        rcf->setElementHeight(rectf.height());
        dom_prop->setElementRectF(rcf);
    }
    return true;

    case QVariant::Font: {
        DomFont *fnt = new DomFont();
        const QFont font = qvariant_cast<QFont>(v);
        const uint mask = font.resolve();
        if (mask & QFont::WeightResolved) {
            fnt->setElementBold(font.bold());
            fnt->setElementWeight(font.weight());
        }
        if (mask & QFont::FamilyResolved)
            fnt->setElementFamily(font.family());
        if (mask & QFont::StyleResolved)
            fnt->setElementItalic(font.italic());
        if (mask & QFont::SizeResolved)
            fnt->setElementPointSize(font.pointSize());
        if (mask & QFont::StrikeOutResolved)
            fnt->setElementStrikeOut(font.strikeOut());
        if (mask & QFont::UnderlineResolved)
            fnt->setElementUnderline(font.underline());
        if (mask & QFont::KerningResolved)
            fnt->setElementKerning(font.kerning());
        if (mask & QFont::StyleStrategyResolved) {
            const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy");
            fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy())));
        }
        dom_prop->setElementFont(fnt);
    }
    return true;

#ifndef QT_NO_CURSOR
    case QVariant::Cursor: {
        const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape");
        dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape())));
    }
    return true;
#endif

    case QVariant::KeySequence: {
        DomString *s = new DomString();
        s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText));
        dom_prop->setElementString(s);
    }
    return true;

    case QVariant::Locale: {
        DomLocale *dom = new DomLocale();
        const QLocale locale = qvariant_cast<QLocale>(v);

        const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language");
        const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country");

        dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language())));
        dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country())));

        dom_prop->setElementLocale(dom);
    }
    return true;

    case QVariant::SizePolicy: {
        DomSizePolicy *dom = new DomSizePolicy();
        const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v);

        dom->setElementHorStretch(sizePolicy.horizontalStretch());
        dom->setElementVerStretch(sizePolicy.verticalStretch());

        const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType");

        dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy())));
        dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy())));

        dom_prop->setElementSizePolicy(dom);
    }
    return true;

    case QVariant::Date: {
        DomDate *dom = new DomDate();
        const QDate date = qvariant_cast<QDate>(v);

        dom->setElementYear(date.year());
        dom->setElementMonth(date.month());
        dom->setElementDay(date.day());

        dom_prop->setElementDate(dom);
    }
    return true;

    case QVariant::Time: {
        DomTime *dom = new DomTime();
        const QTime time = qvariant_cast<QTime>(v);

        dom->setElementHour(time.hour());
        dom->setElementMinute(time.minute());
        dom->setElementSecond(time.second());

        dom_prop->setElementTime(dom);
    }
    return true;

    case QVariant::DateTime: {
        DomDateTime *dom = new DomDateTime();
        const QDateTime dateTime = qvariant_cast<QDateTime>(v);

        dom->setElementHour(dateTime.time().hour());
        dom->setElementMinute(dateTime.time().minute());
        dom->setElementSecond(dateTime.time().second());
        dom->setElementYear(dateTime.date().year());
        dom->setElementMonth(dateTime.date().month());
        dom->setElementDay(dateTime.date().day());

        dom_prop->setElementDateTime(dom);
    }
    return true;

    case QVariant::Url: {
        DomUrl *dom = new DomUrl();
        const QUrl url = v.toUrl();

        DomString *str = new DomString();
        str->setText(url.toString());
        dom->setElementString(str);

        dom_prop->setElementUrl(dom);
    }
    return true;

    case QVariant::StringList: {
        DomStringList *sl = new DomStringList;
        sl->setElementString(qvariant_cast<QStringList>(v));
        dom_prop->setElementStringList(sl);
    }
    return true;

    default:
        break;
    }

    return false;
}
/*!
  Align a date/time value for a step size

  For Qt::Day alignments there is no "natural day 0" -
  instead the first day of the year is used to avoid jumping
  major ticks positions when panning a scale. For other alignments
  ( f.e according to the first day of the month ) alignDate()
  has to be overloaded.

  \param dateTime Date/time value
  \param stepSize Step size
  \param intervalType Interval type
  \param up When true dateTime is ceiled - otherwise it is floored

  \return Aligned date/time value
 */
QDateTime QwtDateScaleEngine::alignDate(
    const QDateTime &dateTime, double stepSize,
    QwtDate::IntervalType intervalType, bool up ) const
{
    // what about: (year == 1582 && month == 10 && day > 4 && day < 15) ??

    QDateTime dt = dateTime;

    if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
    {
        dt.setUtcOffset( 0 );
    }

    switch( intervalType )
    {
        case QwtDate::Millisecond:
        {
            const int ms = qwtAlignValue(
                dt.time().msec(), stepSize, up ) ;

            dt = QwtDate::floor( dateTime, QwtDate::Second );
            dt = dt.addMSecs( ms );

            break;
        }
        case QwtDate::Second:
        {
            int second = dt.time().second();
            if ( up )
            {
                if ( dt.time().msec() > 0 )
                    second++;
            }

            const int s = qwtAlignValue( second, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Minute );
            dt = dt.addSecs( s );

            break;
        }
        case QwtDate::Minute:
        {
            int minute = dt.time().minute();
            if ( up )
            {
                if ( dt.time().msec() > 0 || dt.time().second() > 0 )
                    minute++;
            }

            const int m = qwtAlignValue( minute, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Hour );
            dt = dt.addSecs( m * 60 );

            break;
        }
        case QwtDate::Hour:
        {
            int hour = dt.time().hour();
            if ( up )
            {
                if ( dt.time().msec() > 0 || dt.time().second() > 0
                    || dt.time().minute() > 0 )
                {
                    hour++;
                }
            }
            const int h = qwtAlignValue( hour, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Day );
            dt = dt.addSecs( h * 3600 );

            break;
        }
        case QwtDate::Day:
        {
            // What date do we expect f.e. from an alignment of 5 days ??
            // Aligning them to the beginning of the year avoids at least
            // jumping major ticks when panning

            int day = dt.date().dayOfYear();
            if ( up )
            {
                if ( dt.time() > QTime( 0, 0 ) )
                    day++;
            }

            const int d = qwtAlignValue( day, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Year );
            dt = dt.addDays( d - 1 );

            break;
        }
        case QwtDate::Week:
        {
            const QDate date = QwtDate::dateOfWeek0(
                dt.date().year(), d_data->week0Type );

            int numWeeks = date.daysTo( dt.date() ) / 7;
            if ( up )
            {
                if ( dt.time() > QTime( 0, 0 ) ||
                    date.daysTo( dt.date() ) % 7 )
                {
                    numWeeks++;
                }
            }

            const int d = qwtAlignValue( numWeeks, stepSize, up ) * 7;

            dt = QwtDate::floor( dt, QwtDate::Day );
            dt.setDate( date );
            dt = dt.addDays( d );

            break;
        }
        case QwtDate::Month:
        {
            int month = dt.date().month();
            if ( up )
            {
                if ( dt.date().day() > 1 ||
                    dt.time() > QTime( 0, 0 ) )
                {
                    month++;
                }
            }

            const int m = qwtAlignValue( month - 1, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Year );
            dt = dt.addMonths( m );

            break;
        }
        case QwtDate::Year:
        {
            int year = dateTime.date().year();
            if ( up )
            {
                if ( dateTime.date().dayOfYear() > 1 ||
                    dt.time() > QTime( 0, 0 ) )
                {
                    year++;
                }
            }

            const int y = qwtAlignValue( year, stepSize, up );

            dt = QwtDate::floor( dt, QwtDate::Day );
            if ( y == 0 )
            {
                // there is no year 0 in the Julian calendar
                dt.setDate( QDate( stepSize, 1, 1 ).addYears( -stepSize ) );
            }
            else
            {
                dt.setDate( QDate( y, 1, 1 ) );
            }

            break;
        }
    }

    if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
    {
        dt.setUtcOffset( dateTime.utcOffset() );
    }

    return dt;
}
Пример #8
0
QString CustomEdit::evaluate(QString clause)
{
    int e0=0;
    while (true) {
        int s0 = clause.indexOf (QRegExp("\\{[A-Z]+\\}"), e0);

        if (s0 < 0)
            break;

        e0 = clause.indexOf ("}", s0);

        QString mid = clause.mid(s0 + 1, e0 - s0 - 1);
        QString repl = "";

        if (!mid.compare("TITLE")) {
            repl = m_pginfo->GetTitle();
            repl.replace("\'","\'\'");
        } else if (!mid.compare("SUBTITLE")) {
            repl = m_pginfo->GetSubtitle();
            repl.replace("\'","\'\'");
        } else if (!mid.compare("DESCR")) {
            repl = m_pginfo->GetDescription();
            repl.replace("\'","\'\'");
        } else if (!mid.compare("SERIESID")) {
            repl = QString("%1").arg(m_pginfo->GetSeriesID());
        } else if (!mid.compare("PROGID")) {
            repl = m_pginfo->GetProgramID();
        } else if (!mid.compare("SEASON")) {
            repl = QString::number(m_pginfo->GetSeason());
        } else if (!mid.compare("EPISODE")) {
            repl = QString::number(m_pginfo->GetEpisode());
        } else if (!mid.compare("CATEGORY")) {
            repl = m_pginfo->GetCategory();
        } else if (!mid.compare("CHANID")) {
            repl = QString("%1").arg(m_pginfo->GetChanID());
        } else if (!mid.compare("CHANNUM")) {
            repl = m_pginfo->GetChanNum();
        } else if (!mid.compare("SCHEDID")) {
            repl = m_pginfo->GetChannelSchedulingID();
        } else if (!mid.compare("CHANNAME")) {
            repl = m_pginfo->GetChannelName();
        } else if (!mid.compare("DAYNAME")) {
            repl = m_pginfo->GetScheduledStartTime().toString("dddd");
        } else if (!mid.compare("STARTDATE")) {
            repl = m_pginfo->GetScheduledStartTime().toString("yyyy-mm-dd hh:mm:ss");
        } else if (!mid.compare("ENDDATE")) {
            repl = m_pginfo->GetScheduledEndTime().toString("yyyy-mm-dd hh:mm:ss");
        } else if (!mid.compare("STARTTIME")) {
            repl = m_pginfo->GetScheduledStartTime().toString("hh:mm");
        } else if (!mid.compare("ENDTIME")) {
            repl = m_pginfo->GetScheduledEndTime().toString("hh:mm");
        } else if (!mid.compare("STARTSEC")) {
            QDateTime date = m_pginfo->GetScheduledStartTime();
            QDateTime midnight = QDateTime(date.date());
            repl = QString("%1").arg(midnight.secsTo(date));
        } else if (!mid.compare("ENDSEC")) {
            QDateTime date = m_pginfo->GetScheduledEndTime();
            QDateTime midnight = QDateTime(date.date());
            repl = QString("%1").arg(midnight.secsTo(date));
        }
        // unknown tags are simply removed
        clause.replace(s0, e0 - s0 + 1, repl);
    }
    return clause;
}
Пример #9
0
bool AssetCache::SetLastModified(const QString &assetRef, const QDateTime &dateTime)
{
    if (!dateTime.isValid())
    {
        LogError("AssetCache::SetLastModified() DateTime is invalid: " + assetRef);
        return false;
    }

    QString absolutePath = FindInCache(assetRef);
    if (absolutePath.isEmpty())
        return false;

    QDate date = dateTime.date();
    QTime time = dateTime.time();

#ifdef Q_WS_WIN
    HANDLE fileHandle = (HANDLE)OpenFileHandle(absolutePath);
    if (fileHandle == INVALID_HANDLE_VALUE)
    {
        LogError("AssetCache: Failed to open cache file to update last modified time: " + assetRef);
        return false;
    }

    // Notes: For SYSTEMTIME Sunday is 0 and ignore msec.
    SYSTEMTIME sysTime;
    sysTime.wDay = (WORD)date.day();
    sysTime.wDayOfWeek = (WORD)date.dayOfWeek();
    if (sysTime.wDayOfWeek == 7)
        sysTime.wDayOfWeek = 0;
    sysTime.wMonth = (WORD)date.month();
    sysTime.wYear = (WORD)date.year();
    sysTime.wHour = (WORD)time.hour();
    sysTime.wMinute = (WORD)time.minute();
    sysTime.wSecond = (WORD)time.second();
    sysTime.wMilliseconds = 0; 

    // Set last write time
    FILETIME fileTime;
    BOOL success = SystemTimeToFileTime(&sysTime, &fileTime);
    if (success)
        success = SetFileTime(fileHandle, 0, 0, &fileTime);
    CloseHandle(fileHandle);
    if (!success)
    {
        LogError("AssetCache: Failed to update cache file last modified time: " + assetRef);
        return false;
    }
    return true;
#else
    QString nativePath = QDir::toNativeSeparators(absolutePath);
    utimbuf modTime;
    modTime.actime = (time_t)(dateTime.toMSecsSinceEpoch() / 1000);
    modTime.modtime = (time_t)(dateTime.toMSecsSinceEpoch() / 1000);
    if (utime(nativePath.toStdString().c_str(), &modTime) == -1)
    {
        LogError("AssetCache: Failed to read cache file last modified time: " + assetRef);
        return false;
    }
    else
        return true;
#endif
}
Пример #10
0
void DivePlannerWidget::setupStartTime(QDateTime startTime)
{
	ui.startTime->setTime(startTime.time());
	ui.dateEdit->setDate(startTime.date());
}
Пример #11
0
int QGeoInfoThreadWinCE::msecsTo(QDateTime from, QDateTime to)
{
    int MSECS_PER_DAY = 86400000;
    return (from.date().daysTo(to.date()) * MSECS_PER_DAY) + from.time().msecsTo(to.time());
}
Пример #12
0
void EntryDialog::updateEndDate(const QDateTime & startDate)
{
    ui->endDate->setMinimumDate( startDate.date() );
    ui->endDate->setMinimumTime( startDate.time() );
}
Пример #13
0
void Yahoo::createAutoHistoryUrls (QString &path, QString &d)
{
  if (plug.open(path, chartIndex))
  {
    qDebug("Yahoo::createAutoHistoryUrls:could not open db");
    return;
  }

  QFileInfo fi(path);
  QString fn = fi.fileName();

  // verify if this chart can be updated by this plugin
  QString s;
  DBIndexItem item;
  chartIndex->getIndexItem(fn, item);
  item.getQuotePlugin(s);
  if (! s.length())
  {
    item.setQuotePlugin(pluginName);
    chartIndex->setIndexItem(fn, item);
  }
//  else
//  {
//    if (s.compare(pluginName))
//    {
//      qDebug("Yahoo::createAutoHistoryUrls:source not same as destination");
//      plug.close();
//      return;
//    }
//  }

  QDate edt = QDate::currentDate();
  if (edt.dayOfWeek() == 6)
    edt = edt.addDays(-1);
  else
  {
    if (edt.dayOfWeek() == 7)
      edt = edt.addDays(-2);
  }

  Bar bar;
  plug.getLastBar(bar);
  if (bar.getEmptyFlag())
  {
    QDate dt = edt;
    dt = dt.addDays(-365);
    s = dt.toString("yyyyMMdd000000");
    bar.setDate(s);
  }

  QDateTime dt;
  bar.getDate(dt);
  if (dt.date() == edt)
  {
//    qDebug("Yahoo::createAutoHistoryUrls:barDate == endDate");
    plug.close();
    return;
  }

  s = "http://table.finance.yahoo.com/table.csv?s=";
  s.append(d);
  s.append("&a=");
  s.append(QString::number(dt.date().month() - 1));
  s.append("&b=");
  s.append(dt.toString("dd"));
  s.append("&c=");
  s.append(dt.toString("yyyy"));
  s.append("&d=");
  s.append(QString::number(edt.month() - 1));
  s.append("&e=");
  s.append(edt.toString("dd"));
  s.append("&f=");
  s.append(edt.toString("yyyy"));
  s.append("&g=d&ignore=.csv");

  plug.close();

  Setting *set = new Setting;
  QString ts = "url";
  set->setData(ts, s);
  ts = "symbol";
  set->setData(ts, d);
  url.append(set);
}
static bool isFirstSecOfMonth( const QDateTime& date )
{
    return date.date().day() == 1 && date.time().hour() == 0 && date.time().minute() == 0;
}
Пример #15
0
bool MetaEngine::setImageDateTime(const QDateTime& dateTime, bool setDateTimeDigitized, bool setProgramName) const
{
    if(!dateTime.isValid())
        return false;

    if (!setProgramId(setProgramName))
        return false;

    try
    {
        // In first we write date & time into Exif.

        // DateTimeDigitized is set by slide scanners etc. when a picture is digitized.
        // DateTimeOriginal specifies the date/time when the picture was taken.
        // For digital cameras, these dates should be both set, and identical.
        // Reference: http://www.exif.org/Exif2-2.PDF, chapter 4.6.5, table 4, section F.

        const std::string &exifdatetime(dateTime.toString(QString::fromLatin1("yyyy:MM:dd hh:mm:ss")).toLatin1().constData());
        d->exifMetadata()["Exif.Image.DateTime"]         = exifdatetime;
        d->exifMetadata()["Exif.Photo.DateTimeOriginal"] = exifdatetime;

        if(setDateTimeDigitized)
            d->exifMetadata()["Exif.Photo.DateTimeDigitized"] = exifdatetime;

#ifdef _XMP_SUPPORT_

        // In second we write date & time into Xmp.

        const std::string &xmpdatetime(dateTime.toString(Qt::ISODate).toLatin1().constData());

        Exiv2::Value::AutoPtr xmpTxtVal = Exiv2::Value::create(Exiv2::xmpText);
        xmpTxtVal->read(xmpdatetime);
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.exif.DateTimeOriginal"),  xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.photoshop.DateCreated"),  xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.tiff.DateTime"),          xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.xmp.CreateDate"),         xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.xmp.MetadataDate"),       xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.xmp.ModifyDate"),         xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.video.DateTimeOriginal"), xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.video.DateUTC"),          xmpTxtVal.get());
        d->xmpMetadata().add(Exiv2::XmpKey("Xmp.video.ModificationDate"), xmpTxtVal.get());

        if(setDateTimeDigitized)
        {
            d->xmpMetadata().add(Exiv2::XmpKey("Xmp.exif.DateTimeDigitized"),  xmpTxtVal.get());
            d->xmpMetadata().add(Exiv2::XmpKey("Xmp.video.DateTimeDigitized"), xmpTxtVal.get());
        }

        // Tag not updated:
        // "Xmp.dc.DateTime" is a sequence of date relevant of dublin core change.
        //                   This is not the picture date as well

#endif // _XMP_SUPPORT_

        // In third we write date & time into Iptc.

        const std::string &iptcdate(dateTime.date().toString(Qt::ISODate).toLatin1().constData());
        const std::string &iptctime(dateTime.time().toString(Qt::ISODate).toLatin1().constData());
        d->iptcMetadata()["Iptc.Application2.DateCreated"] = iptcdate;
        d->iptcMetadata()["Iptc.Application2.TimeCreated"] = iptctime;

        if(setDateTimeDigitized)
        {
            d->iptcMetadata()["Iptc.Application2.DigitizationDate"] = iptcdate;
            d->iptcMetadata()["Iptc.Application2.DigitizationTime"] = iptctime;
        }

        return true;
    }
    catch( Exiv2::Error& e )
    {
        d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Date & Time into image using Exiv2 "), e);
    }
    catch(...)
    {
        qCCritical(DIGIKAM_METAENGINE_LOG) << "Default exception from Exiv2";
    }

    return false;
}
Пример #16
0
void KOWhatsNextView::updateView()
{
    KIconLoader kil("kdepim");
    QString *ipath = new QString();
    kil.loadIcon("kdepim", KIcon::NoGroup, 32, KIcon::DefaultState, ipath);

    mText = "<table width=\"100%\">\n";
    mText += "<tr bgcolor=\"#3679AD\"><td><h1>";
    mText += "<img src=\"";
    mText += *ipath;
    mText += "\">";
    mText += "<font color=\"white\"> ";
    mText += i18n("What's Next?") + "</font></h1>";
    mText += "</td></tr>\n<tr><td>";

    mText += "<h2>";
    if(mStartDate.daysTo(mEndDate) < 1)
    {
        mText += KGlobal::locale()->formatDate(mStartDate);
    }
    else
    {
        mText += i18n("Date from - to", "%1 - %2")
                 .arg(KGlobal::locale()->formatDate(mStartDate))
                 .arg(KGlobal::locale()->formatDate(mEndDate));
    }
    mText += "</h2>\n";

    Event::List events;
    for(QDate date = mStartDate; date <= mEndDate; date = date.addDays(1))
        events += calendar()->events(date, EventSortStartDate, SortDirectionAscending);

    if(events.count() > 0)
    {
        mText += "<p></p>";
        kil.loadIcon("appointment", KIcon::NoGroup, 22, KIcon::DefaultState, ipath);
        mText += "<h2><img src=\"";
        mText += *ipath;
        mText += "\">";
        mText += i18n("Events:") + "</h2>\n";
        mText += "<table>\n";
        Event::List::ConstIterator it;
        for(it = events.begin(); it != events.end(); ++it)
        {
            Event *ev = *it;
            if(!ev->doesRecur())
            {
                appendEvent(ev);
            }
            else
            {
                // FIXME: This should actually be cleaned up. Libkcal should
                // provide a method to return a list of all recurrences in a
                // given time span.
                Recurrence *recur = ev->recurrence();
                int duration = ev->dtStart().secsTo(ev->dtEnd());
                QDateTime start = recur->getPreviousDateTime(
                                      QDateTime(mStartDate, QTime()));
                QDateTime end = start.addSecs(duration);
                if(end.date() >= mStartDate)
                {
                    appendEvent(ev, start, end);
                }
                start = recur->getNextDateTime(start);
                while(start.isValid() && start.date() <= mEndDate)
                {
                    appendEvent(ev, start);
                    start = recur->getNextDateTime(start);
                }
            }
        }
        mText += "</table>\n";
    }

    mTodos.clear();
    Todo::List todos = calendar()->todos(TodoSortDueDate, SortDirectionAscending);
    if(todos.count() > 0)
    {
        kil.loadIcon("todo", KIcon::NoGroup, 22, KIcon::DefaultState, ipath);
        mText += "<h2><img src=\"";
        mText += *ipath;
        mText += "\">";
        mText += i18n("To-do:") + "</h2>\n";
        mText += "<ul>\n";
        Todo::List::ConstIterator it;
        for(it = todos.begin(); it != todos.end(); ++it)
        {
            Todo *todo = *it;
            if(!todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= mEndDate)
                appendTodo(todo);
        }
        bool gotone = false;
        int priority = 1;
        while(!gotone && priority <= 9)
        {
            for(it = todos.begin(); it != todos.end(); ++it)
            {
                Todo *todo = *it;
                if(!todo->isCompleted() && (todo->priority() == priority))
                {
                    appendTodo(todo);
                    gotone = true;
                }
            }
            priority++;
            kdDebug(5850) << "adding the todos..." << endl;
        }
        mText += "</ul>\n";
    }

    QStringList myEmails(KOPrefs::instance()->allEmails());
    int replies = 0;
    events = calendar()->events(QDate::currentDate(), QDate(2975, 12, 6));
    Event::List::ConstIterator it2;
    for(it2 = events.begin(); it2 != events.end(); ++it2)
    {
        Event *ev = *it2;
        Attendee *me = ev->attendeeByMails(myEmails);
        if(me != 0)
        {
            if(me->status() == Attendee::NeedsAction && me->RSVP())
            {
                if(replies == 0)
                {
                    mText += "<p></p>";
                    kil.loadIcon("reply", KIcon::NoGroup, 22, KIcon::DefaultState, ipath);
                    mText += "<h2><img src=\"";
                    mText += *ipath;
                    mText += "\">";
                    mText += i18n("Events and to-dos that need a reply:") + "</h2>\n";
                    mText += "<table>\n";
                }
                replies++;
                appendEvent(ev);
            }
        }
    }
    todos = calendar()->todos();
    Todo::List::ConstIterator it3;
    for(it3 = todos.begin(); it3 != todos.end(); ++it3)
    {
        Todo *to = *it3;
        Attendee *me = to->attendeeByMails(myEmails);
        if(me != 0)
        {
            if(me->status() == Attendee::NeedsAction && me->RSVP())
            {
                if(replies == 0)
                {
                    mText += "<p></p>";
                    kil.loadIcon("reply", KIcon::NoGroup, 22, KIcon::DefaultState, ipath);
                    mText += "<h2><img src=\"";
                    mText += *ipath;
                    mText += "\">";
                    mText += i18n("Events and to-dos that need a reply:") + "</h2>\n";
                    mText += "<table>\n";
                }
                replies++;
                appendEvent(to);
            }
        }
        kdDebug() << "check for todo-replies..." << endl;
    }
    if(replies > 0) mText += "</table>\n";


    mText += "</td></tr>\n</table>\n";

    kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl;

    delete ipath;

    mView->setText(mText);
}
Пример #17
0
QString dateTimeStr(const QDateTime &date)
{
    return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm");
}
Пример #18
0
/** 
 * Dummy database for testing. If you want to edit a data, you also edit
 * test_models.cpp TestModels::test_common.
 *
 */
void dummy_db()
{
    // initially created in initdb()
    // Unit count;
    // count.setName("count");
    // QCOMPARE(count.save(), true);
    
    Unit second;
    second.setName("second");
    QCOMPARE(second.save(), true);

    const QDjangoQuerySet<Unit> units;
    Unit* f_second = units.get(QDjangoWhere("name", QDjangoWhere::Equals, "second"));
    
    Element pushup;
    pushup.setName("pushup");
    pushup.setPurpose(1000);
    pushup.setNote("It is pushup note.");
    pushup.setShortcut("push");
    pushup.setUnit(f_second);
    QCOMPARE(pushup.save(), true);

    Element* running = new Element;
    running->setName("running");
    running->setPurpose(300);
    running->setNote("It is running note.");
    QCOMPARE(running->save(), true);

    Element breathing;
    breathing.setName("breathing");
    breathing.setPurpose(70000);
    QCOMPARE(breathing.save(), true);

    Group daily_group;
    daily_group.setName("daily");
    daily_group.setNote("It is daily.");
    QCOMPARE(daily_group.save(), true);

    Group monthly_group;
    monthly_group.setName("monthly");
    monthly_group.setNote("It is monthly");
    QCOMPARE(monthly_group.save(), true);

    const QDjangoQuerySet<Element> elements;
    Element* f_pushup = elements.get(QDjangoWhere("name", QDjangoWhere::Equals, "pushup"));
    Element* f_running = elements.get(QDjangoWhere("name", QDjangoWhere::Equals, "running"));
    
    const QDjangoQuerySet<Group> groups;
    Group* f_daily_group = groups.get(QDjangoWhere("name", QDjangoWhere::Equals, "daily"));


    // It requires free store. It requires more code.
    ElementGroup daily;
    daily.setElement(f_pushup);
    daily.setGroup(f_daily_group);
    QCOMPARE(daily.save(), true);


    QDateTime current = QDateTime::currentDateTime();
    int year = current.date().year();
    int month = current.date().month();
    int day = current.date().day();

    QDate ddate = QDate(year, month, current.date().addDays(1).day());
    QTime dtime = QTime(10, 5, 59);
    QDateTime start = QDateTime(ddate, dtime);
    QDateTime end = QDateTime(QDate(year, month, current.date().addDays(3).day()), QTime(15, 6, 5));

    Schedule today;		// start: today + 1, end: today + 3
    today.setStart(start);
    today.setEnd(end);
    today.setElement(f_pushup);
    QCOMPARE(today.save(), true);

    QDate ddate2 = QDate(year, month, day);
    QDateTime start2 = QDateTime(ddate2);
    Schedule today2;		// start: today0
    today2.setStart(start2);
    today2.setEnd(start2);
    today2.setGroup(f_daily_group);
    QCOMPARE(today2.save(), true);

    Schedule today3;		// start: today0, end: today0 + 1
    today3.setStart(start2);
    today3.setEnd(start2.addDays(1));
    today3.setElement(f_pushup);
    QCOMPARE(today3.save(), true);

    Schedule today4;		// start: today, end: today + 3
    today4.setStart(current);
    today4.setEnd(current.addDays(3));
    today4.setElement(f_pushup);
    QCOMPARE(today4.save(), true);

    Schedule today5;		// start: today0 + 1, end: today0 + 2
    today5.setStart(start2.addDays(1));
    today5.setEnd(current.addDays(2));
    today5.setElement(f_pushup);
    QCOMPARE(today5.save(), true);

    Schedule yesterday;		// start: today0 - 1, end: today0 + 3
    yesterday.setStart(start2.addDays(-1));
    yesterday.setEnd(start2.addDays(3));
    yesterday.setElement(f_pushup);
    QCOMPARE(yesterday.save(), true);

    Schedule yesterday2;
    yesterday2.setStart(start2.addDays(-1));
    yesterday2.setEnd(start2.addDays(4));
    yesterday2.setElement(running);
    QCOMPARE(yesterday2.save(), true);

    QDateTime rdate = QDateTime(QDate(year, month, day), QTime(18, 0, 0));
    Record record_of_today;
    record_of_today.setDatetime(rdate);
    record_of_today.setRecord(800);
    record_of_today.setElement(f_pushup);
    QCOMPARE(record_of_today.save(), true);
}