Homework 17
The goal of this homework is for you to practice collaboration modeling as well as the mediator pattern.
For this homework, fill in this word file with your answers. I suggest you to work on this problem purely
on paper, with your computer and textbook closed, because a problem of this style. may be given in Exam 2.
The images shown below are screen shots of a simple application. The application starts with the main
window that contains the following objects: a progress bar, a horizontal slider, a text input, a combo box
and a push button. The progress bar ranges from 0 to 100. The slider range is from 0 to 100 and its default
location is the 0th position. The text input shows the value of slider position, it can also be used to change
the slider position, progress bar and combo box values. The combo box contains three options; 0, 50, and
100. Changes in combo box selections are immediately reflected in all other objects. The reset button resets
the values of all objects to zero.
(1) Complete the code given below to implement the functionality described above. For your convenience,
parts of the code are already given to you while some functions have been removed and replaced with
empty boxes that you need to fill. Here is a list of QT signals for your reference: textChanged(QString),
currentTextChanged(QString), valueChanged(QString), textEdited(QString), returnPressed(),
editingFinished(), clicked(bool), clicked(), pressed(), released(), stateChanged(int)
Mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
namespace Ui {
class MainWindow; }
class MainWindow : public QMainWindow
{ Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void actByYourChange(QObject*);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "myslider.h"
#include "mylineedit.h"
#include "mycombobox.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->horizontalSlider->setMinimum(0);
ui->horizontalSlider->setMaximum(100);
ui->horizontalSlider->setValue(0);
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
ui->progressBar->setValue(0);
ui->lineEdit->setText("0");
}
MainWindow::~MainWindow()
{ delete ui;
}
void MainWindow::actByYourChange(QObject* sender){
ui->centralWidget->adjustSize();
}
Mycombobox.h
#ifndef MYCOMBOBOX_H
#define MYCOMBOBOX_H
#include
class mycomboBox: public QComboBox {
Q_OBJECT
public:
mycomboBox(QWidget* qw):QComboBox(qw){};
signals:
public slots:
};
#endif // /MYCOMBOBOX_H
Mycombobox.cpp
#include "mycombobox.h"
MylineEdit.h
#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H
#include //box
class MyLineEdit:public QLineEdit{
Q_OBJECT
public:
MyLineEdit(const QString qs):QLineEdit(qs){};
MyLineEdit(QWidget* qw):QLineEdit(qw){};
signals:
public slots:
};
#endif // MYLINEEDIT_H
MylineEdit.cpp
#include "mylineedit.h"
MySlider.h
#ifndef MYSLIDER_H
#define MYSLIDER_H
#include //box here
class MySlider:public QSlider {
Q_OBJECT
public:
MySlider(QWidget* qw):QSlider(qw){}
signals:
public slots:
};
#endif // MYSLIDER_H
MySlider.cpp
#include "myslider.h"
Resetbutton.h
#ifndef RESETBUTTON_H
#define RESETBUTTON_H
#include
class ResetButton:public QPushButton {
Q_OBJECT
public:
ResetButton(QWidget* qw):QPushButton(qw){}
signals:
private slots:
};
#endif // RESETBUTTON_H
Resetbutton.cpp
#include "resetbutton.h"
(2) Sequence Diagram
Consider the above application that uses a slider bar, progress bar, text input, combobox and a push button
object. Draw a sequence diagram that depicts the following scenario: The main dialog window is open and
a user changes slider position in main window. Please draw the diagram in word. We do not accept
handwritten diagrams.