]> sigrok.org Git - pulseview.git/blobdiff - pv/prop/bool.cpp
Enum: Use slider instead of combo box for contiguous ranges
[pulseview.git] / pv / prop / bool.cpp
index 3e201cc4c6a1ffc8bdec2b940a8686fef9dc5e94..6c89741ff6f6657779d74f4a6e30d0c7675d72d4 100644 (file)
  * 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 <http://www.gnu.org/licenses/>.
  */
 
-#include <assert.h>
+#include <cassert>
 
 #include <QCheckBox>
 
 namespace pv {
 namespace prop {
 
-Bool::Bool(QString name, Getter getter, Setter setter) :
-       Property(name, getter, setter),
+Bool::Bool(QString name, QString desc, Getter getter, Setter setter) :
+       Property(name, desc, getter, setter),
        check_box_(nullptr)
 {
 }
 
-Bool::~Bool()
-{
-}
-
 QWidget* Bool::get_widget(QWidget *parent, bool auto_commit)
 {
        if (check_box_)
@@ -49,11 +44,10 @@ QWidget* Bool::get_widget(QWidget *parent, bool auto_commit)
        if (!variant.gobj())
                return nullptr;
 
-       bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
-               variant).get();
-
        check_box_ = new QCheckBox(name(), parent);
-       check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked);
+       check_box_->setToolTip(desc());
+
+       update_widget();
 
        if (auto_commit)
                connect(check_box_, SIGNAL(stateChanged(int)),
@@ -67,6 +61,20 @@ bool Bool::labeled_widget() const
        return true;
 }
 
+void Bool::update_widget()
+{
+       if (!check_box_)
+               return;
+
+       Glib::VariantBase variant = getter_();
+       assert(variant.gobj());
+
+       bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
+               variant).get();
+
+       check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked);
+}
+
 void Bool::commit()
 {
        assert(setter_);
@@ -83,5 +91,5 @@ void Bool::on_state_changed(int)
        commit();
 }
 
-} // prop
-} // pv
+}  // namespace prop
+}  // namespace pv