diff --git a/Libs/Core/ctkUtils.h b/Libs/Core/ctkUtils.h index 92d1888608..14e15439c7 100644 --- a/Libs/Core/ctkUtils.h +++ b/Libs/Core/ctkUtils.h @@ -30,6 +30,23 @@ #include "ctkCoreExport.h" +/// This macro can be used instead of Q_ASSERT to log a warning when +/// a condition fails. It logs a warning message in debug mode and +/// has no effect in release mode. +#ifndef NDEBUG +# define CTK_VALIDATE(condition) \ + { \ + if (! (condition) ) \ + { \ + qWarning() << "Check `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__; \ + } \ + } +#else +# define CTK_VALIDATE(condition) +#endif + + namespace ctk { /// /// \ingroup Core diff --git a/Libs/Widgets/ctkMatrixWidget.cpp b/Libs/Widgets/ctkMatrixWidget.cpp index 32e5ffa656..f1c9b62738 100644 --- a/Libs/Widgets/ctkMatrixWidget.cpp +++ b/Libs/Widgets/ctkMatrixWidget.cpp @@ -21,6 +21,7 @@ // CTK includes #include "ctkMatrixWidget.h" #include "ctkDoubleSpinBox.h" +#include "ctkUtils.h" // Qt includes #include @@ -238,7 +239,7 @@ void ctkMatrixWidgetPrivate::updateGeometries() bool lastColumn = (j==(ccount-1)); int newWidth = lastColumn ? lastColWidth : colWidth; this->Table->setColumnWidth(j, newWidth); - Q_ASSERT(this->Table->columnWidth(j) == newWidth); + CTK_VALIDATE(this->Table->columnWidth(j) == newWidth); } // rows const int rcount = q->rowCount(); @@ -249,7 +250,7 @@ void ctkMatrixWidgetPrivate::updateGeometries() bool lastRow = (i==(rcount-1)); int newHeight = lastRow ? lastRowHeight : rowHeight; this->Table->setRowHeight(i, newHeight); - Q_ASSERT(this->Table->rowHeight(i) == newHeight); + CTK_VALIDATE(this->Table->rowHeight(i) == newHeight); } this->Table->updateGeometry(); }