Commit ab6a1f99 authored by Stefan Gerlach's avatar Stefan Gerlach

code style fixes

parent 494c8e31
......@@ -139,7 +139,7 @@ bool AbstractFilter::input(int port, const AbstractColumn* source) {
inputAboutToBeDisconnected(old_input);
m_inputs[port] = source;
if (source) { // we have a new source
DEBUG(" new source");
// DEBUG(" new source");
if(old_input && source->columnMode() != old_input->columnMode())
inputModeAboutToChange(source);
inputDataChanged(source);
......@@ -182,7 +182,7 @@ bool AbstractFilter::input(int port, const AbstractColumn* source) {
QObject::connect(source, SIGNAL(aboutToBeDestroyed(const AbstractColumn*)),
this, SLOT(inputAboutToBeDestroyed(const AbstractColumn*)));
} else { // source==0, that is, the input port has been disconnected
DEBUG(" no source");
// DEBUG(" no source");
// try to shrink m_inputs
int num_connected_inputs = m_inputs.size();
while (m_inputs.at(num_connected_inputs-1) == 0) {
......
......@@ -34,27 +34,26 @@
#include <cmath>
//! Conversion filter QDateTime -> double (using Julian day).
class DateTime2DoubleFilter : public AbstractSimpleFilter
{
class DateTime2DoubleFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual double valueAt(int row) const {
if (!m_inputs.value(0)) return NAN;
QDateTime input_value = m_inputs.value(0)->dateTimeAt(row);
if (!input_value.isValid()) return NAN;
return double(input_value.date().toJulianDay()) +
double( -input_value.time().msecsTo(QTime(12,0,0,0)) ) / 86400000.0;
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Numeric; }
protected:
//! Using typed ports: only DateTime inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::DateTime;
}
public:
virtual double valueAt(int row) const {
if (!m_inputs.value(0)) return NAN;
QDateTime input_value = m_inputs.value(0)->dateTimeAt(row);
if (!input_value.isValid()) return NAN;
return double(input_value.date().toJulianDay()) +
double( -input_value.time().msecsTo(QTime(12,0,0,0)) ) / 86400000.0;
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Numeric; }
protected:
//! Using typed ports: only DateTime inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::DateTime;
}
};
#endif // ifndef DATE_TIME2DOUBLE_FILTER_H
......
......@@ -35,26 +35,25 @@
#include <cmath>
//! Conversion filter QDateTime -> double, translating dates into days of the week (Monday -> 1).
class DayOfWeek2DoubleFilter : public AbstractSimpleFilter
{
class DayOfWeek2DoubleFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual double valueAt(int row) const {
if (!m_inputs.value(0)) return NAN;
QDate date = m_inputs.value(0)->dateAt(row);
if (!date.isValid()) return NAN;
return double(date.dayOfWeek());
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Numeric; }
protected:
//! Using typed ports: only date-time inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Day;
}
public:
virtual double valueAt(int row) const {
if (!m_inputs.value(0)) return NAN;
QDate date = m_inputs.value(0)->dateAt(row);
if (!date.isValid()) return NAN;
return double(date.dayOfWeek());
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Numeric; }
protected:
//! Using typed ports: only date-time inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Day;
}
};
#endif // ifndef DAY_OF_WEEK2DOUBLE_FILTER_H
......
......@@ -35,37 +35,36 @@
#include <cmath>
//! Conversion filter double -> QDateTime, interpreting the input numbers as (fractional) Julian days.
class Double2DateTimeFilter : public AbstractSimpleFilter
{
class Double2DateTimeFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDate();
return QDate::fromJulianDay(qRound(inputValue));
}
virtual QTime timeAt(int row) const {
if (!m_inputs.value(0)) return QTime();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QTime();
// we only want the digits behind the dot and
// convert them from fraction of day to milliseconds
return QTime(12,0,0,0).addMSecs(int( (inputValue - int(inputValue)) * 86400000.0 ));
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDate();
return QDate::fromJulianDay(qRound(inputValue));
}
virtual QTime timeAt(int row) const {
if (!m_inputs.value(0)) return QTime();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QTime();
// we only want the digits behind the dot and
// convert them from fraction of day to milliseconds
return QTime(12,0,0,0).addMSecs(int( (inputValue - int(inputValue)) * 86400000.0 ));
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::DateTime; }
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::DateTime; }
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
};
#endif // ifndef DOUBLE2DATE_TIME_FILTER_H
......
......@@ -35,34 +35,34 @@
#include <cmath>
//! Conversion filter double -> QDateTime, interpreting the input numbers as days of the week (1 = Monday).
class Double2DayOfWeekFilter : public AbstractSimpleFilter
{
class Double2DayOfWeekFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDate();
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead (a Monday)
return QDate(1900,1,1).addDays(qRound(inputValue - 1.0));
}
virtual QTime timeAt(int row) const {
Q_UNUSED(row)
return QTime(0,0,0,0);
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Day; }
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDate();
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead (a Monday)
return QDate(1900,1,1).addDays(qRound(inputValue - 1.0));
}
virtual QTime timeAt(int row) const {
Q_UNUSED(row)
return QTime(0,0,0,0);
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Day; }
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
};
#endif // ifndef DOUBLE2DAY_OF_WEEK_FILTER_H
......@@ -35,34 +35,34 @@
#include <cmath>
//! Conversion filter double -> QDateTime, interpreting the input numbers as months of the year.
class Double2MonthFilter : public AbstractSimpleFilter
{
class Double2MonthFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual QDate dateAt(int row) const {
return dateTimeAt(row).date();
}
virtual QTime timeAt(int row) const {
return dateTimeAt(row).time();
}
virtual QDateTime dateTimeAt(int row) const {
if (!m_inputs.value(0)) return QDateTime();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDateTime();
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead
QDate result_date = QDate(1900,1,1).addMonths(qRound(inputValue - 1.0));
QTime result_time = QTime(0,0,0,0);
return QDateTime(result_date, result_time);
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Month; }
public:
virtual QDate dateAt(int row) const {
return dateTimeAt(row).date();
}
virtual QTime timeAt(int row) const {
return dateTimeAt(row).time();
}
virtual QDateTime dateTimeAt(int row) const {
if (!m_inputs.value(0)) return QDateTime();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QDateTime();
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead
QDate result_date = QDate(1900,1,1).addMonths(qRound(inputValue - 1.0));
QTime result_time = QTime(0,0,0,0);
return QDateTime(result_date, result_time);
}
protected:
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Month; }
protected:
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
};
#endif // ifndef DOUBLE2MONTH_FILTER_H
......
......@@ -34,115 +34,98 @@
#include <KLocale>
class Double2StringFilterSetFormatCmd : public QUndoCommand
{
public:
Double2StringFilterSetFormatCmd(Double2StringFilter* target, char new_format);
class Double2StringFilterSetFormatCmd : public QUndoCommand {
public:
Double2StringFilterSetFormatCmd(Double2StringFilter* target, char new_format);
virtual void redo();
virtual void undo();
virtual void redo();
virtual void undo();
private:
Double2StringFilter* m_target;
char m_other_format;
private:
Double2StringFilter* m_target;
char m_other_format;
};
class Double2StringFilterSetDigitsCmd : public QUndoCommand
{
public:
Double2StringFilterSetDigitsCmd(Double2StringFilter* target, int new_digits);
class Double2StringFilterSetDigitsCmd : public QUndoCommand {
public:
Double2StringFilterSetDigitsCmd(Double2StringFilter* target, int new_digits);
virtual void redo();
virtual void undo();
virtual void redo();
virtual void undo();
private:
Double2StringFilter* m_target;
int m_other_digits;
private:
Double2StringFilter* m_target;
int m_other_digits;
};
void Double2StringFilter::writeExtraAttributes(QXmlStreamWriter * writer) const
{
void Double2StringFilter::writeExtraAttributes(QXmlStreamWriter * writer) const {
writer->writeAttribute("format", QString(QChar(numericFormat())));
writer->writeAttribute("digits", QString::number(numDigits()));
}
bool Double2StringFilter::load(XmlStreamReader * reader)
{
bool Double2StringFilter::load(XmlStreamReader * reader) {
QXmlStreamAttributes attribs = reader->attributes();
QString format_str = attribs.value(reader->namespaceUri().toString(), "format").toString();
QString digits_str = attribs.value(reader->namespaceUri().toString(), "digits").toString();
if (AbstractSimpleFilter::load(reader))
{
if (AbstractSimpleFilter::load(reader)) {
bool ok;
int digits = digits_str.toInt(&ok);
if( (format_str.size() != 1) || !ok )
if ( (format_str.size() != 1) || !ok ) {
reader->raiseError(i18n("missing or invalid format attribute"));
else
{
} else {
setNumericFormat( format_str.at(0).toAscii() );
setNumDigits( digits );
}
}
else
} else
return false;
return !reader->hasError();
}
void Double2StringFilter::setNumericFormat(char format)
{
void Double2StringFilter::setNumericFormat(char format) {
exec(new Double2StringFilterSetFormatCmd(this, format));
}
void Double2StringFilter::setNumDigits(int digits)
{
void Double2StringFilter::setNumDigits(int digits) {
exec(new Double2StringFilterSetDigitsCmd(this, digits));
}
Double2StringFilterSetFormatCmd::Double2StringFilterSetFormatCmd(Double2StringFilter* target, char new_format)
: m_target(target), m_other_format(new_format)
{
: m_target(target), m_other_format(new_format) {
if(m_target->parentAspect())
setText(i18n("%1: set numeric format to '%2'", m_target->parentAspect()->name(), new_format));
else
setText(i18n("set numeric format to '%1'", new_format));
}
void Double2StringFilterSetFormatCmd::redo()
{
void Double2StringFilterSetFormatCmd::redo() {
char tmp = m_target->m_format;
m_target->m_format = m_other_format;
m_other_format = tmp;
emit m_target->formatChanged();
}
void Double2StringFilterSetFormatCmd::undo()
{
void Double2StringFilterSetFormatCmd::undo() {
redo();
}
Double2StringFilterSetDigitsCmd::Double2StringFilterSetDigitsCmd(Double2StringFilter* target, int new_digits)
: m_target(target), m_other_digits(new_digits)
{
: m_target(target), m_other_digits(new_digits) {
if(m_target->parentAspect())
setText(i18n("%1: set decimal digits to %2", m_target->parentAspect()->name(), new_digits));
else
setText(i18n("set decimal digits to %1", new_digits));
}
void Double2StringFilterSetDigitsCmd::redo()
{
void Double2StringFilterSetDigitsCmd::redo() {
int tmp = m_target->m_digits;
m_target->m_digits = m_other_digits;
m_other_digits = tmp;
emit m_target->digitsChanged();
}
void Double2StringFilterSetDigitsCmd::undo()
{
void Double2StringFilterSetDigitsCmd::undo() {
redo();
}
......@@ -34,56 +34,53 @@
#include <cmath>
//! Locale-aware conversion filter double -> QString.
class Double2StringFilter : public AbstractSimpleFilter
{
class Double2StringFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
//! Standard constructor.
explicit Double2StringFilter(char format='e', int digits=6) : m_format(format), m_digits(digits) {}
//! Set format character as in QString::number
void setNumericFormat(char format);
//! Set number of displayed digits
void setNumDigits(int digits);
//! Get format character as in QString::number
char numericFormat() const { return m_format; }
//! Get number of displayed digits
int numDigits() const { return m_digits; }
public:
//! Standard constructor.
explicit Double2StringFilter(char format='e', int digits=6) : m_format(format), m_digits(digits) {}
//! Set format character as in QString::number
void setNumericFormat(char format);
//! Set number of displayed digits
void setNumDigits(int digits);
//! Get format character as in QString::number
char numericFormat() const { return m_format; }
//! Get number of displayed digits
int numDigits() const { return m_digits; }
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Text; }
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Text; }
private:
friend class Double2StringFilterSetFormatCmd;
friend class Double2StringFilterSetDigitsCmd;
//! Format character as in QString::number
char m_format;
//! Display digits or precision as in QString::number
int m_digits;
private:
friend class Double2StringFilterSetFormatCmd;
friend class Double2StringFilterSetDigitsCmd;
//! Format character as in QString::number
char m_format;
//! Display digits or precision as in QString::number
int m_digits;
//! \name XML related functions
//@{
virtual void writeExtraAttributes(QXmlStreamWriter * writer) const;
virtual bool load(XmlStreamReader * reader);
//@}
public:
virtual QString textAt(int row) const {
//DEBUG("Double2String::textAt()");
if (!m_inputs.value(0)) return QString();
if (m_inputs.value(0)->rowCount() <= row) return QString();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QString();
return QLocale().toString(inputValue, m_format, m_digits);
}
//! \name XML related functions
//@{
virtual void writeExtraAttributes(QXmlStreamWriter * writer) const;
virtual bool load(XmlStreamReader * reader);
//@}
public:
virtual QString textAt(int row) const {
//DEBUG("Double2String::textAt()");
if (!m_inputs.value(0)) return QString();
if (m_inputs.value(0)->rowCount() <= row) return QString();
double inputValue = m_inputs.value(0)->valueAt(row);
if (std::isnan(inputValue)) return QString();
return QLocale().toString(inputValue, m_format, m_digits);
}
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
protected:
//! Using typed ports: only double inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {
return source->columnMode() == AbstractColumn::Numeric;
}
};
#endif // ifndef DOUBLE2STRING_FILTER_H
......
......@@ -31,36 +31,35 @@
#include "../AbstractSimpleFilter.h"
#include <QDateTime>
#include <cmath>
//! Conversion filter int -> QDateTime, interpreting the input numbers as days of the week (1 = Monday).
class Integer2DayOfWeekFilter : public AbstractSimpleFilter
{
class Integer2DayOfWeekFilter : public AbstractSimpleFilter {
Q_OBJECT
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
int inputValue = m_inputs.value(0)->integerAt(row);
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead (a Monday)
return QDate(1900,1,1).addDays(inputValue);
}
virtual QTime timeAt(int row) const {
Q_UNUSED(row)
return QTime(0,0,0,0);
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
//! Return the data type of the column
virtual AbstractColumn::ColumnMode columnMode() const { return AbstractColumn::Day; }
public:
virtual QDate dateAt(int row) const {
if (!m_inputs.value(0)) return QDate();
int inputValue = m_inputs.value(0)->integerAt(row);
// Don't use Julian days here since support for years < 1 is bad
// Use 1900-01-01 instead (a Monday)
return QDate(1900,1,1).addDays(inputValue);
}
virtual QTime timeAt(int row) const {
Q_UNUSED(row)
return QTime(0,0,0,0);
}
virtual QDateTime dateTimeAt(int row) const {
return QDateTime(dateAt(row), timeAt(row));
}
protected:
//! Using typed ports: only integer inputs are accepted.
virtual bool inputAcceptable(int, const AbstractColumn *source) {