pv/mainwindow.cpp
pv/sigsession.cpp
pv/storesession.cpp
+ pv/util.cpp
pv/data/analog.cpp
pv/data/analogsnapshot.cpp
pv/data/logic.cpp
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "util.h"
+
+#include <extdef.h>
+
+#include <assert.h>
+
+#include <QTextStream>
+#include <QDebug>
+
+using namespace Qt;
+
+namespace pv {
+namespace util {
+
+static const QString SIPrefixes[9] =
+ {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
+const int FirstSIPrefixPower = -15;
+
+QString format_time(double t, unsigned int prefix,
+ unsigned int precision, bool sign)
+{
+ assert(prefix < countof(SIPrefixes));
+
+ const double multiplier = pow(10.0,
+ (int)- prefix * 3 - FirstSIPrefixPower);
+
+ QString s;
+ QTextStream ts(&s);
+ if (sign) {
+ ts << forcesign;
+ }
+ ts << fixed << qSetRealNumberPrecision(precision)
+ << (t * multiplier) << SIPrefixes[prefix] << "s";
+
+ return s;
+}
+
+} // namespace util
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_UTIL_H
+#define PULSEVIEW_UTIL_H
+
+#include <math.h>
+
+#include <QString>
+
+namespace pv {
+namespace util {
+
+extern const int FirstSIPrefixPower;
+
+/**
+ * Formats a given time value with the specified SI prefix.
+ * @param t The time value in seconds to format.
+ * @param prefix The number of the prefix, from 0 for 'femto' up to
+ * 8 for 'giga'.
+ * @parma precision The number of digits after the decimal separator.
+ * @param sign Whether or not to add a sign also for positive numbers.
+ *
+ * @return The formated value.
+ */
+QString format_time(
+ double t, unsigned int prefix,
+ unsigned precision = 0, bool sign = true);
+
+} // namespace util
+} // namespace pv
+
+#endif // PULSEVIEW_UTIL_H
#include "cursor.h"
-#include "ruler.h"
#include "view.h"
+#include "pv/util.h"
#include <QBrush>
#include <QPainter>
p.setPen(TextColour);
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
- Ruler::format_time(_time, prefix, 2));
+ pv::util::format_time(_time, prefix, 2));
}
void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
{
_text_size = p.boundingRect(QRectF(), 0,
- Ruler::format_time(_time, prefix, 2)).size();
+ pv::util::format_time(_time, prefix, 2)).size();
}
shared_ptr<Cursor> Cursor::get_other_cursor() const
#include "cursorpair.h"
-#include "ruler.h"
#include "view.h"
+#include "pv/util.h"
#include <algorithm>
p.setPen(Cursor::TextColour);
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
- Ruler::format_time(_second->time() - _first->time(), prefix, 2));
+ pv::util::format_time(_second->time() - _first->time(), prefix, 2));
}
// Paint the cursor markers
assert(_first);
assert(_second);
- _text_size = p.boundingRect(QRectF(), 0, Ruler::format_time(
+ _text_size = p.boundingRect(QRectF(), 0, pv::util::format_time(
_second->time() - _first->time(), prefix, 2)).size();
}
#include "cursor.h"
#include "view.h"
#include "viewport.h"
+#include "pv/util.h"
#include <extdef.h>
-#include <assert.h>
-#include <math.h>
-#include <limits.h>
-
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
const int Ruler::MinorTickSubdivision = 4;
const int Ruler::ScaleUnits[3] = {1, 2, 5};
-const QString Ruler::SIPrefixes[9] =
- {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
-const int Ruler::FirstSIPrefixPower = -15;
-
const int Ruler::HoverArrowSize = 5;
Ruler::Ruler(View &parent) :
update();
}
-QString Ruler::format_time(double t, unsigned int prefix,
- unsigned int precision)
-{
- const double multiplier = pow(10.0,
- (int)- prefix * 3 - FirstSIPrefixPower);
-
- QString s;
- QTextStream ts(&s);
- ts.setRealNumberPrecision(precision);
- ts << fixed << forcesign << (t * multiplier) <<
- SIPrefixes[prefix] << "s";
- return s;
-}
QSize Ruler::sizeHint() const
{
tick_period = order_decimal * ScaleUnits[unit++];
} while (tick_period < min_period && unit < countof(ScaleUnits));
- prefix = (order - FirstSIPrefixPower) / 3;
- assert(prefix < countof(SIPrefixes));
-
+ prefix = (order - pv::util::FirstSIPrefixPower) / 3;
typical_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
- AlignLeft | AlignTop, format_time(_view.offset(),
+ AlignLeft | AlignTop, pv::util::format_time(_view.offset(),
prefix)).width() + MinValueSpacing;
min_width += SpacingIncrement;
// Draw a major tick
p.drawText(x, ValueMargin, 0, text_height,
AlignCenter | AlignTop | TextDontClip,
- format_time(t, prefix));
+ pv::util::format_time(t, prefix));
p.drawLine(QPointF(x, major_tick_y1),
QPointF(x, tick_y2));
}
static const int MinorTickSubdivision;
static const int ScaleUnits[3];
- static const QString SIPrefixes[9];
- static const int FirstSIPrefixPower;
-
static const int HoverArrowSize;
public:
void clear_selection();
- static QString format_time(double t, unsigned int prefix,
- unsigned precision = 0);
-
public:
QSize sizeHint() const;