Skip to content

Commit

Permalink
Redesigns MainWindow and adds ProccessList
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Passos committed May 12, 2019
1 parent b1fd221 commit a5656e0
Show file tree
Hide file tree
Showing 12 changed files with 2,260 additions and 272 deletions.
1,138 changes: 1,042 additions & 96 deletions Makefile.Debug

Large diffs are not rendered by default.

1,139 changes: 1,042 additions & 97 deletions Makefile.Release

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions object_script.main.Debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
debug/main.o
debug/mainwindow.o
debug/addproccesswidget.o
debug/operatingsystem.o
debug/proccess.o
debug/scheduler.o
debug/proccesslist.o
debug/moc_mainwindow.o
debug/moc_addproccesswidget.o
debug/moc_proccesslist.o
10 changes: 10 additions & 0 deletions object_script.main.Release
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
release/main.o
release/mainwindow.o
release/addproccesswidget.o
release/operatingsystem.o
release/proccess.o
release/scheduler.o
release/proccesslist.o
release/moc_mainwindow.o
release/moc_addproccesswidget.o
release/moc_proccesslist.o
2 changes: 2 additions & 0 deletions project.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ HEADERS += src/addproccesswidget.h
HEADERS += src/operatingsystem.h
HEADERS += src/memory.h
HEADERS += src/scheduler.h
HEADERS += src/proccesslist.h
SOURCES += src/main.cpp
SOURCES += src/mainwindow.cpp
SOURCES += src/addproccesswidget.cpp
SOURCES += src/operatingsystem.cpp
SOURCES += src/proccess.cpp
SOURCES += src/scheduler.cpp
SOURCES += src/proccesslist.cpp

QT += core
QT += widgets
Expand Down
11 changes: 9 additions & 2 deletions src/addproccesswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ AddProccessWidget::AddProccessWidget(int proccessIndex, QWidget* parent)
m_arrivalTimeInput->setStatusTip(tr("Set the arrival time of the proccess."));

QPushButton* removeButton = new QPushButton(tr("Remove"), nullptr);
connect(removeButton, &QPushButton::clicked, this, AddProccessWidget::close);
connect(removeButton, &QPushButton::clicked,
this, &AddProccessWidget::RemoveButtonClicked);

m_proccessLayout->addWidget(m_priorityLabel, 0, 0);
m_proccessLayout->addWidget(m_priorityInput, 0, 1);
m_proccessLayout->addWidget(m_durationLabel, 1, 0);
m_proccessLayout->addWidget(m_durationInput, 1, 1);
m_proccessLayout->addWidget(m_arrivalTimeLabel, 2, 0);
m_proccessLayout->addWidget(m_arrivalTimeInput, 2, 1);
m_proccessLayout->addWidget(removeButton, 3, 0, Qt::AlignCenter);
m_proccessLayout->addWidget(removeButton, 3, 1, Qt::AlignRight);

setFixedSize(150, 150);
setLayout(m_proccessLayout);
}

int AddProccessWidget::GetArrivalTime()
{
return m_arrivalTimeInput->value();
}

void AddProccessWidget::RemoveButtonClicked()
{
emit RemoveProccessRequested(this);
}
6 changes: 6 additions & 0 deletions src/addproccesswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class AddProccessWidget : public QGroupBox
// Retrieves current value of arrival time
int GetArrivalTime();

private slots:
void RemoveButtonClicked();

signals:
void RemoveProccessRequested(QWidget* proccess);

private:
QGridLayout* m_proccessLayout;
QLabel* m_priorityLabel;
Expand Down
23 changes: 0 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,6 @@

