20 #include <analitza/analyzer.h>
21 #include <analitza/expression.h>
22 #include <analitza/variables.h>
23 #include <analitzagui/expressionedit.h>
27 #include <QPushButton>
29 #include <QVBoxLayout>
31 #include <KPushButton>
34 KDialog(parent), vars(0), m_correct(false)
37 setCaption(i18n(
"Add/Edit a variable"));
39 setButtons(KDialog::User1 | KDialog::Ok | KDialog::Cancel);
40 enableButtonApply(
false );
41 setMainWidget( widget );
43 setButtonText(KDialog::User1, i18n(
"Remove Variable"));
45 setButtonIcon(KDialog::User1, KIcon(
"edit-table-delete-row"));
46 setButtonIcon(KDialog::Ok, KIcon(
"dialog-ok"));
47 setButtonIcon(KDialog::Cancel, KIcon(
"dialog-cancel"));
49 connect(button(KDialog::User1), SIGNAL(clicked(
bool)), SLOT(removeVariable()));
51 connect(
this, SIGNAL(applyClicked()),
this, SLOT(accept()) );
52 connect(
this, SIGNAL(okClicked()),
this, SLOT(reject()) );
54 m_exp =
new Analitza::ExpressionEdit(widget);
55 connect(m_exp, SIGNAL(textChanged()),
this, SLOT(edit()));
56 connect(m_exp, SIGNAL(returnPressed()),
this, SLOT(ok()));
58 m_valid =
new QLabel(widget);
70 setWindowTitle(i18n(
"Edit '%1' value", newVar));
72 m_exp->setText(i18n(
"not available"));
74 m_exp->setExpression(Analitza::Expression(vars->value(newVar)->copy()));
77 button(KDialog::User1)->setEnabled(canRemove(newVar));
80 bool VarEdit::canRemove(
const QString& name)
const
83 for(; it!=itEnd; ++it) {
94 Analitza::Expression
val;
95 Analitza::Analyzer a(vars);
97 a.setExpression(m_exp->expression());
104 m_correct = a.isCorrect();
106 m_valid->
setText(i18n(
"<b style='color:#090'>%1 := %2</b>", m_var, val.toString()));
109 m_valid->
setText(i18n(
"<b style='color:red'>WRONG</b>"));
112 button(Ok)->setEnabled(m_correct);
113 m_exp->setCorrect(m_correct);
131 vars= na->variables();
132 m_exp->setAnalitza(na);
135 void VarEdit::removeVariable()
bool contains(const QString &str, Qt::CaseSensitivity cs) const
VarEdit(QWidget *parent=0, bool modal=false)
Constructor.
void setAnalitza(Analitza::Analyzer *na)
Sets an Analitza which will evaluate it.
void setText(const QString &)
void setName(const QString &newVar)
Sets the editing variable name.
Analitza::Expression val()
Returns the resulting variable expression.