92 lines
1.7 KiB
C++
92 lines
1.7 KiB
C++
#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;
|
|
|
|
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;
|
|
}
|
|
|
|
void updateGui() {
|
|
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++) {
|
|
this->widget->setItem(i, j, new QTableWidgetItem("0"));
|
|
}
|
|
}
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|
|
};
|
|
|
|
public:
|
|
FilterGui(int filter_size = 3) {
|
|
this->data = NULL;
|
|
this->widget = new QTableWidget();
|
|
this->setSize(filter_size);
|
|
};
|
|
|
|
~FilterGui() {
|
|
if(this->widget != NULL) {
|
|
delete this->widget;
|
|
this->widget = NULL;
|
|
}
|
|
if(this->data != NULL) {
|
|
delete this->data;
|
|
this->data = NULL;
|
|
}
|
|
};
|
|
|
|
QTableWidget* getWidget() {
|
|
return this->widget;
|
|
};
|
|
|
|
void setSize(int size) {
|
|
this->size = size;
|
|
this->updateGui();
|
|
};
|
|
|
|
int getSize() {
|
|
return this->size;
|
|
};
|
|
|
|
int* getData() {
|
|
this->recreateDataStorage();
|
|
this->fetchData();
|
|
return this->data;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
#endif
|