Beispiel #1
0
void BlDateSearch::s_searchFecha()
{
    BL_FUNC_DEBUG

    QDialog *diag = new QDialog ( 0 );
    diag->setModal ( true );
    QCalendarWidget *calend = new QCalendarWidget ( diag );
    /// Se pone el 1er dia del calendario a lunes.
    calend->setFirstDayOfWeek ( Qt::Monday );

    /// Evitar fechas demasiado antiguas
    calend->setMinimumDate( QDate ( 1900, 1, 1 ) );

    /// Si el campo estaba vacío, seleccionar una fecha imposible, pero mostrar el mes actual
    if ( m_textoFecha->text().isEmpty() ) {
        calend->setSelectedDate ( calend->minimumDate() );
        calend->setCurrentPage ( QDate::currentDate().year(), QDate::currentDate().month() );
    }

    /// Si ya hay una fecha en el campo, abrir el calendario con ese día seleccionado inicialmente
    else {
        calend->setSelectedDate ( blNormalizeDate ( m_textoFecha->text() ) );
    }

    connect ( calend, SIGNAL ( activated ( const QDate & ) ), diag, SLOT ( accept() ) );

    /// Creamos un layout donde estara el contenido de la ventana y la ajustamos al QDialog
    /// para que sea redimensionable y aparezca el titulo de la ventana.
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget ( calend );
    layout->setMargin ( 0 );
    layout->setSpacing ( 0 );
    diag->setLayout ( layout );
    diag->setWindowTitle ( _ ( "Seleccione fecha" ) );
    diag->exec();

    /// Si la fecha es imposible, significa que el usuario no ha seleccionado una fecha
    /// y su campo debe quedarse como estaba: vacío
    if ( calend->selectedDate() != QDate ( 1900, 1, 1 ) ) {
        m_textoFecha->setText ( calend->selectedDate().toString ( "dd/MM/yyyy" ) );
    }

    /// Liberamos la memoria
    delete layout;
    delete calend;
    delete diag;

    emit ( valueChanged ( m_textoFecha->text() ) );
    emit ( editingFinished () );

    
}
void tst_QCalendarWidget::buttonClickCheck()
{
    QCalendarWidget object;
    QSize size = object.sizeHint();
    object.setGeometry(0,0,size.width(), size.height());
    object.show();
    object.activateWindow();
    QVERIFY(QTest::qWaitForWindowActive(&object));

    QDate selectedDate(2005, 1, 1);
    //click on the month buttons
    int month = object.monthShown();
    QToolButton *button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(month > 1 ? month-1 : 12, object.monthShown());
    button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(month, object.monthShown());

    button = object.findChild<QToolButton *>("qt_calendar_yearbutton");
    QTest::mouseClick(button, Qt::LeftButton, Qt::NoModifier, button->rect().center(), 2);
    QVERIFY(!button->isVisible());
    QSpinBox *spinbox = object.findChild<QSpinBox *>("qt_calendar_yearedit");
    QTest::qWait(500);
    QTest::keyClick(spinbox, '2');
    QTest::keyClick(spinbox, '0');
    QTest::keyClick(spinbox, '0');
    QTest::keyClick(spinbox, '6');
    QTest::qWait(500);
    QWidget *widget = object.findChild<QWidget *>("qt_calendar_calendarview");
    QTest::mouseMove(widget);
    QTest::mouseClick(widget, Qt::LeftButton);
    QCOMPARE(2006, object.yearShown());
    object.setSelectedDate(selectedDate);
    object.showSelectedDate();
    QTest::keyClick(widget, Qt::Key_Down);
    QVERIFY(selectedDate != object.selectedDate());

    object.setDateRange(QDate(2006,1,1), QDate(2006,2,28));
    object.setSelectedDate(QDate(2006,1,1));
    object.showSelectedDate();
    button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(1, object.monthShown());

    button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(2, object.monthShown());
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(2, object.monthShown());

}
void QgsAttributeEditor::selectDate()
{
  QPushButton *pb = qobject_cast<QPushButton *>( sender() );
  if ( !pb )
    return;

  QWidget *hbox = qobject_cast<QWidget *>( pb->parent() );
  if ( !hbox )
    return;

  QLineEdit *le = hbox->findChild<QLineEdit *>();
  if ( !le )
    return;

  QDialog *dlg = new QDialog();
  dlg->setWindowTitle( tr( "Select a date" ) );
  QVBoxLayout *vl = new QVBoxLayout( dlg );

  QCalendarWidget *cw = new QCalendarWidget( dlg );
  cw->setSelectedDate( QDate::fromString( le->text(), Qt::ISODate ) );
  vl->addWidget( cw );

  QDialogButtonBox *buttonBox = new QDialogButtonBox( dlg );
  buttonBox->addButton( QDialogButtonBox::Ok );
  buttonBox->addButton( QDialogButtonBox::Cancel );
  vl->addWidget( buttonBox );

  connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
  connect( buttonBox, SIGNAL( rejected() ), dlg, SLOT( reject() ) );

  if ( dlg->exec() == QDialog::Accepted )
  {
    le->setText( cw->selectedDate().toString( Qt::ISODate ) );
  }
}
Beispiel #4
0
QDate QtopiaInputDialog::getDate(QWidget *parent, const QString &title, const QString &label, const QDate &date,
                                 const QDate &minDate, const QDate &maxDate, bool *ok)
{
#ifdef CALENDAR_FOR_DATE
    QCalendarWidget *cal = new QCalendarWidget();
    cal->setSelectedDate(date);
    cal->setMinimumDate(minDate);
    cal->setMaximumDate(maxDate);
    cal->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
    QTextCharFormat headerFormat = cal->headerTextFormat();
    headerFormat.setBackground(QApplication::palette().window());
    headerFormat.setForeground(QApplication::palette().windowText());
    cal->setHeaderTextFormat(headerFormat);
    QWidget *navBar = cal->findChild<QWidget*>("qt_calendar_navigationbar");
    if (navBar)
        navBar->setBackgroundRole(QPalette::Window);

    QtopiaInputDialog dlg(parent, title, label, cal);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return cal->selectedDate();
#else
    QDateEdit *de = new QDateEdit(date);
    de->setMinimumDate(minDate);
    de->setMaximumDate(maxDate);

    QtopiaInputDialog dlg(parent, title, label, de);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return de->date();
#endif
}
Beispiel #5
0
void LXQtWorldClock::activated(ActivationReason reason)
{
    switch (reason)
    {
    case ILXQtPanelPlugin::Trigger:
    case ILXQtPanelPlugin::MiddleClick:
        break;

    default:
        return;
    }

    if (!mPopup)
    {
        mPopup = new LXQtWorldClockPopup(mContent);
        connect(mPopup, SIGNAL(deactivated()), SLOT(deletePopup()));

        if (reason == ILXQtPanelPlugin::Trigger)
        {
            mPopup->setObjectName(QLatin1String("WorldClockCalendar"));

            mPopup->layout()->setContentsMargins(0, 0, 0, 0);
            QCalendarWidget *calendarWidget = new QCalendarWidget(mPopup);
            mPopup->layout()->addWidget(calendarWidget);

            QString timeZoneName = mActiveTimeZone;
            if (timeZoneName == QLatin1String("local"))
                timeZoneName = QString::fromLatin1(QTimeZone::systemTimeZoneId());

            QTimeZone timeZone(timeZoneName.toLatin1());
            calendarWidget->setFirstDayOfWeek(QLocale(QLocale::AnyLanguage, timeZone.country()).firstDayOfWeek());
            calendarWidget->setSelectedDate(QDateTime::currentDateTime().toTimeZone(timeZone).date());
        }
        else
        {
            mPopup->setObjectName(QLatin1String("WorldClockPopup"));

            mPopupContent = new QLabel(mPopup);
            mPopup->layout()->addWidget(mPopupContent);
            mPopupContent->setAlignment(mContent->alignment());

            updatePopupContent();
        }

        mPopup->adjustSize();
        mPopup->setGeometry(calculatePopupWindowPos(mPopup->size()));

        willShowWindow(mPopup);
        mPopup->show();
    }
    else
    {
        deletePopup();
    }
}
Beispiel #6
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QCalendarWidget calendar;
    calendar.setSelectedDate(calendar.selectedDate().addDays(3));
    calendar.setGridVisible(true);
    calendar.show();

    QCalendarWidget calendarMin;
    calendarMin.setMinimumDate(calendarMin.selectedDate().addDays(-7));
    calendarMin.setGridVisible(true);
    calendarMin.show();

    QCalendarWidget calendarMax;
    calendarMax.setMaximumDate(calendarMax.selectedDate().addDays(7));
    calendarMax.setGridVisible(true);
    calendarMax.show();

    return app.exec();
}
void tst_QCalendarWidget::showPrevNext()
{
    QFETCH(ShowFunc, function);
    QFETCH(QDate, dateOrigin);
    QFETCH(QDate, expectedDate);

    QCalendarWidget calWidget;
    calWidget.show();
    QVERIFY(QTest::qWaitForWindowExposed(&calWidget));
    if(!dateOrigin.isNull()) {
        calWidget.setSelectedDate(dateOrigin);
        calWidget.setCurrentPage(dateOrigin.year(), dateOrigin.month());

        QCOMPARE(calWidget.yearShown(), dateOrigin.year());
        QCOMPARE(calWidget.monthShown(), dateOrigin.month());
    } else {
        QCOMPARE(calWidget.yearShown(), QDate::currentDate().year());
        QCOMPARE(calWidget.monthShown(), QDate::currentDate().month());
    }

    (calWidget.*function)();

    QCOMPARE(calWidget.yearShown(), expectedDate.year());
    QCOMPARE(calWidget.monthShown(), expectedDate.month());

    // QTBUG-4058
    QTest::qWait(20);
    QToolButton *button = calWidget.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    expectedDate = expectedDate.addMonths(-1);
    QCOMPARE(calWidget.yearShown(), expectedDate.year());
    QCOMPARE(calWidget.monthShown(), expectedDate.month());

    if(!dateOrigin.isNull()) {
        //the selectedDate should not have changed
        QCOMPARE(calWidget.selectedDate(), dateOrigin);
    }
}
bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
{
    if ( !editor )
        return false;

    QgsVectorLayer::EditType editType = vl->editType( idx );
    const QgsField &field = vl->pendingFields()[idx];
    QVariant::Type myFieldType = field.type();

    QSettings settings;
    QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

    switch ( editType )
    {
    case QgsVectorLayer::Classification:
    case QgsVectorLayer::UniqueValues:
    case QgsVectorLayer::Enumeration:
    case QgsVectorLayer::ValueMap:
    case QgsVectorLayer::ValueRelation:
    {
        QVariant v = value;
        QComboBox *cb = qobject_cast<QComboBox *>( editor );
        if ( !cb )
            return false;

        if ( v.isNull() )
        {
            v = nullValue;
        }

        int idx = cb->findData( v );
        if ( idx < 0 )
            return false;

        cb->setCurrentIndex( idx );
    }
    break;

    case QgsVectorLayer::DialRange:
    case QgsVectorLayer::SliderRange:
    case QgsVectorLayer::EditRange:
    {
        if ( myFieldType == QVariant::Int )
        {
            if ( editType == QgsVectorLayer::EditRange )
            {
                QSpinBox *sb = qobject_cast<QSpinBox *>( editor );
                if ( !sb )
                    return false;
                sb->setValue( value.toInt() );
            }
            else
            {
                QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
                if ( !sl )
                    return false;
                sl->setValue( value.toInt() );
            }
            break;
        }
        else if ( myFieldType == QVariant::Double )
        {
            QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor );
            if ( !dsb )
                return false;
            dsb->setValue( value.toDouble() );
        }
    }

    case QgsVectorLayer::CheckBox:
    {
        QGroupBox *gb = qobject_cast<QGroupBox *>( editor );
        if ( gb )
        {
            QPair<QString, QString> states = vl->checkedState( idx );
            gb->setChecked( value == states.first );
            break;
        }

        QCheckBox *cb = qobject_cast<QCheckBox *>( editor );
        if ( cb )
        {
            QPair<QString, QString> states = vl->checkedState( idx );
            cb->setChecked( value == states.first );
            break;
        }
    }

    // fall-through

    case QgsVectorLayer::LineEdit:
    case QgsVectorLayer::UniqueValuesEditable:
    case QgsVectorLayer::Immutable:
    case QgsVectorLayer::UuidGenerator:
    default:
    {
        QLineEdit *le = qobject_cast<QLineEdit *>( editor );
        QComboBox *cb = qobject_cast<QComboBox *>( editor );
        QTextEdit *te = qobject_cast<QTextEdit *>( editor );
        QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor );
        if ( !le && ! cb && !te && !pte )
            return false;

        QString text;
        if ( value.isNull() )
        {
            if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
                text = "";
            else if ( editType == QgsVectorLayer::UuidGenerator )
                text = QUuid::createUuid().toString();
            else
                text = nullValue;
        }
        else
        {
            text = value.toString();
        }

        if ( le )
            le->setText( text );
        if ( cb && cb->isEditable() )
            cb->setEditText( text );
        if ( te )
            te->setHtml( text );
        if ( pte )
            pte->setPlainText( text );
    }
    break;

    case QgsVectorLayer::FileName:
    case QgsVectorLayer::Calendar:
    {
        QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
        if ( cw )
        {
            cw->setSelectedDate( value.toDate() );
            break;
        }

        QLineEdit* le = qobject_cast<QLineEdit*>( editor );
        if ( !le )
        {
            le = editor->findChild<QLineEdit *>();
        }
        if ( !le )
        {
            return false;
        }
        le->setText( value.toString() );
    }
    break;
    }

    return true;
}