Esempio n. 1
0
int main() {

    GpxFile gpx("data/quandry.gpx");

    qDebug() << "Total distance: " << meter2mile(gpx.length()) << " miles";
    qDebug() << "Total duration: " << formatDuration(gpx.duration());
    qDebug() << "Max speed: " << meterPerSecond2MilePerHour(gpx.maxSpeed()) << " mph";
    qDebug() << "Average speed: " << meterPerSecond2MilePerHour(gpx.averageSpeed()) << " mph";

    qDebug() << "\nNumber of segments: " << gpx.segmentCount();

    for (int i=0; i<gpx.segmentCount(); ++i) {
        qDebug() << "Segment " << (i+1) << " has " <<
            gpx[i].pointCount() << " points, "
            "length " << meter2mile(gpx[i].length()) << " miles, "
            "duration " << formatDuration(gpx[i].duration()) <<
            "max speed of " << meterPerSecond2MilePerHour(gpx[i].maxSpeed()) << " mph, "
            "and average speed of " << meterPerSecond2MilePerHour(gpx[i].averageSpeed()) << " mph";
    }

    testBounds();

    testFuncCallOp();

    testMerge();
    qDebug() << "All tests passed.";
    return 0;
}
Esempio n. 2
0
void GpxTreeWidget::recompute() {
    if (root) {
        root->setText(0, tr("GpxFile"));
        root->setText(2, tr("%1").arg(meter2mile(_gpx->length()), 2,'f',2));
        root->setText(3, tr("%1").arg(_gpx->pointCount()));
        root->setText(4, tr("%1").arg(formatDuration(_gpx->duration(), true)));
        root->setText(5, tr("%1").arg(meterPerSecond2MilePerHour(_gpx->maxSpeed()), 2,'f',2));
        root->setText(6, tr("%1").arg(meterPerSecond2MilePerHour(_gpx->averageSpeed()), 2,'f',2));

        QTreeWidgetItem *track = root;

        for (int i=0; i<_gpx->segmentCount(); ++i) {
            track = itemBelow(track);
            if (track == 0) return;
            GpxTrackSegment cur = (*_gpx)[i];
            track->setText(0, tr("Track %1").arg(cur.number()));

            track->setText(1, tr("%1").arg(cur.name()));
            track->setText(2, tr("%1").arg(meter2mile(cur.length()), 2, 'f', 2));
            track->setText(3, tr("%1").arg(cur.pointCount()));
            track->setText(4, tr("%1").arg(formatDuration(cur.duration(), true)));
            track->setText(5, tr("%1").arg(meterPerSecond2MilePerHour(cur.maxSpeed()), 2,'f',2));
            track->setText(6, tr("%1").arg(meterPerSecond2MilePerHour(cur.averageSpeed()), 2,'f',2));
        }
    }

}
Esempio n. 3
0
void EnterVacationDialog::createEvents()
{
    const EventList events = createEventList( m_ui->startDate->date(),
                                              m_ui->endDate->date().addDays( 1 ),
                                              m_ui->hoursSpinBox->value() * 60 + m_ui->minutesSpinBox->value(),
                                              m_selectedTaskId );

    QDialog confirmationDialog( this );
    QVBoxLayout* layout = new QVBoxLayout( &confirmationDialog );

    QLabel* label = new QLabel( tr( "The following vacation events will be created." ) );
    label->setWordWrap( true );
    layout->addWidget( label );
    QTextBrowser* textBrowser = new QTextBrowser;
    layout->addWidget( textBrowser );
    QDialogButtonBox* box = new QDialogButtonBox;
    box->setStandardButtons( QDialogButtonBox::Ok|QDialogButtonBox::Cancel );
    box->button(QDialogButtonBox::Ok)->setText(tr("Create"));
    connect( box, SIGNAL(accepted()), &confirmationDialog, SLOT(accept()) );
    connect( box, SIGNAL(rejected()), &confirmationDialog, SLOT(reject()) );
    layout->addWidget( box );


    const QString startDate = m_ui->startDate->date().toString( Qt::TextDate );
    const QString endDate = m_ui->endDate->date().toString( Qt::TextDate );
    const Task task = DATAMODEL->getTask( m_selectedTaskId );

    const QString htmlStartDate = toHtmlEscaped( startDate );
    const QString htmlEndDate = toHtmlEscaped( endDate );
    const QString htmlTaskName = toHtmlEscaped( task.name() );

    QString html = "<html><body>";
    html += QString::fromLatin1("<h1>%1</h1>").arg( tr("Vacation"));
    html += QString::fromLatin1("<h3>%1</h3>").arg( tr("From %1 to %2").arg( htmlStartDate, htmlEndDate ) );
    html += QString::fromLatin1("<h4>%1</h4>").arg( tr("Task used: %1").arg( htmlTaskName ) );
    html += "<p>";
    Q_FOREACH ( const Event& event, events ) {
        const QDate eventStart = event.startDateTime().date();
        const QDate eventEnd = event.endDateTime().date();
        Q_ASSERT( eventStart == eventEnd );
        Q_UNUSED( eventEnd ) //release mode
        const QString shortDate = eventStart.toString( Qt::DefaultLocaleShortDate );
        const QString duration = formatDuration( event.startDateTime(), event.endDateTime() );

        const QString htmlShortDate = toHtmlEscaped( shortDate );
        const QString htmlDuration = toHtmlEscaped( duration );

        html += QString::fromLatin1("%1").arg( tr( "%1: %3", "short date, duration" ).arg( htmlShortDate, htmlDuration ) );
        html += "</p><p>";
    }
    html += "</p>";
    html += "</body></html>";
    textBrowser->setHtml( html );
    confirmationDialog.resize( 400, 600 );
    if ( confirmationDialog.exec() == QDialog::Accepted )
        m_events = events;
}
Esempio n. 4
0
void RootContainer::outputObject(NPT_XmlSerializer& xml, const Object *obj, const NPT_String& resUriTmpl)
{
	xml.StartElement("dc", "title");
	xml.Text(obj->title());
	xml.EndElement("dc", "title");

	if (!obj->creator().IsEmpty()) {
		xml.StartElement("dc", "creator");
		xml.Text(obj->creator());
		xml.EndElement("dc", "creator");
	}

	if (!obj->date().IsEmpty()) {
		xml.StartElement("dc", "date");
		xml.Text(obj->date());
		xml.EndElement("dc", "date");
	}

	xml.StartElement("upnp", "class");
	if (!obj->classDesc().IsEmpty()) {
		xml.Attribute(NULL, "name", obj->classDesc());
	}
	xml.Text(obj->className());
	xml.EndElement("upnp", "class");

	if (!obj->mimeType().IsEmpty() && !obj->fileSystemPath().IsEmpty()) {
		xml.StartElement(NULL, "res");
		//xml.Attribute(NULL, "protocolInfo", NPT_String::Format("http-get:*:%s:DLNA.ORG_PN=JPEG_SM;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00d00000000000000000000000000000", obj->mimeType().GetChars()));
		xml.Attribute(NULL, "protocolInfo", NPT_String::Format("http-get:*:%s:*", obj->mimeType().GetChars()));
		if (obj->size() != NO_VALUE) {
			xml.Attribute(NULL, "size", NPT_String::FromIntegerU(obj->size()));
		}

		if (obj->duration() != NO_VALUE) {
			xml.Attribute(NULL, "duration", formatDuration(obj->duration()));
		}

		NPT_String uu = NPT_String::Format(resUriTmpl, obj->id().GetChars());
		xml.Text(uu);
/*		if (obj->className().StartsWith("object.item.imageItem")) {
			xml.StartElement("upnp", "album");
			xml.Text("[unknown]");
			xml.EndElement("upnp", "album");
			xml.StartElement("upnp", "albumArtURI");
			xml.Text(uu);
			xml.EndElement("upnp", "albumArtURI");
		}*/
		//xml.Text("http://img0.pconline.com.cn/pconline/test/focus/bbs/1111/88.jpg");

		xml.EndElement(NULL, "res");
	}

}
Esempio n. 5
0
QVariant QtHistory::data(const QModelIndex& index, int role) const {
	if (index.row() < 0 || index.row() >= _mementoIdList.size()) {
		return QVariant();
	}
	int id = _mementoIdList[index.row()];
	HistoryMementoCollection * collection = _cHistory.getHistory().getHistoryMementoCollection();
	HistoryMemento* memento = collection->getMemento(id);
	if (!memento) {
		LOG_ERROR("Couldn't get memento for id " + String::fromNumber(id));
		return QVariant();
	}

	if (role == Qt::DisplayRole) {
		switch (index.column()) {
		case 0:
			return textForMementoState(memento->getState());

		case 1:
			return QVariant(formatName(memento->getPeer(), _isWengoAccountConnected));

		case 2:
			return QVariant(formatDate(qDateTimeForMemento(memento)));
		case 3:
			//VOXOX - CJC - 2009.05.31 Only show duration for calls
			if(memento->getState() == HistoryMemento::OutgoingCall || memento->getState()== HistoryMemento::IncomingCall
				||memento->getState() == HistoryMemento::MissedCall || memento->getState() == HistoryMemento::RejectedCall){
					return QVariant(formatDuration(qTimeForDuration(memento->getDuration())));
				}else{
					return QVariant("");
			}

		default:
			return QVariant();
		}
	} else if (role == Qt::DecorationRole) {
		if (index.column() == 0) {
			return QVariant(iconForMementoState(memento->getState()));
		} else {
			return QVariant();
		}
	} else if (role == Qt::UserRole) {
		return QVariant(id);
	}
	return QVariant();
}
Esempio n. 6
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    std::cout << formatDuration(0) << std::endl;
    std::cout << formatDuration(1) << std::endl;
    std::cout << formatDuration(2) << std::endl;
    std::cout << formatDuration(59) << std::endl;
    std::cout << formatDuration(60) << std::endl;
    std::cout << formatDuration(61) << std::endl;
    std::cout << formatDuration(300) << std::endl;
    std::cout << formatDuration(900) << std::endl;
    std::cout << formatDuration(1800) << std::endl;
    std::cout << formatDuration(3600) << std::endl;
    std::cout << formatDuration(3601) << std::endl;
    std::cout << formatDuration(86423) << std::endl;
    std::cout << formatDuration(1234567) << std::endl;
}
Esempio n. 7
0
QString KLocale::formatDuration(unsigned long mSec) const
{
    return d->formatDuration(mSec);
}
Esempio n. 8
0
std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
{
  std::stringstream before;
  bool verbose = context.verbose ("edit");

  if (verbose)
    before << "# " << STRING_EDIT_HEADER_1 << "\n"
           << "# " << STRING_EDIT_HEADER_2 << "\n"
           << "# " << STRING_EDIT_HEADER_3 << "\n"
           << "# " << STRING_EDIT_HEADER_4 << "\n"
           << "# " << STRING_EDIT_HEADER_5 << "\n"
           << "# " << STRING_EDIT_HEADER_6 << "\n"
           << "#\n"
           << "# " << STRING_EDIT_HEADER_7 << "\n"
           << "# " << STRING_EDIT_HEADER_8 << "\n"
           << "# " << STRING_EDIT_HEADER_9 << "\n"
           << "#\n"
           << "# " << STRING_EDIT_HEADER_10 << "\n"
           << "# " << STRING_EDIT_HEADER_11 << "\n"
           << "# " << STRING_EDIT_HEADER_12 << "\n"
           << "#\n";

  before << "# " << STRING_EDIT_TABLE_HEADER_1 << "\n"
         << "# " << STRING_EDIT_TABLE_HEADER_2 << "\n"
         << "# ID:                " << task.id                                          << "\n"
         << "# UUID:              " << task.get ("uuid")                                << "\n"
         << "# Status:            " << ucFirst (Task::statusToText (task.getStatus ())) << "\n"  // L10N safe ucFirst.
         << "# Mask:              " << task.get ("mask")                                << "\n"
         << "# iMask:             " << task.get ("imask")                               << "\n"
         << "  Project:           " << task.get ("project")                             << "\n";

  std::vector <std::string> tags;
  task.getTags (tags);
  std::string allTags;
  join (allTags, " ", tags);

  if (verbose)
    before << "# " << STRING_EDIT_TAG_SEP << "\n";

  before << "  Tags:              " << allTags                                          << "\n"
         << "  Description:       " << task.get ("description")                         << "\n"
         << "  Created:           " << formatDate (task, "entry", dateformat)           << "\n"
         << "  Started:           " << formatDate (task, "start", dateformat)           << "\n"
         << "  Ended:             " << formatDate (task, "end", dateformat)             << "\n"
         << "  Scheduled:         " << formatDate (task, "scheduled", dateformat)       << "\n"
         << "  Due:               " << formatDate (task, "due", dateformat)             << "\n"
         << "  Until:             " << formatDate (task, "until", dateformat)           << "\n"
         << "  Recur:             " << task.get ("recur")                               << "\n"
         << "  Wait until:        " << formatDate (task, "wait", dateformat)            << "\n"
         << "# Modified:          " << formatDate (task, "modified", dateformat)        << "\n"
         << "  Parent:            " << task.get ("parent")                              << "\n";

  if (verbose)
    before << "# " << STRING_EDIT_HEADER_13 << "\n"
           << "# " << STRING_EDIT_HEADER_14 << "\n"
           << "# " << STRING_EDIT_HEADER_15 << "\n";

  std::map <std::string, std::string> annotations;
  task.getAnnotations (annotations);
  std::map <std::string, std::string>::iterator anno;
  for (anno = annotations.begin (); anno != annotations.end (); ++anno)
  {
    Date dt (strtol (anno->first.substr (11).c_str (), NULL, 10));
    before << "  Annotation:        " << dt.toString (dateformat)
           << " -- "                  << anno->second << "\n";
  }

  Date now;
  before << "  Annotation:        " << now.toString (dateformat) << " -- \n";

  // Add dependencies here.
  std::vector <std::string> dependencies;
  task.getDependencies (dependencies);
  std::stringstream allDeps;
  for (unsigned int i = 0; i < dependencies.size (); ++i)
  {
    if (i)
      allDeps << ",";

    Task t;
    context.tdb2.get (dependencies[i], t);
    if (t.getStatus () == Task::pending ||
        t.getStatus () == Task::waiting)
      allDeps << t.id;
    else
      allDeps << dependencies[i];
  }

  if (verbose)
    before << "# " << STRING_EDIT_DEP_SEP << "\n";

  before << "  Dependencies:      " << allDeps.str () << "\n";

  // UDAs
  std::vector <std::string> udas;
  std::map <std::string, Column*>::iterator col;
  for (col = context.columns.begin (); col != context.columns.end (); ++col)
    if (context.config.get ("uda." + col->first + ".type") != "")
      udas.push_back (col->first);

  if (udas.size ())
  {
    before << "# " << STRING_EDIT_UDA_SEP << "\n";
    std::sort (udas.begin (), udas.end ());
    std::vector <std::string>::iterator uda;
    for (uda = udas.begin (); uda != udas.end (); ++uda)
    {
      int pad = 13 - uda->length ();
      std::string padding = "";
      if (pad > 0)
        padding = std::string (pad, ' ');

      std::string type = context.config.get ("uda." + *uda + ".type");
      if (type == "string" || type == "numeric")    
        before << "  UDA " << *uda << ": " << padding << task.get (*uda) << "\n";
      else if (type == "date")
        before << "  UDA " << *uda << ": " << padding << formatDate (task, *uda, dateformat) << "\n";
      else if (type == "duration")
        before << "  UDA " << *uda << ": " << padding << formatDuration (task, *uda) << "\n";
    }
  }

  // UDA orphans
  std::vector <std::string> orphans;
  task.getUDAOrphans (orphans);

  if (orphans.size ())
  {
    before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n";
    std::sort (orphans.begin (), orphans.end ());
    std::vector <std::string>::iterator orphan;
    for (orphan = orphans.begin (); orphan != orphans.end (); ++orphan)
    {
      int pad = 6 - orphan->length ();
      std::string padding = "";
      if (pad > 0)
        padding = std::string (pad, ' ');

      before << "  UDA Orphan " << *orphan << ": " << padding << task.get (*orphan) << "\n";
    }
  }

  before << "# " << STRING_EDIT_END << "\n";
  return before.str ();
}