コード例 #1
0
ファイル: CommandsTester.cpp プロジェクト: KDE/calligra
void CommandsTester::testCalendarModifyParentCmd()
{
    Calendar *calendar1 = new Calendar();
    calendar1->setTimeZone(QTimeZone("Europe/Berlin"));
    Calendar *calendar2 = new Calendar();
    calendar2->setTimeZone(QTimeZone("Africa/Cairo"));
    m_project->addCalendar(calendar1);
    m_project->addCalendar(calendar2);
    QVERIFY(m_project->calendarCount() == 2);
    QVERIFY(calendar1->timeZone().id() == "Europe/Berlin");
    QVERIFY(calendar2->timeZone().id() == "Africa/Cairo");

    CalendarModifyParentCmd *cmd1 = new CalendarModifyParentCmd(m_project, calendar1, calendar2);
    cmd1->execute();
    QVERIFY(calendar2->childAt(0) == calendar1);
    QVERIFY(calendar1->timeZone().id() == "Africa/Cairo");
    cmd1->unexecute();
    QVERIFY(!calendar2->childCount());
    QVERIFY(calendar1->timeZone().id() == "Europe/Berlin");

    delete cmd1;
    m_project->takeCalendar(calendar1);
    m_project->takeCalendar(calendar2);
    delete calendar1;
    delete calendar2;
}
コード例 #2
0
ファイル: timesource.cpp プロジェクト: KDE/plasma-workspace
void TimeSource::setTimeZone(const QString &tz)
{
    m_tzName = tz;
    m_local = m_tzName == I18N_NOOP("Local");
    if (m_local) {
        m_tzName = QString::fromUtf8(QTimeZone::systemTimeZoneId());
    }

    if (m_local) {
        m_tz = QTimeZone(QTimeZone::systemTimeZoneId());
    } else {
        m_tz = QTimeZone(m_tzName.toUtf8());
        if (!m_tz.isValid()) {
            m_tz = QTimeZone(QTimeZone::systemTimeZoneId());
        }
    }

    const QString trTimezone = i18n(m_tzName.toUtf8());
    setData(I18N_NOOP("Timezone"), trTimezone);

    const QStringList tzParts = trTimezone.split('/', QString::SkipEmptyParts);
    if (tzParts.count() == 1) {
        // no '/' so just set it as the city
        setData(I18N_NOOP("Timezone City"), trTimezone);
    } else if (tzParts.count() == 2) {
        setData(I18N_NOOP("Timezone Continent"), tzParts.value(0));
        setData(I18N_NOOP("Timezone City"), tzParts.value(1));
    } else { // for zones like America/Argentina/Buenos_Aires
        setData(I18N_NOOP("Timezone Continent"), tzParts.value(0));
        setData(I18N_NOOP("Timezone Country"), tzParts.value(1));
        setData(I18N_NOOP("Timezone City"), tzParts.value(2));
    }

    updateTime();
}
コード例 #3
0
void WorldTime::beginNewTz()
{
    changed = false;

    QString selectedTz;
    int selButton = findCurrentButton();
    if(selButton > 0) {
        if(! listCities.at(selButton)->isChecked())
            listCities.at(selButton)->setChecked(true);
        return;
    }

    if(selButton == -2) {
        selButton = 0;
        listCities.at(0)->setChecked(true);
        setButtonAvailable(0);
    }

    else if(selButton != -1 ) {
        selectedTz = strCityTz[selButton];
    }


    if(selectedTz.isEmpty()) {
        selectedTz = strCityTz[0];
        listCities.at(0)->setChecked(true);
    }

    frmMap->setZone( QTimeZone( selectedTz.toLocal8Bit() ) );
    frmMap->setFocus();
    editMode();
    frmMap->selectNewZone();

}
コード例 #4
0
void
TimeDateModule::save()
{
    if ( ui->isNtpEnabledCheckBox->isChecked() != m_timeDate->isNtpEnabled() )
        m_timeDate->setNtp( ui->isNtpEnabledCheckBox->isChecked() );

    // Only possible to modify date if ntp is disabled
    if ( ( m_isTimeEdited || m_isDateEdited ) && !ui->isNtpEnabledCheckBox->isChecked() )
    {
        QDateTime time( ui->dateEdit->date(), ui->timeEdit->time() );
        m_timeDate->setTime( time );
    }

    if ( ui->isRtcLocalCheckBox->isChecked() != m_timeDate->isRtcInLocalTimeZone() )
        m_timeDate->setLocalRtc( ui->isRtcLocalCheckBox->isChecked() );

    if ( !m_timeZone.isEmpty() && QTimeZone( m_timeZone.toLatin1() ).isValid() )
    {
        if ( m_timeZone != m_timeDate->timeZone() )
            m_timeDate->setTimeZone( m_timeZone );
    }

    m_isTimeEdited = false;
    m_isDateEdited = false;
    updateFields();
    updateTimeFields();
}
コード例 #5
0
void WorldTime::slotNewTzCancelled()
{
    QString currTz;
    if(isEditMode) {
        int selButton = findCurrentButton();
        currTz = strCityTz[selButton];
        frmMap->setZone( QTimeZone( currTz.toLocal8Bit() ) );
        slotNewTz( QTimeZone( currTz.toLocal8Bit() ) );
        if( listCities.at(selButton)->isChecked())
            listCities.at(selButton)->setChecked( false);

    }

    cancelChanges();
    readInTimes();
}
コード例 #6
0
ファイル: CommandsTester.cpp プロジェクト: KDE/calligra
void CommandsTester::testCalendarModifyTimeZoneCmd()
{
    Calendar *calendar1 = new Calendar();
    calendar1->setTimeZone(QTimeZone("Europe/Berlin"));
    m_project->addCalendar(calendar1);
    QVERIFY(m_project->calendarCount() == 1);
    QVERIFY(calendar1->timeZone().id() == "Europe/Berlin");

    CalendarModifyTimeZoneCmd *cmd1 = new CalendarModifyTimeZoneCmd(calendar1, QTimeZone("Africa/Cairo"));
    cmd1->execute();
    QVERIFY(calendar1->timeZone().id() == "Africa/Cairo");
    cmd1->unexecute();
    QVERIFY(calendar1->timeZone().id() == "Europe/Berlin");

    delete cmd1;
    m_project->takeCalendar(calendar1);
    delete calendar1;
}
コード例 #7
0
ファイル: timezone.cpp プロジェクト: EvorzStudios/plexydesk
void TimeZoneActivity::loadTimeZones() {
  std::vector<UIKit::ModelViewItem *> _item_list;

  foreach(const QByteArray id, QTimeZone::availableTimeZoneIds()) {
    QString l_time_zone_lable_str = QString(id);
    l_time_zone_lable_str +=
        " " + QTimeZone(id).displayName(QDateTime::currentDateTime(),
                                        QTimeZone::OffsetName);

    UIKit::Label *lTimeZoneLabelPtr =
        new UIKit::Label(m_priv_ptr->m_timezone_browser_ptr);
    UIKit::ModelViewItem *l_item = new UIKit::ModelViewItem();

    l_item->set_data("label", l_time_zone_lable_str);
    l_item->set_data("zone_id", id);
    l_item->on_activated([&](UIKit::ModelViewItem *a_item) {
      if (a_item) {
        m_priv_ptr->m_result_data["timezone"] =
            a_item->data("label").toString();
        m_priv_ptr->m_result_data["zone_id"] =
            a_item->data("zone_id").toByteArray();
        notify_done();
      }
    });

    l_item->set_view(lTimeZoneLabelPtr);
    l_item->on_view_removed([&] (UIKit::ModelViewItem *a_item) {
      if (a_item && a_item->view()) {
          UIKit::Widget *view = a_item->view();
          if (view)
            delete view;
      }
    });
    l_item->on_filter([&](const UIKit::Widget *a_view,
                          const QString &a_keyword) {
      const UIKit::Label *_lbl_widget =
          dynamic_cast<const UIKit::Label *>(a_view);

      if (_lbl_widget) {
        if (_lbl_widget->label().toLower().contains(a_keyword.toLower())) {
          return 1;
        }
      }

      return 0;
    });

    lTimeZoneLabelPtr->set_alignment(Qt::AlignLeft);

    lTimeZoneLabelPtr->setMinimumSize(
        m_priv_ptr->m_timezone_browser_ptr->geometry().width(), 32);
    lTimeZoneLabelPtr->set_size(
        QSizeF(m_priv_ptr->m_timezone_browser_ptr->boundingRect().width(), 32));
    lTimeZoneLabelPtr->set_label(l_time_zone_lable_str);
    _item_list.push_back(l_item);
  }
コード例 #8
0
DevicePluginDateTime::DevicePluginDateTime() :
    m_timer(0),
    m_todayDevice(0),
    m_timeZone(QTimeZone("Europe/Vienna")),
    m_dusk(QDateTime()),
    m_sunrise(QDateTime()),
    m_noon(QDateTime()),
    m_sunset(QDateTime()),
    m_dawn(QDateTime())
{
    m_timer = new QTimer(this);
    m_timer->setInterval(1000);

    m_timeZone = QTimeZone(configValue("timezone").toByteArray());
    m_currentDateTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone);

    connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::onSecondChanged);
    connect(this, &DevicePluginDateTime::configValueChanged, this, &DevicePluginDateTime::onConfigValueChanged);
}
コード例 #9
0
void
TimeDateModule::updateFields()
{
    if ( m_timeDate->canNtp() )
        ui->isNtpEnabledCheckBox->setChecked( m_timeDate->isNtpEnabled() );
    else
    {
        ui->isNtpEnabledCheckBox->setChecked( false );
        ui->isNtpEnabledCheckBox->setEnabled( false );
    }

    ui->isRtcLocalCheckBox->setChecked( m_timeDate->isRtcInLocalTimeZone() );

    QTimeZone timeZone = QTimeZone( m_timeZone.toLatin1() );
    if ( timeZone.isValid() )
    {
        ui->timeZoneLabel_2->setText( m_timeZone );
        ui->countryLabel_2->setText( QLocale::countryToString( timeZone.country() ) );

        QIcon yesIcon = QIcon();
        yesIcon.addFile( ":/images/yes.svg", QSize( 16, 16 ) );
        QIcon noIcon = QIcon();
        noIcon.addFile( ":/images/no.svg", QSize( 16, 16 ) );
        if ( timeZone.hasDaylightTime() )
            ui->hasDaylightTimeIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) );
        else
            ui->hasDaylightTimeIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) );
        if ( timeZone.isDaylightTime( QDateTime::currentDateTime() ) )
            ui->isDaylightTimeIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) );
        else
            ui->isDaylightTimeIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) );
        if ( timeZone.hasTransitions() )
            ui->hasTransitionsIcon->setPixmap( yesIcon.pixmap( QSize( 16, 16 ) ) );
        else
            ui->hasTransitionsIcon->setPixmap( noIcon.pixmap( QSize( 16, 16 ) ) );

        QTimeZone::OffsetData offset = timeZone.nextTransition( QDateTime::currentDateTime() );
        if ( offset.atUtc != QDateTime() )
        {
            ui->nextTransitionLabel->setEnabled( true );
            ui->nextTransitionTimeLabel->setEnabled( true );
            ui->nextTransitionTimeLabel->setText( offset.atUtc.toString( "dddd yyyy-MM-dd HH:mm:ss" ) );
        }
        else
        {
            ui->nextTransitionLabel->setEnabled( false );
            ui->nextTransitionTimeLabel->setEnabled( false );
            ui->nextTransitionTimeLabel->setText( tr( "none" ) );
        }
    }
}
コード例 #10
0
ファイル: Wpp.cpp プロジェクト: AndrewDesign/wpp-qt
/*
QDateTime Wpp::makeDateTime(const QString& ianaId, qint64 msecsSinceEpoch)
{
	if ( ianaId.isEmpty() )
		return QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, QTimeZone(getSystemTimezoneId()) );
	else
		return QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, QTimeZone(ianaId.toLatin1()) );
}

QDateTime Wpp::currentDateTime(const QString& ianaId)
{
	return makeDateTime(ianaId, QDateTime::currentMSecsSinceEpoch());
}
*/
QString Wpp::formatDateTime(qint64 msecsSinceEpoch, const QString& format, const QString& ianaId)
{
	//QDateTime dateTime = makeDateTime(ianaId, msecsSinceEpoch);
	QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch);
	QDateTime utc(dateTime.toTimeSpec(Qt::UTC));
	QDateTime tzDateTime = utc.toTimeZone( QTimeZone(ianaId.toLatin1()) );// createTimeZone(ianaId) );
	qDebug() << __FUNCTION__ << ":ianaId=" << ianaId;
	qDebug() << __FUNCTION__ << ":msecsSinceEpoch=" << msecsSinceEpoch;
	qDebug() << __FUNCTION__ << ":format=" << format;
	qDebug() << __FUNCTION__ << ":dateTime=" << dateTime;
	qDebug() << __FUNCTION__ << ":utc=" << utc;
	qDebug() << __FUNCTION__ << ":tzDateTime=" << tzDateTime;
	qDebug() << __FUNCTION__ << ":tzDateTime.toString(format)=" << tzDateTime.toString(format);

	return tzDateTime.toString(format);
}
コード例 #11
0
void LXQtWorldClock::updatePopupContent()
{
    if (mPopupContent)
    {
        QDateTime now = QDateTime::currentDateTime();
        QStringList allTimeZones;
        bool hasTimeZone = formatHasTimeZone(mFormat);

        foreach (QString timeZoneName, mTimeZones)
        {
            if (timeZoneName == QLatin1String("local"))
                timeZoneName = QString::fromLatin1(QTimeZone::systemTimeZoneId());

            QString formatted = formatDateTime(now, timeZoneName);

            if (!hasTimeZone)
                formatted += QLatin1String("<br/>") + QString::fromLatin1(QTimeZone(timeZoneName.toLatin1()).id());

            allTimeZones.append(formatted);
        }

        mPopupContent->setText(allTimeZones.join(QLatin1String("<hr/>")));
    }
}
コード例 #12
0
void LxQtWorldClock::updatePopupContent()
{
    if (mPopupContent)
    {
        QDateTime now = QDateTime::currentDateTime();
        QStringList allTimeZones;

        foreach (QString timeZoneName, mTimeZones)
        {
            QString formatted = formatDateTime(now, timeZoneName);
            switch (mFormatType)
            {
            case FORMAT_SHORT_TIMEONLY:
            case FORMAT_SHORT:
                formatted += QLatin1String("<br/>") + QString::fromLatin1(QTimeZone(timeZoneName.toLatin1()).id());
                break;

            default:;
            }
            allTimeZones.append(formatted);
        }

        mPopupContent->setText(allTimeZones.join(QLatin1String("<hr/>")));
    }
コード例 #13
0
ファイル: deviceplugindatetime.cpp プロジェクト: haklein/guh
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
{
    // check the DeviceClassId
    if(device->deviceClassId() != dateTimeDeviceClassId){
        return DeviceManager::DeviceSetupStatusFailure;
    }

    // make shore there is just one date/time
    if (myDevices().count() != 0 && myDevices().takeFirst()->id() != device->id()) {
        return DeviceManager::DeviceSetupStatusFailure;
    }

    device->setName("Time (" + device->paramValue("timezone").toString() + ")");
    m_timeZone = QTimeZone(device->paramValue("timezone").toByteArray());

    if(m_timeZone.isValid()){
        QDateTime zoneTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone).toLocalTime();
        qCDebug(dcDateTime) << zoneTime.toLocalTime().date() << zoneTime.toLocalTime().time()  << QLocale::countryToString(m_timeZone.country());
        m_timer->start();

        return DeviceManager::DeviceSetupStatusSuccess;
    }
    return DeviceManager::DeviceSetupStatusFailure;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: muromec/qtopia-ezx
QSXE_APP_KEY

#include "qtopiaserverapplication.h"

#include <QDesktopWidget>
#include <QLibraryInfo>

#include <sys/types.h>
#include <unistd.h>

#include <QValueSpaceItem>
#include <QKeyEvent>
#include <ThemedView>

// Not currently supported, available for demonstration purposes.
//#define QTOPIA_ANIMATED_SPLASH

static void refreshTimeZoneConfig()
{
   // We need to help WorldTime in setting up its configuration for
   //   the current translation
    // BEGIN no tr
    const char *defaultTz[] = {
        "America/New_York",
        "Asia/Beijing",
        "America/Los_Angeles",
        "Europe/London",
        "Asia/Tokyo",
        "Europe/Paris",
        0
    };

    // END no tr

    QTimeZone curZone;
    QString zoneID;
    int zoneIndex;
    QSettings cfg( "Trolltech", "WorldTime" );
    cfg.beginGroup( "TimeZones" );
    if (!cfg.contains( "Zone0" )){
        // We have no existing timezones - use the defaults that are untranslated strings
        QString currTz = QTimeZone::current().id();
        QStringList zoneDefaults;
        zoneDefaults.append( currTz );
        for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) {
            if ( defaultTz[i] != currTz )
                zoneDefaults.append( defaultTz[i] );
        }
        zoneIndex = 0;
        for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){
            cfg.setValue( "Zone" + QString::number( zoneIndex ) , *it);
            zoneIndex++;
        }
    }
    // We have an existing list of timezones - refresh the
    //  translations of QTimeZone name
    zoneIndex = 0;
    while (cfg.contains( "Zone"+ QString::number( zoneIndex ))){
        zoneID = cfg.value( "Zone" + QString::number( zoneIndex )).toString();
        curZone = QTimeZone( zoneID.toLatin1() );
        if ( !curZone.isValid() ){
            qWarning( "initEnvironment() Invalid QTimeZone %s", (const char *)zoneID.toLatin1() );
            break;
        }
        zoneIndex++;
    }

}
コード例 #15
0
void NativeDateTimePicker::open()
{
#ifdef Q_OS_ANDROID
	QAndroidJniObject activity = QtAndroid::androidActivity();
	qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();

	//QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod(
	//			"wpp/android/DatePickerDialog", "show", "(Landroid/content/Context;)Ljava/lang/String;", activity.object<jobject>());
	//qDebug() << "str.isValid()=" << str.isValid();

	QDateTime dateTime;
	dateTime.setTimeZone(QTimeZone("UTC"));
	dateTime.setTimeSpec(Qt::UTC);
	dateTime.setTime_t( this->dateTime().toTime_t() );
	QAndroidJniObject initDateISO8601 = QAndroidJniObject::fromString( dateTime.toString(Qt::ISODate) );
	qDebug() << "QT--initDateISO8601=" << initDateISO8601.toString();
	qDebug() << "QT--ts=" << dateTime.toTime_t();

	QAndroidJniObject timezoneId = QAndroidJniObject::fromString( QString( System::getSystemTimezoneId() ) );
	qDebug() << "QT--timezoneId=" << timezoneId.toString();

	jlong qmlDateTimePickerPtr = (jlong)this;

	QAndroidJniObject jsonStr =
			QAndroidJniObject::callStaticObjectMethod(
				"wpp/android/DatePickerDialog", "show",
				"(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;J)Ljava/lang/String;",
				activity.object<jobject>(),
				initDateISO8601.object<jstring>(),
				timezoneId.object<jstring>(),
				qmlDateTimePickerPtr
				);
	/*QAndroidJniObject jsonStr = activity.callObjectMethod(
		"showDatePickerDialog", "()Ljava/lang/String;"
	);*/
			/*QAndroidJniObject::callStaticObjectMethod(
				"com/kuulabu/android/app/MainActivity", "showDatePickerDialog",
				"()Ljava/lang/String;",
				activity.object<jobject>());*/
	qDebug() << "jsonStr.isValid()=" << jsonStr.isValid() << ",jsonStr=" << jsonStr.toString();

	//QAndroidJniObject dialog( "wpp/android/DatePickerDialog", "(Landroid/content/Context;)V", activity.object<jobject>() );
	//qDebug() << "dialog.isValid()=" << dialog.isValid();

	//dialog.callMethod<void>("show","()V");
	//qDebug() << "dialog show ends...";

	QAndroidJniEnvironment env;
	if (env->ExceptionCheck())
	{
		// Handle exception here.
		qDebug() << "Exception 1....";
		env->ExceptionDescribe();
		env->ExceptionClear();
	}

	/*QAndroidJniObject::callStaticObjectMethod(
				"wpp/android/DatePickerDialog", "show",
				"(Landroid/content/Context;)V",
				activity.object<jobject>()
	);*/


	/*

	//android.provider.MediaStore.EXTRA_OUTPUT
	QAndroidJniObject MediaStore__EXTRA_OUTPUT
			= QAndroidJniObject::getStaticObjectField(
				"android/provider/MediaStore", "EXTRA_OUTPUT", "Ljava/lang/String;");
	qDebug() << "MediaStore__EXTRA_OUTPUT.isValid()=" << MediaStore__EXTRA_OUTPUT.isValid();


	QAndroidJniObject action = QAndroidJniObject::fromString("android.media.action.IMAGE_CAPTURE");
	QAndroidJniObject intent=QAndroidJniObject("android/content/Intent","(Ljava/lang/String;)V",
											   action.object<jstring>());
	qDebug() << __FUNCTION__ << "intent.isValid()=" << intent.isValid();

	QAndroidJniObject extDir = QAndroidJniObject::callStaticObjectMethod(
				"android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
	qDebug() << "extDir.isValid()=" << extDir.isValid();

	QAndroidJniObject filename = QAndroidJniObject::fromString("camera.jpg");

	QAndroidJniObject photo=QAndroidJniObject("java/io/File","(Ljava/io/File;Ljava/lang/String;)V",
											   extDir.object<jobject>(), filename.object<jstring>());
	qDebug() << __FUNCTION__ << "photo.isValid()=" << photo.isValid();

	takePhotoSavedUri = QAndroidJniObject::callStaticObjectMethod(
				"android/net/Uri", "fromFile", "(Ljava/io/File;)Landroid/net/Uri;", photo.object<jobject>());
	qDebug() << "takePhotoSavedUri.isValid()=" << takePhotoSavedUri.isValid();

	intent.callObjectMethod(
				"putExtra","(Ljava/lang/String;Landroid/os/Parcelable;)Landroid/content/Intent;",
				MediaStore__EXTRA_OUTPUT.object<jstring>(), takePhotoSavedUri.object<jobject>());
	qDebug() << __FUNCTION__ << "intent.isValid()=" << intent.isValid();

	int SHOOT_PHOTO = 1;
	QtAndroid::startActivity(intent, SHOOT_PHOTO, this);*/
#endif

}
コード例 #16
0
ファイル: worldclock.cpp プロジェクト: OmarRi/worldclock
QString TimeZone::TimeZone::readAllCities()
{
    // get translation list
    QString lines = cityTranslations();

    QSettings settings;
    int sortOrder = settings.value("sortorder_completeList", "").toInt();
    QList<QByteArray> ids =  QTimeZone::availableTimeZoneIds();
    QString output;
    QString sign;
    QString timeoffset;
    QMultiMap<int, QString> map;
    QMultiMap<QString, QString> sorted_map;
    // QMultiMap is sorted by key by default
    // We use QMultiMap (not QMap) so we can have duplicates
    int dummy_counter_for_sort = 0; // to inverse reverted sorting
    foreach (QByteArray id, ids) {
        QTimeZone zone = QTimeZone(id);
        QDateTime zoneTime = QDateTime(QDate::currentDate(), QTime::currentTime(), zone).toLocalTime();
        int offset = zone.offsetFromUtc(QDateTime::currentDateTime());
        QString countryName = QLocale::countryToString(zone.country());
        QString countryNameOrg = countryName;
        // insert space where appropriate. Can't be done in one regex replace?
        QRegularExpression rx("([a-z])([A-Z])");
        QRegularExpressionMatch match = rx.match(countryName);
        for (int i = 1; i <= 6; i++) {
            match = rx.match(countryName);
            if (match.hasMatch()) {
                QString lowerChar1 = match.captured(1);
                QString upperChar1 = match.captured(2);
                countryName.replace(lowerChar1+upperChar1,lowerChar1 + " " + upperChar1);
            }
        }
        int index = lines.indexOf('\n'+countryName+';', 0, Qt::CaseInsensitive);
        if (index != -1) {
            index++;
            // Replace countryName with translation
            countryName = lines.mid(index+countryName.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1);
        }
        if ( countryName == "Default") {
            // UTC name
            countryName = "";
        } else {
            countryName = " [" + countryName + "]";
        }
        if (offset < 0)
            sign = "-";
        else
            sign = "+";
        if((offset % 3600)==0)
            // offset equals to whole hour
            timeoffset = QString("UTC %3").arg(sign+QString::number(abs(offset)/3600));
        else
        {
            int minutes = offset/60 %60;
            timeoffset = QString("UTC %3:%4").arg(sign+QString::number(abs(offset)/3600)).arg(abs(minutes));
        }

        const int delimiter = id.lastIndexOf('/');
        int nbrSlashes = id.count("/");
        QString cityNameTr = id.mid(delimiter + 1).replace("_"," ");
        QString continentTr = id.mid(0, delimiter);
        QString stateTr = "";
        if ( nbrSlashes == 2) {
            // eg (America/North Dakota/Beulah)
            continentTr = id.mid(0, id.indexOf('/')); //first part
            stateTr = id.mid(id.indexOf('/')+1, delimiter - continentTr.length() - 1 ); //second part
        }
        if (!lines.isEmpty()) {
            int index = lines.indexOf(cityNameTr+';', 0, Qt::CaseInsensitive);
            if (index != -1) {
                cityNameTr = lines.mid(index+cityNameTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1);
            }
            index = lines.indexOf(continentTr+';', 0, Qt::CaseInsensitive);
            if (index != -1) {
                continentTr = lines.mid(index+continentTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1);
            }
            if (!stateTr.isEmpty()) {
                index = lines.indexOf(stateTr+';', 0, Qt::CaseInsensitive);
                if (index != -1) {
                    stateTr =  lines.mid(index+stateTr.length()+1, lines.indexOf('\n',index) - lines.indexOf(';',index)-1);
                }
                continentTr = continentTr + "/" + stateTr;
            }
        }
        if (sortOrder == 1) {
            dummy_counter_for_sort ++;
            map.insert(offset + dummy_counter_for_sort,timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg);
        } else if (sortOrder == 2) {
            sorted_map.insert(cityNameTr, timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg);
        } else if (sortOrder == 3) {
            sorted_map.insert(countryName, timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id + ";" + countryNameOrg);
        } else {
            output += timeoffset + " (" + continentTr + "/" + cityNameTr + ")" + countryName + ";" + id +  + ";" + countryNameOrg + "\n";
        }

    }
コード例 #17
0
ファイル: main.cpp プロジェクト: MojaveTom/QtReadEkm
#include <QCoreApplication>
#include <QtCore/QCoreApplication>
#include <QtCore/QCommandLineParser>
#include <QtCore/QCommandLineOption>
#include <QtSql>
#include <QtSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <unistd.h>
#include <stdlib.h>

#include "../SupportRoutines/supportfunctions.h"
#include "messages.h"

/* ********  Global variable declarations  ***************/
QTimeZone LocalTimeZone = QTimeZone(QTimeZone::systemTimeZoneId()); //!< The local timezone, either Standard time or Daylight time.
QTimeZone LocalStandardTimeZone = QTimeZone(LocalTimeZone.standardTimeOffset(QDateTime::currentDateTime())); //!< Timezone for Local Standard time.


/* ********  Global function declarations  ***************/
bool ConnectSerial(const QString &serialDeviceName, QSerialPort **serialPortPtr);
bool SaveV3ResponseToDatabase(const ResponseV3Data &responseData);
bool SaveV4ResponseToDatabase(const uint8_t responseType, const ResponseV4Generic &response);
bool GetMeterV4Data(QSerialPort *serialPort, const QString meterId, const uint8_t requestType, ResponseV4Generic *response);
bool GetMeterV3Data(QSerialPort *serialPort, const QString meterId, ResponseV3Data *response);
bool ReadResponse(QSerialPort *serialPort, qint8 *msg, const qint64 msgSize);
bool WriteSerialMsg(QSerialPort *serialPort, const char *msg, const qint64 msgSize);
bool ValidateCRC(const uint8_t *msg, int numBytes);
bool SendControl(QSerialPort *serialPort, QString &meterId, OutputControlDef *ctrlMsg, const int msgSize);
bool SetMeterTime(QSerialPort *serialPort, QString &meterId);
bool InitializeMeters(QSerialPort *serialPort, const QStringList &args);
コード例 #18
0
ファイル: qgooglecontext.cpp プロジェクト: Camelek/qtmoko
QTimeZone GoogleCalHandler::parseTimeZone(const QString &)
{
    // TODO parse timezone part of strings sent.
    // for now, treat everything as local.
    return QTimeZone();
}
コード例 #19
0
/*!
    \since 5.5
    Returns a QTimeZone object that refers to UTC (Universal Time Coordinated).

    \sa systemTimeZone()
*/
QTimeZone QTimeZone::utc()
{
    return QTimeZone(QTimeZonePrivate::utcQByteArray());
}
コード例 #20
0
/*!
    \since 5.5
    Returns a QTimeZone object that refers to the local system time, as
    specified by systemTimeZoneId().

    \sa utc()
*/
QTimeZone QTimeZone::systemTimeZone()
{
    return QTimeZone(QTimeZone::systemTimeZoneId());
}