int main(int argc, char* args[])
{
// OperatingSystem operatingSystem = OperatingSystem(3, 1, SchedulingAlgorithm::EDF);
// Proccess* p1 = new Proccess(1, 0, 5, 4, 1);
// Proccess* p2 = new Proccess(2, 0, 7, 4, 2);
// Proccess* p3 = new Proccess(3, 8, 10, 4, 2);

// operatingSystem.AddProccess(p1);
// operatingSystem.AddProccess(p2);
// operatingSystem.AddProccess(p3);
// std::cout << "Hi" << std::endl;
// while(operatingSystem.NextStep());
// std::cout << "Done." << std::endl;
// std::cout << "Turnaround: " << operatingSystem.GetAverageTurnaround() << std::endl;

// const std::vector<Proccess*>& fp = operatingSystem.GetFinishedProccesses();
// for(auto p = fp.begin(); p != fp.end(); p++)
// {
// std::cout << "Proccess " << (*p)->GetID() << ". Started at " <<
// (*p)->GetArrivalTime() << " and finished at " << (*p)->GetFinishTime() <<
// ". TA is " << (*p)->GetTurnAround() << std::endl;
// }
// std::cin.get();

// std::cin.get();
QApplication app(argc, args);
MainWindow mainWindow;
mainWindow.show();
Expand Down
100 changes: 49 additions & 51 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#include "mainwindow.h"
#include "addproccesswidget.h"
#include "proccesslist.h"

MainWindow::MainWindow()
: m_mainWidget(nullptr),
m_mainLayout(nullptr),
: m_schedulerSettingsLayout(nullptr),
m_fileMenu(nullptr),
m_addProccessButon(nullptr),
m_addProccessButton(nullptr),
m_loadAction(nullptr),
m_schedulingAlgorithmBox(nullptr),
m_schedulingOptionsLayout(nullptr),
m_schedulingRadioButtons(nullptr),
m_quantumValueSelectorBox(nullptr),
m_quantumValueSelector(nullptr),
m_proccessList(nullptr),
m_runButton(nullptr),
m_numberOfProccesses(0)
{
Expand All @@ -32,8 +33,23 @@ MainWindow::MainWindow()
void MainWindow::AddProccessBox()
{
m_numberOfProccesses++;
QGroupBox* addProccessWidget = new AddProccessWidget(m_numberOfProccesses, this);
m_mainLayout->insertWidget(m_numberOfProccesses, addProccessWidget);
m_proccessList->AddProccess(m_numberOfProccesses);
}

void MainWindow::ActivateOrDeactivateRunButton(int numberOfProccesses)
{
// For the run button to be active, there must be
// at least one proccess on the list.
// The simulation can't run otherwise.
if(numberOfProccesses > 0)
{
m_runButton->setEnabled(true);
}
else
{
m_numberOfProccesses = 0;
m_runButton->setEnabled(false);
}
}

void MainWindow::Load()
Expand All @@ -43,12 +59,12 @@ void MainWindow::Load()

void MainWindow::CreateButtons()
{
m_addProccessButon = new QPushButton(tr("+\nAdd Process"), this);
m_addProccessButon->setFixedSize(QSize(70, 40));
m_addProccessButon->setStatusTip(tr("Add a new process."));
m_addProccessButton = new QPushButton(tr("+\nAdd Process"), this);
m_addProccessButton->setFixedSize(QSize(100, 50));
m_addProccessButton->setStatusTip(tr("Add a new process."));

m_runButton = new QPushButton(tr(">\nRun"), this);
m_runButton->setFixedSize(QSize(80, 40));
m_runButton->setFixedSize(QSize(200, 80));
m_runButton->setStatusTip(tr("Run simulation using the current confiuration."));

QPalette pal = m_runButton->palette();
Expand Down Expand Up @@ -93,6 +109,8 @@ void MainWindow::CreateSchedulingAlgorithmSelectionBox()
m_schedulingRadioButtons->addButton(sjfButton);
m_schedulingRadioButtons->addButton(roundRobinButton);
m_schedulingRadioButtons->addButton(edfButton);

m_schedulingAlgorithmBox->setFixedSize(300, 60);
}

void MainWindow::CreateQuantumValueSelectionBox()
Expand All @@ -107,6 +125,7 @@ void MainWindow::CreateQuantumValueSelectionBox()
quantumSelectorGrid->addWidget(m_quantumValueSelector, 0, 1);

m_quantumValueSelectorBox->setLayout(quantumSelectorGrid);
m_quantumValueSelectorBox->setFixedSize(300, 60);
}


Expand All @@ -126,54 +145,33 @@ void MainWindow::CreateStatusBar()

void MainWindow::CreateMainLayout()
{
m_osSettingsGroup = new QGroupBox(tr("Scheduler Settings"), this);
m_schedulerSettingsLayout = new QBoxLayout(QBoxLayout::LeftToRight, m_osSettingsGroup);
m_schedulerSettingsLayout->insertWidget(0, m_schedulingAlgorithmBox);
m_schedulerSettingsLayout->insertWidget(1, m_quantumValueSelectorBox);
m_osSettingsGroup->setLayout(m_schedulerSettingsLayout);

m_prccessListGroup = new QWidget(m_osSettingsGroup);
m_proccessList = new ProccessList(this);
m_mainGrid = new QVBoxLayout();
m_mainGrid->addWidget(m_addProccessButton, 0, Qt::AlignCenter | Qt::AlignTop);
m_mainGrid->addWidget(m_proccessList);
m_prccessListGroup->setLayout(m_mainGrid);

m_mainLayout = new QVBoxLayout(this);
m_mainLayout->addWidget(m_osSettingsGroup);
m_mainLayout->addWidget(m_prccessListGroup);
m_mainLayout->addWidget(m_runButton, 0, Qt::AlignCenter);

m_mainWidget = new QWidget(this);
m_mainLayout = new QBoxLayout(QBoxLayout::TopToBottom);

m_mainLayout->insertWidget(0, m_schedulingAlgorithmBox);
m_mainLayout->insertWidget(1, m_quantumValueSelectorBox);
m_mainLayout->insertSpacing(2, 10);
m_mainLayout->insertWidget(3, m_addProccessButon, 0, Qt::AlignCenter | Qt::AlignTop);
m_mainLayout->insertSpacing(4, 30);
m_mainLayout->insertWidget(5, m_runButton, 0, Qt::AlignCenter | Qt::AlignTop);
m_mainLayout->insertSpacing(6, 10);

// QTableWidget* tw = new QTableWidget(3, 1, this);
// QTableWidgetItem* pa = new QTableWidgetItem(tr("%1").arg(10));
// QTableWidgetItem* pd = new QTableWidgetItem(tr("%1").arg(3));
// QTableWidgetItem* pde = new QTableWidgetItem(tr("%1").arg(20));
// tw->setItem(0, 0, pa);
// tw->setItem(1, 0, pd);
// tw->setItem(2, 0, pde);
// tw->setHorizontalHeaderItem(0, new QTableWidgetItem("Proccess 1"));
// tw->setVerticalHeaderItem(0, new QTableWidgetItem("Arrival"));
// tw->setVerticalHeaderItem(1, new QTableWidgetItem("Duration"));
// tw->setVerticalHeaderItem(2, new QTableWidgetItem("Deadline"));

// m_mainLayout->insertWidget(1, tw);
// for(int i = 0; i < 50; i++)
// {
// for(int j = 0; j < 1; j++)
// {
// QTableWidgetItem* item = new QTableWidgetItem(tr("%1").arg(i + j));
// item->setFlags(item->flags() ^ Qt::ItemIsEditable);
// tw->setItem(i, j, item);
// }
// }
m_mainWidget->setLayout(m_mainLayout);

// QPropertyAnimation* animation = new QPropertyAnimation(m_addProccessButon, "geometry");
// animation->setDuration(1000);
// animation->setStartValue(m_addProccessButon->geometry());
// QRect rc = m_addProccessButon->geometry();
// rc.setHeight( rc.height() + 50);
// animation->setEndValue(rc);
// animation->setEasingCurve(QEasingCurve::InQuad);
// animation->start();

setCentralWidget(m_mainWidget);
}

void MainWindow::ConnectWidgets()
{
connect(m_addProccessButon, &QPushButton::clicked, this, &MainWindow::AddProccessBox);
connect(m_addProccessButton, &QPushButton::clicked, this, &MainWindow::AddProccessBox);
connect(m_proccessList, &ProccessList::NumberOfProccessesChanged,
this, &MainWindow::ActivateOrDeactivateRunButton);
}
16 changes: 13 additions & 3 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QtWidgets\QtWidgets>

class ProccessList;

class MainWindow : public QMainWindow
{
Q_OBJECT
Expand All @@ -11,6 +13,7 @@ class MainWindow : public QMainWindow

private slots:
void AddProccessBox();
void ActivateOrDeactivateRunButton(int numberOfProccesses);
void Load();

private:
Expand All @@ -23,18 +26,25 @@ private slots:
void ConnectWidgets();

QWidget* m_mainWidget;
QBoxLayout* m_mainLayout;

QVBoxLayout* m_mainGrid;
QVBoxLayout* m_mainLayout;

QGroupBox* m_osSettingsGroup;
QMenu* m_fileMenu;
QPushButton* m_addProccessButon;
QAction* m_loadAction;

QGroupBox* m_schedulingAlgorithmBox;
QBoxLayout* m_schedulerSettingsLayout;
QHBoxLayout* m_schedulingOptionsLayout;
QButtonGroup* m_schedulingRadioButtons;

QGroupBox* m_quantumValueSelectorBox;
QSpinBox* m_quantumValueSelector;

QWidget* m_prccessListGroup;
ProccessList* m_proccessList;
QPushButton* m_addProccessButton;

QPushButton* m_runButton;
int m_numberOfProccesses;
};
Expand Down
48 changes: 48 additions & 0 deletions src/proccesslist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "proccesslist.h"
#include "addproccesswidget.h"

ProccessList::ProccessList(QWidget* parent)
: QScrollArea(parent),
m_mainLayout(nullptr),
m_centralWidget(nullptr),
m_numberOfProccesses(0)
{
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setWidgetResizable(true);
setFixedHeight(190);
setFixedWidth(600);
CreateMainLayout();
}

void ProccessList::AddProccess(int index)
{
AddProccessWidget* proccessBox = new AddProccessWidget(index, this);
connect(proccessBox, &AddProccessWidget::RemoveProccessRequested,
this, &ProccessList::RemoveProccess);
m_mainLayout->insertWidget(m_numberOfProccesses, proccessBox,
0, Qt::AlignLeft | Qt::AlignTop);

m_numberOfProccesses++;

emit NumberOfProccessesChanged(m_numberOfProccesses);
}

void ProccessList::RemoveProccess(QWidget* widget)
{
m_numberOfProccesses--;
m_mainLayout->removeWidget(widget);
delete widget;
widget = nullptr;

emit NumberOfProccessesChanged(m_numberOfProccesses);
}

void ProccessList::CreateMainLayout()
{
m_mainLayout = new QHBoxLayout(this);
m_mainLayout->setAlignment(Qt::AlignLeft);
m_centralWidget = new QWidget(this);
this->setWidget(m_centralWidget);

m_centralWidget->setLayout(m_mainLayout);
}
29 changes: 29 additions & 0 deletions src/proccesslist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef PROCCESLIST_H
#define PROCCESSLIST_H

#include <QtWidgets/QtWidgets>

class ProccessList : public QScrollArea
{
Q_OBJECT

public:
ProccessList(QWidget* parent = nullptr);
void AddProccess(int index);

signals:
void NumberOfProccessesChanged(int value);

private slots:
void RemoveProccess(QWidget* widget);

private:
QHBoxLayout* m_mainLayout;;
QWidget* m_centralWidget;

int m_numberOfProccesses;

void CreateMainLayout();
};

#endif

0 comments on commit a5656e0

Please sign in to comment.