]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decode/row.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / data / decode / row.cpp
index e5972517a446bc7a47b0ba3a6238e257b91b8114..6212c92195bb888838348122f14624d0e83f2edc 100644 (file)
@@ -17,6 +17,9 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <cassert>
+#include <QDebug>
+
 #include "decoder.hpp"
 #include "row.hpp"
 
@@ -75,11 +78,17 @@ const QString Row::description() const
 
 vector<AnnotationClass*> Row::ann_classes() const
 {
+       assert(decoder_);
+
        vector<AnnotationClass*> result;
 
-       if (!srd_row_)
+       if (!srd_row_) {
+               if (index_ == 0) {
+                       // When operating as the fallback row, all annotation classes belong to it
+                       return decoder_->ann_classes();
+               }
                return result;
-       assert(decoder_);
+       }
 
        for (GSList *l = srd_row_->ann_classes; l; l = l->next) {
                size_t class_id = (size_t)l->data;
@@ -102,17 +111,86 @@ bool Row::visible() const
 void Row::set_visible(bool visible)
 {
        visible_ = visible;
+
+       visibility_changed();
+}
+
+void Row::set_base_color(QColor base_color)
+{
+       // For the row color, use the base color hue and add an offset that's
+       // not a dividend of 360
+
+       const int h = (base_color.toHsv().hue() + 20 * index_) % 360;
+       const int s = DECODE_COLOR_SATURATION;
+       const int v = DECODE_COLOR_VALUE;
+       color_.setHsl(h, s, v);
+
+       vector<AnnotationClass*> classes = ann_classes();
+       for (const AnnotationClass* ann_class : classes) {
+
+               // For each class color, use the row color hue and add an offset that's
+               // not a dividend of 360 and not a multiple of the row offset
+
+               QColor ann_color(color_);
+               const int h = (ann_color.toHsv().hue() + 55 * ann_class->id) % 360;
+               const int s = DECODE_COLOR_SATURATION;
+               const int v = DECODE_COLOR_VALUE;
+               ann_color.setHsl(h, s, v);
+
+               ann_class_color_[ann_class->id] = ann_color;
+               ann_bright_class_color_[ann_class->id] = ann_color.lighter();
+               ann_dark_class_color_[ann_class->id] = ann_color.darker();
+       }
+}
+
+const QColor Row::color() const
+{
+       return color_;
+}
+
+const QColor Row::get_class_color(uint32_t ann_class_id) const
+{
+       try {
+               return ann_class_color_.at(ann_class_id);
+       } catch (std::out_of_range &e) {
+               qWarning() << "Warning: annotation type" << decoder_->get_ann_class_by_id(ann_class_id)->name
+                       << "(" << ann_class_id << ")" << "not assigned to any annotation row!";
+               return QColor(20, 20, 20);
+       }
+}
+
+const QColor Row::get_bright_class_color(uint32_t ann_class_id) const
+{
+       try {
+               return ann_bright_class_color_.at(ann_class_id);
+       } catch (std::out_of_range &e) {
+               return QColor(20, 20, 20);
+       }
+}
+
+const QColor Row::get_dark_class_color(uint32_t ann_class_id) const
+{
+       try {
+               return ann_dark_class_color_.at(ann_class_id);
+       } catch (std::out_of_range &e) {
+               return QColor(20, 20, 20);
+       }
 }
 
 bool Row::has_hidden_classes() const
 {
        for (const AnnotationClass* c : ann_classes())
-               if (!c->visible)
+               if (!c->visible())
                        return true;
 
        return false;
 }
 
+bool Row::class_is_visible(uint32_t ann_class_id) const
+{
+       return decoder_->get_ann_class_by_id(ann_class_id)->visible();
+}
+
 bool Row::operator<(const Row& other) const
 {
        return (decoder_ < other.decoder_) ||