---
CMakeLists.txt | 1 +
pv/util.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
pv/util.h | 50 ++++++++++++++++++++++++++++++++++++++++++
pv/view/cursor.cpp | 6 ++---
pv/view/cursorpair.cpp | 6 ++---
pv/view/ruler.cpp | 30 ++++---------------------
pv/view/ruler.h | 6 -----
7 files changed, 120 insertions(+), 38 deletions(-)
create mode 100644 pv/util.cpp
create mode 100644 pv/util.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50dde49..a6a6c40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,6 +121,7 @@ set(pulseview_SOURCES
pv/mainwindow.cpp
pv/sigsession.cpp
pv/storesession.cpp
+ pv/util.cpp
pv/data/analog.cpp
pv/data/analogsnapshot.cpp
pv/data/logic.cpp
diff --git a/pv/util.cpp b/pv/util.cpp
new file mode 100644
index 0000000..28e0dfd
--- /dev/null
+++ b/pv/util.cpp
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <[email protected]>
+ *
+ * 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
diff --git a/pv/util.h b/pv/util.h
new file mode 100644
index 0000000..1af3ce9
--- /dev/null
+++ b/pv/util.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <[email protected]>
+ *
+ * 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
diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp
index ca22eef..95134b7 100644
--- a/pv/view/cursor.cpp
+++ b/pv/view/cursor.cpp
@@ -20,8 +20,8 @@
#include "cursor.h"
-#include "ruler.h"
#include "view.h"
+#include "pv/util.h"
#include <QBrush>
#include <QPainter>
@@ -139,13 +139,13 @@ void Cursor::paint_label(QPainter &p, const QRect &rect,
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
diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp
index ed8829d..f73567e 100644
--- a/pv/view/cursorpair.cpp
+++ b/pv/view/cursorpair.cpp
@@ -20,8 +20,8 @@
#include "cursorpair.h"
-#include "ruler.h"
#include "view.h"
+#include "pv/util.h"
#include <algorithm>
@@ -99,7 +99,7 @@ void CursorPair::draw_markers(QPainter &p,
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
@@ -137,7 +137,7 @@ void CursorPair::compute_text_size(QPainter &p, unsigned
int prefix)
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();
}
diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp
index aec3de9..9e29ec2 100644
--- a/pv/view/ruler.cpp
+++ b/pv/view/ruler.cpp
@@ -23,13 +23,10 @@
#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>
@@ -47,10 +44,6 @@ const int Ruler::RulerHeight = 30;
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) :
@@ -71,19 +64,6 @@ void Ruler::clear_selection()
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
{
@@ -120,12 +100,10 @@ void Ruler::paintEvent(QPaintEvent*)
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;
@@ -163,7 +141,7 @@ void Ruler::paintEvent(QPaintEvent*)
// 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));
}
diff --git a/pv/view/ruler.h b/pv/view/ruler.h
index dc4e7bb..c48f25a 100644
--- a/pv/view/ruler.h
+++ b/pv/view/ruler.h
@@ -40,9 +40,6 @@ private:
static const int MinorTickSubdivision;
static const int ScaleUnits[3];
- static const QString SIPrefixes[9];
- static const int FirstSIPrefixPower;
-
static const int HoverArrowSize;
public:
@@ -50,9 +47,6 @@ public:
void clear_selection();
- static QString format_time(double t, unsigned int prefix,
- unsigned precision = 0);
-
public:
QSize sizeHint() const;
--
1.9.0
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel