2015-11-27 13:53:39 +01:00
|
|
|
#ifndef FILTER_GUI_C
|
|
|
|
#define FILTER_GUI_C
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QColor>
|
|
|
|
#include <qboxlayout.h>
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
class FilterGui {
|
|
|
|
|
|
|
|
private:
|
|
|
|
QTableWidget* widget;
|
|
|
|
|
2015-11-27 14:17:54 +01:00
|
|
|
int size;
|
|
|
|
int* data;
|
|
|
|
|
|
|
|
void recreateDataStorage() {
|
|
|
|
if(data != NULL) {
|
|
|
|
delete data;
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
int fields = this->size * this->size;
|
|
|
|
data = (int*) malloc(sizeof(int) * fields);
|
|
|
|
for(int i=0; i<fields; i++) data[i] = 0;
|
|
|
|
}
|
2015-11-27 13:53:39 +01:00
|
|
|
|
|
|
|
void updateGui() {
|
2015-11-27 14:17:54 +01:00
|
|
|
this->widget->setRowCount(this->size);
|
|
|
|
this->widget->setColumnCount(this->size);
|
|
|
|
for(int i=0; i<this->size; i++) {
|
|
|
|
for(int j=0; j<this->size; j++) {
|
2015-11-27 13:53:39 +01:00
|
|
|
this->widget->setItem(i, j, new QTableWidgetItem("0"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-11-27 14:17:54 +01:00
|
|
|
|
|
|
|
void fetchData() {
|
|
|
|
for(int i=0; i<this->size; i++) {
|
|
|
|
for(int j=0; j<this->size; j++) {
|
|
|
|
QString temp = this->widget->item(i, j)->text();
|
|
|
|
this->data[i*this->size + j] = temp.toInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-11-27 13:53:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
FilterGui(int filter_size = 3) {
|
2015-11-27 14:17:54 +01:00
|
|
|
this->data = NULL;
|
2015-11-27 13:53:39 +01:00
|
|
|
this->widget = new QTableWidget();
|
|
|
|
this->setSize(filter_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
~FilterGui() {
|
2015-11-27 14:17:54 +01:00
|
|
|
if(this->widget != NULL) {
|
|
|
|
delete this->widget;
|
|
|
|
this->widget = NULL;
|
|
|
|
}
|
|
|
|
if(this->data != NULL) {
|
|
|
|
delete this->data;
|
|
|
|
this->data = NULL;
|
|
|
|
}
|
2015-11-27 13:53:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
QTableWidget* getWidget() {
|
|
|
|
return this->widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setSize(int size) {
|
2015-11-27 14:17:54 +01:00
|
|
|
this->size = size;
|
2015-11-27 13:53:39 +01:00
|
|
|
this->updateGui();
|
|
|
|
};
|
|
|
|
|
|
|
|
int getSize() {
|
2015-11-27 14:17:54 +01:00
|
|
|
return this->size;
|
2015-11-27 13:53:39 +01:00
|
|
|
};
|
2015-11-27 14:17:54 +01:00
|
|
|
|
|
|
|
int* getData() {
|
|
|
|
this->recreateDataStorage();
|
|
|
|
this->fetchData();
|
|
|
|
return this->data;
|
|
|
|
}
|
2015-11-27 13:53:39 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|