]> git.lyx.org Git - features.git/commitdiff
Mark insets with invalid buffer() in red in devel-mode.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Oct 2019 14:45:03 +0000 (16:45 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:45 +0000 (15:48 +0200)
We tend to have insets which buffer() member is invalid. To help
debugging, this commit paints their background in red when devel-mode
is on.

To this end, a new method develMode() is added to the Painter class.

With this commit, it is easy to see that macro template do not have a
proper buffer set!

src/MetricsInfo.cpp
src/frontends/NullPainter.h
src/frontends/Painter.h
src/frontends/qt/GuiPainter.cpp
src/frontends/qt/GuiPainter.h
src/frontends/qt/GuiWorkArea.cpp
src/mathed/MathRow.cpp

index e7bbefbf0dbe62beb36b1efcbf967e8027469e17..93c6e396f1a8ced06d2aca52f02e2403d3fedc0c 100644 (file)
@@ -158,19 +158,21 @@ ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
        if (selected && sel)
                // This inset is in a selection
                return Color_selection;
-       else {
-               if (color_bg != Color_none)
-                       // This inset has its own color
-                       return color_bg;
-               else {
-                       if (background_color == Color_none)
-                               // This inset has no own color and does not inherit a color
-                               return Color_background;
-                       else
-                               // This inset has no own color, but inherits a color
-                               return background_color;
-               }
-       }
+
+       if (pain.develMode() && !inset->isBufferValid())
+               // This inset is in error
+               return Color_error;
+
+       if (color_bg != Color_none)
+               // This inset has its own color
+               return color_bg;
+
+       if (background_color == Color_none)
+               // This inset has no own color and does not inherit a color
+               return Color_background;
+
+       // This inset has no own color, but inherits a color
+       return background_color;
 }
 
 
index 19ac8b66a26ce5acd4806c8fbb6b2a8aaa0d60ce..6984e7ca50e941de1674169f2e70a587f27cab1c 100644 (file)
@@ -25,7 +25,7 @@ namespace frontend {
  */
 class NullPainter : public Painter {
 public:
-       NullPainter() : Painter(1) {}
+       NullPainter() : Painter(1, false) {}
 
        ~NullPainter() {}
 
index 17253b2f44dae76fb7d5eebcb55f01bd5d28eb51..1ab43476c7478d8335953a7be8e183b15327c77e 100644 (file)
@@ -49,7 +49,8 @@ namespace frontend {
  */
 class Painter {
 public:
-       Painter(double pixel_ratio) : pixel_ratio_(pixel_ratio) {}
+       Painter(double pixel_ratio, bool devel_mode)
+               : pixel_ratio_(pixel_ratio), devel_mode_(devel_mode) {}
 
        static const int thin_line;
 
@@ -152,6 +153,8 @@ public:
 
        double pixelRatio() const { return pixel_ratio_; }
 
+       double develMode() const { return devel_mode_; }
+
        /// draw the underbar, strikeout, xout, uuline and uwave font attributes
        virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
 
@@ -182,6 +185,8 @@ public:
 private:
        /// Ratio between physical pixels and device-independent pixels
        double pixel_ratio_;
+       /// True when developer more is on at application-level.
+       bool devel_mode_;
 };
 
 } // namespace frontend
index c1f3677815f26b646f49b1e4ceda2b04356717b2..d255f507cbc88c39c5db390305435fe5b9c1f7df 100644 (file)
@@ -39,8 +39,8 @@ namespace frontend {
 
 const int Painter::thin_line = 1;
 
-GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio)
-       : QPainter(device), Painter(pixel_ratio)
+GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio, bool devel_mode)
+       : QPainter(device), Painter(pixel_ratio, devel_mode)
 {
        // set cache correctly
        current_color_ = pen().color();
index a4f40be51c7b9e797f6638052a75f1028b80f2ce..0c85194a4da9a9202574d5729756b6e38053984f 100644 (file)
@@ -34,7 +34,7 @@ namespace frontend {
  */
 class GuiPainter : public QPainter, public Painter {
 public:
-       GuiPainter(QPaintDevice *, double pixel_ratio);
+       GuiPainter(QPaintDevice *, double pixel_ratio, bool devel_mode);
        virtual ~GuiPainter();
 
        /// This painter paints
index 07ad690469893fcd1497a0ccbc6accd8665c4c2d..ab13c687d7c9d549299508303bea29a33371f30f 100644 (file)
@@ -1330,7 +1330,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
 
        d->last_pixel_ratio_ = pixelRatio();
 
-       GuiPainter pain(d->screenDevice(), pixelRatio());
+       GuiPainter pain(d->screenDevice(), pixelRatio(), d->lyx_view_->develMode());
 
        d->buffer_view_->draw(pain, d->caret_visible_);
 
index 7c5b9456ac2097d34e8496cf87ee9d4174a15ebb..d66d0d3e16b3af558cf8be2c125eb9965cdd41d5 100644 (file)
@@ -326,6 +326,9 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const
                        Dimension d2 = d;
                        d2.wid -= e.before + e.after;
                        coords.insets().add(e.inset, d2);
+                       if (pi.pain.develMode() && !e.inset->isBufferValid())
+                               pi.pain.fillRectangle(x + e.before, y - d2.ascent(),
+                                                     d2.width(), d2.height(), Color_error);
                        e.inset->draw(pi, x + e.before, y);
                        coords.insets().add(e.inset, x, y);
                        coords.insets().add(e.inset, d);