Introduce old redir program
[lcapit-junk-code.git] / qt-course / exer54-invert-numbers / MyWidget.cpp
blob7f96b7d86afafc12ec202382af32bf041577e45e
1 #include <QString>
2 #include <QQueue>
3 #include <QStack>
5 #include "MyWidget.h"
7 MyWidget::MyWidget(QWidget *parent)
8 : QWidget(parent)
10 m_ui = new Ui::MyWidgetBase();
11 m_ui->setupUi(this);
13 m_numbers = new QQueue<int>;
15 connect(m_ui->m_addButton, SIGNAL(clicked(bool)), this,
16 SLOT(slot_addButtonClicked()));
18 connect(m_ui->m_invButton, SIGNAL(clicked(bool)), this,
19 SLOT(slot_invButtonClicked()));
21 connect(m_ui->m_clrButton, SIGNAL(clicked(bool)), this,
22 SLOT(slot_clrButtonClicked()));
25 MyWidget::~MyWidget()
27 delete m_numbers;
30 void MyWidget::slot_addButtonClicked()
32 QString num = m_ui->m_lineEdit->text();
33 if (num == "")
34 return;
36 m_numbers->append(num.toInt());
38 QString text = m_ui->m_label->text();
39 text += num + " ";
40 m_ui->m_label->setText(text);
41 m_ui->m_lineEdit->setText("");
44 void MyWidget::slot_invButtonClicked()
46 QStack<int> m_stack;
48 if (m_numbers->isEmpty())
49 return;
51 int count = m_numbers->count();
52 for (int i = 0; i < count; i++)
53 m_stack.push(m_numbers->dequeue());
55 QString text;
56 for (int i = 0; i < count; i++)
57 text += QString::number(m_stack.pop(), 10) + " ";
59 m_ui->m_label->setText(text);
62 void MyWidget::slot_clrButtonClicked()
64 m_ui->m_label->setText("");
65 m_ui->m_lineEdit->setText("");
66 m_numbers->clear();