]> sigrok.org Git - pulseview.git/commitdiff
LogicSignal: Added an icon cache
authorJoel Holdsworth <redacted>
Sun, 23 Nov 2014 19:24:53 +0000 (19:24 +0000)
committerJoel Holdsworth <redacted>
Sun, 23 Nov 2014 19:24:53 +0000 (19:24 +0000)
pv/view/logicsignal.cpp
pv/view/logicsignal.hpp

index c58b85d9857a2a622c6e7cf51b3674be7b77a48a..4b07c568d90268dcccb5b5c25c251e07902c45ff 100644 (file)
@@ -241,32 +241,32 @@ void LogicSignal::paint_caps(QPainter &p, QLineF *const lines,
 
 void LogicSignal::init_trigger_actions(QWidget *parent)
 {
-       trigger_none_ = new QAction(QIcon(":/icons/trigger-none.svg"),
+       trigger_none_ = new QAction(*get_icon(":/icons/trigger-none.svg"),
                tr("No trigger"), parent);
        trigger_none_->setCheckable(true);
        connect(trigger_none_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 
-       trigger_rising_ = new QAction(QIcon(":/icons/trigger-rising.svg"),
+       trigger_rising_ = new QAction(*get_icon(":/icons/trigger-rising.svg"),
                tr("Trigger on rising edge"), parent);
        trigger_rising_->setCheckable(true);
        connect(trigger_rising_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 
-       trigger_high_ = new QAction(QIcon(":/icons/trigger-high.svg"),
+       trigger_high_ = new QAction(*get_icon(":/icons/trigger-high.svg"),
                tr("Trigger on high level"), parent);
        trigger_high_->setCheckable(true);
        connect(trigger_high_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 
-       trigger_falling_ = new QAction(QIcon(":/icons/trigger-falling.svg"),
+       trigger_falling_ = new QAction(*get_icon(":/icons/trigger-falling.svg"),
                tr("Trigger on falling edge"), parent);
        trigger_falling_->setCheckable(true);
        connect(trigger_falling_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 
-       trigger_low_ = new QAction(QIcon(":/icons/trigger-low.svg"),
+       trigger_low_ = new QAction(*get_icon(":/icons/trigger-low.svg"),
                tr("Trigger on low level"), parent);
        trigger_low_->setCheckable(true);
        connect(trigger_low_, SIGNAL(triggered()), this, SLOT(on_trigger()));
 
-       trigger_change_ = new QAction(QIcon(":/icons/trigger-change.svg"),
+       trigger_change_ = new QAction(*get_icon(":/icons/trigger-change.svg"),
                tr("Trigger on rising or falling edge"), parent);
        trigger_change_->setCheckable(true);
        connect(trigger_change_, SIGNAL(triggered()), this, SLOT(on_trigger()));
@@ -380,6 +380,17 @@ void LogicSignal::modify_trigger()
                new_trigger->stages().empty() ? nullptr : new_trigger);
 }
 
+const QIcon* LogicSignal::get_icon(const char *path)
+{
+       const QIcon *icon = icon_cache_.take(path);
+       if (!icon) {
+               icon = new QIcon(path);
+               icon_cache_.insert(path, icon);
+       }
+
+       return icon;
+}
+
 void LogicSignal::on_trigger()
 {
        QAction *action;
index 6d6d89aa3420d66697d47cbbee89fe4e29f177e2..7a1c62f570d37227890bf07677284fe72489458f 100644 (file)
 #ifndef PULSEVIEW_PV_VIEW_LOGICSIGNAL_H
 #define PULSEVIEW_PV_VIEW_LOGICSIGNAL_H
 
+#include <QCache>
+
 #include "signal.hpp"
 
 #include <memory>
 
+class QIcon;
 class QToolBar;
 
 namespace sigrok {
@@ -106,6 +109,8 @@ private:
        void populate_popup_form(QWidget *parent, QFormLayout *form);
        void modify_trigger();
 
+       static const QIcon* get_icon(const char *path);
+
 private Q_SLOTS:
        void on_trigger();
 
@@ -121,6 +126,8 @@ private:
        QAction *trigger_falling_;
        QAction *trigger_low_;
        QAction *trigger_change_;
+
+       static QCache<QString, const QIcon> icon_cache_;
 };
 
 } // namespace view