summaryrefslogtreecommitdiffstats
path: root/src/gui/boolfieldwidget.cpp
blob: 5a8e88b860cd3f54ccdaf910f6a2bc969d6c441e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
    copyright            : (C) 2005-2006 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "boolfieldwidget.h"
#include "../field.h"
#include "../latin1literal.h"

#include <qlabel.h>
#include <qcheckbox.h>
#include <qlayout.h>

using Tellico::GUI::BoolFieldWidget;

BoolFieldWidget::BoolFieldWidget(Data::FieldPtr field_, QWidget* parent_, const char* name_/*=0*/)
    : FieldWidget(field_, parent_, name_) {

  m_checkBox = new QCheckBox(this);
  connect(m_checkBox, SIGNAL(clicked()), SIGNAL(modified()));
  registerWidget();
}

QString BoolFieldWidget::text() const {
  if(m_checkBox->isChecked()) {
    return QString::fromLatin1("true");
  }

  return QString();
}

void BoolFieldWidget::setText(const QString& text_) {
  blockSignals(true);

  m_checkBox->blockSignals(true);
  // be lax, don't have to check for "1" or "true"
  // just check for a non-empty string
  m_checkBox->setChecked(!text_.isEmpty());
  m_checkBox->blockSignals(false);

  blockSignals(false);
}

void BoolFieldWidget::clear() {
  m_checkBox->setChecked(false);
  editMultiple(false);
}

QWidget* BoolFieldWidget::widget() {
  return m_checkBox;
}

#include "boolfieldwidget.moc"