X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fruler.cpp;h=712244a9df8cc9a4399d80217ac413467abd0f5d;hp=cd72a179cc72a84e46f4e9e65edb82750da42b0b;hb=6f925ba9d6faf1077b73c5a5808259576081716a;hpb=97f712530f0f22461d16f7d34b5ff8bf6e4c3c7f diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index cd72a17..712244a 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -14,8 +14,7 @@ * 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 + * along with this program; if not, see . */ #include @@ -29,16 +28,18 @@ using namespace Qt; +using std::function; using std::shared_ptr; using std::vector; namespace pv { -namespace view { +namespace views { +namespace TraceView { -const float Ruler::RulerHeight = 2.5f; // x Text Height +const float Ruler::RulerHeight = 2.5f; // x Text Height const int Ruler::MinorTickSubdivision = 4; -const float Ruler::HoverArrowSize = 0.5f; // x Text Height +const float Ruler::HoverArrowSize = 0.5f; // x Text Height Ruler::Ruler(View &parent) : MarginWidget(parent) @@ -70,7 +71,7 @@ QSize Ruler::sizeHint() const QSize Ruler::extended_size_hint() const { QRectF max_rect; - std::vector< std::shared_ptr > items(view_.time_items()); + vector< shared_ptr > items(view_.time_items()); for (auto &i : items) max_rect = max_rect.united(i->label_rect(QRect())); return QSize(0, sizeHint().height() - max_rect.top() / 2 + @@ -128,8 +129,7 @@ shared_ptr Ruler::get_mouse_over_item(const QPoint &pt) void Ruler::paintEvent(QPaintEvent*) { if (!tick_position_cache_) { - auto ffunc = [this](const pv::util::Timestamp& t) - { + auto ffunc = [this](const pv::util::Timestamp& t) { return format_time_with_distance( this->view_.tick_period(), t, @@ -138,12 +138,12 @@ void Ruler::paintEvent(QPaintEvent*) this->view_.tick_precision()); }; - tick_position_cache_.emplace(calculate_tick_positions( + tick_position_cache_ = calculate_tick_positions( view_.tick_period(), view_.offset(), view_.scale(), width(), - ffunc)); + ffunc); } const int ValueMargin = 3; @@ -194,12 +194,11 @@ Ruler::TickPositions Ruler::calculate_tick_positions( const pv::util::Timestamp& offset, const double scale, const int width, - std::function format_function) + function format_function) { TickPositions tp; - const double minor_period = - (major_period / MinorTickSubdivision).convert_to(); + const pv::util::Timestamp minor_period = major_period / MinorTickSubdivision; const pv::util::Timestamp first_major_division = floor(offset / major_period); const pv::util::Timestamp first_minor_division = ceil(offset / minor_period); const pv::util::Timestamp t0 = first_major_division * major_period; @@ -214,7 +213,7 @@ Ruler::TickPositions Ruler::calculate_tick_positions( x = ((t - offset) / scale).convert_to(); if (division % MinorTickSubdivision == 0) { - // Recalculate 't' without using 'minor_period' which is of type double. + // Recalculate 't' without using 'minor_period' which is a fraction t = t0 + division / MinorTickSubdivision * major_period; tp.major.emplace_back(x, format_function(t)); } else { @@ -227,9 +226,9 @@ Ruler::TickPositions Ruler::calculate_tick_positions( return tp; } -void Ruler::mouseDoubleClickEvent(QMouseEvent *e) +void Ruler::mouseDoubleClickEvent(QMouseEvent *event) { - view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale()); + view_.add_flag(view_.offset() + ((double)event->x() + 0.5) * view_.scale()); } void Ruler::draw_hover_mark(QPainter &p, int text_height) @@ -273,5 +272,6 @@ void Ruler::resizeEvent(QResizeEvent*) invalidate_tick_position_cache(); } -} // namespace view +} // namespace TraceView +} // namespace views } // namespace pv