Skip to content
Snippets Groups Projects
Commit 6957ae5f authored by Provot Bertrand's avatar Provot Bertrand
Browse files

filter editor: fixed and improved interface

parent 68fbc539
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <QSpinBox> #include <QSpinBox>
#include <QMdiArea> #include <QMdiArea>
#include <QPushButton> #include <QPushButton>
#include <QFont>
#include <QTimer> #include <QTimer>
#include <QFile> #include <QFile>
...@@ -38,18 +39,27 @@ ...@@ -38,18 +39,27 @@
#include <QtXml/QDomImplementation> #include <QtXml/QDomImplementation>
#include <QtXml/QDomElement> #include <QtXml/QDomElement>
#include <QTextStream> #include <QTextStream>
#include <QFileDialog>
#include <regex>
using namespace filtrme; using namespace filtrme;
using namespace imagein::algorithm; using namespace imagein::algorithm;
using namespace std; using namespace std;
/**
* @brief FilterEditor::FilterEditor
*
* Constructor
*/
FilterEditor::FilterEditor() FilterEditor::FilterEditor()
{ {
_nbFilters = 1; _nbFilters = 1;
initUI(); initUI();
} }
/**
* @brief FilterEditor::initUI
*/
void FilterEditor::initUI() void FilterEditor::initUI()
{ {
_filterLayout = new QVBoxLayout(); _filterLayout = new QVBoxLayout();
...@@ -59,6 +69,20 @@ void FilterEditor::initUI() ...@@ -59,6 +69,20 @@ void FilterEditor::initUI()
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
QScrollArea* scroll = new QScrollArea(); QScrollArea* scroll = new QScrollArea();
QWidget* widgetPath = new QWidget();
QHBoxLayout* hLayoutPath = new QHBoxLayout(widgetPath);
_buttonPath = new QPushButton("...");
_buttonPath->setFixedWidth(50);
QLabel* labelPath = new QLabel(tr("Filter file:"));
QLabel* labelPath2 = new QLabel(tr("Select a filter file:"));
_linePath = new QLineEdit(tr("No XML file selected!"));
_linePath->setReadOnly(true);
hLayoutPath->addWidget(labelPath);
hLayoutPath->addWidget(_linePath);
hLayoutPath->addWidget(labelPath2);
hLayoutPath->addWidget(_buttonPath);
_filterLayout->addWidget(widgetPath);
QHBoxLayout* hLayout = new QHBoxLayout(); QHBoxLayout* hLayout = new QHBoxLayout();
QWidget* widget = new QWidget(); QWidget* widget = new QWidget();
widget->setLayout(hLayout); widget->setLayout(hLayout);
...@@ -66,7 +90,7 @@ void FilterEditor::initUI() ...@@ -66,7 +90,7 @@ void FilterEditor::initUI()
QLabel *label_3; QLabel *label_3;
QLabel *label_4; QLabel *label_4;
label_3 = new QLabel(); label_3 = new QLabel();
label_3->setText(tr("Name:")); label_3->setText(tr("Name of your filter:"));
_name = new QLineEdit(); _name = new QLineEdit();
label_4 = new QLabel(); label_4 = new QLabel();
label_4->setText(tr("Number of filters:")); label_4->setText(tr("Number of filters:"));
...@@ -86,40 +110,68 @@ void FilterEditor::initUI() ...@@ -86,40 +110,68 @@ void FilterEditor::initUI()
buttonBox = new QDialogButtonBox(); buttonBox = new QDialogButtonBox();
buttonBox->setOrientation(Qt::Horizontal); buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save);
// QPushButton* applyButton = buttonBox->addButton(QString::fromStdString("Apply"), QDialogButtonBox::ApplyRole); QLabel* labelInfo = new QLabel(tr("You need to select a file and a name for your filter to save it"));
_filterLayout->addWidget(buttonBox); QFont* fontInfo = new QFont(labelInfo->font());
fontInfo->setItalic(true);
labelInfo->setFont(*fontInfo);
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(save()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
// QObject::connect(applyButton, SIGNAL(clicked()), this, SLOT(apply()));
QObject::connect(spinBoxNbFilters, SIGNAL(valueChanged(int)), this, SLOT(nbFiltersChanged(int)));
_saveButton = buttonBox->button(QDialogButtonBox::Save); _saveButton = buttonBox->button(QDialogButtonBox::Save);
_saveButton->setEnabled(false); _saveButton->setEnabled(false);
QObject::connect(_name, SIGNAL(textEdited(QString)), this, SLOT(nameChanged(QString)));
QHBoxLayout* hLayoutInfo = new QHBoxLayout();
hLayoutInfo->addWidget(labelInfo);
hLayoutInfo->addWidget(buttonBox);
scroll->setWidget(widgetPrinc); scroll->setWidget(widgetPrinc);
scroll->setWidgetResizable(true); scroll->setWidgetResizable(true);
layout->addWidget(scroll); layout->addWidget(scroll);
layout->addLayout(hLayoutInfo);
this->setLayout(layout); this->setLayout(layout);
this->setMinimumSize(670, 470); this->setMinimumSize(670, 470);
this->setWindowTitle(tr("FilterEditor")); this->setWindowTitle(tr("FilterEditor"));
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(save()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
QObject::connect(spinBoxNbFilters, SIGNAL(valueChanged(int)), this, SLOT(nbFiltersChanged(int)));
QObject::connect(_name, SIGNAL(textEdited(QString)), this, SLOT(nameChanged(QString)));
QObject::connect(_buttonPath, SIGNAL(clicked()), this, SLOT(saveFile()));
} }
/**
* @brief FilterEditor::saveFile
*/
void FilterEditor::saveFile() {
QString file = QFileDialog::getSaveFileName(this, tr("Chose a file filter"), QString(), tr("XML Files (*.xml)"));
if(file.size()==0) return;
_linePath->setText(file.toUtf8());
}
/**
* @brief FilterEditor::nameChanged
* @param name
*/
void FilterEditor::nameChanged(QString name) { void FilterEditor::nameChanged(QString name) {
_saveButton->setEnabled(!name.isEmpty()); _saveButton->setEnabled(!name.isEmpty());
} }
/**
* @brief FilterEditor::save
*/
void FilterEditor::save() void FilterEditor::save()
{ {
vector<Filter*> filters; vector<Filter*> filters;
if(_name->text() == "") if(_name->text() == "")
{ {
QMessageBox msgBox(QMessageBox::Critical, tr("Error!"), tr("Your filter has to have a name to be saved.")); QMessageBox msgBox(QMessageBox::Critical, tr("Error!"), tr("Your filter needs a name to be saved."));
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec(); msgBox.exec();
return; return;
} }
//condition regex sur le format du fichier .xml
// if(...
bool ok; bool ok;
filters = validFilters(&ok); filters = validFilters(&ok);
if(ok) { if(ok) {
...@@ -128,9 +180,13 @@ void FilterEditor::save() ...@@ -128,9 +180,13 @@ void FilterEditor::save()
} }
} }
/**
* @brief FilterEditor::saveXML
* @param filtersToSave
*/
void FilterEditor::saveXML(vector<Filter*> filtersToSave) void FilterEditor::saveXML(vector<Filter*> filtersToSave)
{ {
QFile file("filters.xml"); QFile file(_linePath->text());
// document // document
QDomImplementation impl = QDomDocument().implementation(); QDomImplementation impl = QDomDocument().implementation();
// document with document type // document with document type
...@@ -163,8 +219,8 @@ void FilterEditor::saveXML(vector<Filter*> filtersToSave) ...@@ -163,8 +219,8 @@ void FilterEditor::saveXML(vector<Filter*> filtersToSave)
// We know how to treat appearance and geometry // We know how to treat appearance and geometry
if (e.attribute("name") == _name->text()) if (e.attribute("name") == _name->text())
{ {
QMessageBox msgBox(QMessageBox::Warning, tr("Warning!"), tr("This filter name is already use.")); QMessageBox msgBox(QMessageBox::Warning, tr("Warning!"), tr("This filter name is already used."));
msgBox.setInformativeText(tr("Do you want to replace it?")); msgBox.setInformativeText(tr("Do you want to overwrite it?"));
msgBox.setStandardButtons(QMessageBox::No|QMessageBox::Yes); msgBox.setStandardButtons(QMessageBox::No|QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec(); int ret = msgBox.exec();
...@@ -222,23 +278,31 @@ void FilterEditor::saveXML(vector<Filter*> filtersToSave) ...@@ -222,23 +278,31 @@ void FilterEditor::saveXML(vector<Filter*> filtersToSave)
} }
} }
/**
* @brief FilterEditor::validFilters
* @param ok
* @return
*/
vector<Filter*> FilterEditor::validFilters(bool* ok) vector<Filter*> FilterEditor::validFilters(bool* ok)
{ {
vector<Filter*> filters; vector<Filter*> filters;
*ok = true; *ok = true;
for(int i = 1; i <= _nbFilters; i++) for(int i = 2; i <= 1+_nbFilters; i++)
{ {
FilterEditorItem* item = (FilterEditorItem*)_filterLayout->itemAt(i)->widget(); FilterEditorItem* item = (FilterEditorItem*)_filterLayout->itemAt(i)->widget();
cout << "type d'item :" << _filterLayout->itemAt(i) << " \n";
Filter* f = item->validFilter(); Filter* f = item->validFilter();
cout << "out validFilter\n";
cout << "val de f : " << f << "\n";
if(f != NULL) if(f != NULL)
filters.push_back(f); filters.push_back(f);
else else
{ {
*ok = false; *ok = false;
QMessageBox msgBox(QMessageBox::Critical, tr("Error!"), tr("Every square have to be completed by int value.")); QMessageBox msgBox(QMessageBox::Critical, tr("Error!"), tr("Every square has to be filled with an integer."));
msgBox.setInformativeText(tr("Filter %1 isn't ok.").arg(i)); msgBox.setInformativeText(tr("Filter %1 is not a valid filter.").arg(i-1));
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec(); msgBox.exec();
...@@ -249,6 +313,11 @@ vector<Filter*> FilterEditor::validFilters(bool* ok) ...@@ -249,6 +313,11 @@ vector<Filter*> FilterEditor::validFilters(bool* ok)
return filters; return filters;
} }
/**
* @brief FilterEditor::cancel
*
* Manages popup window that comes when you press cancel.
*/
void FilterEditor::cancel() void FilterEditor::cancel()
{ {
QMessageBox msgBox(QMessageBox::Warning, tr("Warning!"), tr("Unsaved changes will be lost.")); QMessageBox msgBox(QMessageBox::Warning, tr("Warning!"), tr("Unsaved changes will be lost."));
...@@ -257,20 +326,30 @@ void FilterEditor::cancel() ...@@ -257,20 +326,30 @@ void FilterEditor::cancel()
msgBox.setDefaultButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec(); int ret = msgBox.exec();
if(ret == QMessageBox::Yes) if(ret == QMessageBox::Yes)
// QTimer::singleShot(200, this, SLOT(quit()));
this->reject(); this->reject();
} }
/**
* @brief FilterEditor::nbFiltersChanged
* @param nb
*/
void FilterEditor::nbFiltersChanged(const int nb) void FilterEditor::nbFiltersChanged(const int nb)
{ {
if(_nbFilters < nb) if(_nbFilters < nb)
{ {
FilterEditorItem* item = new FilterEditorItem(); while(_nbFilters!= nb){
_filterLayout->insertWidget(_nbFilters + 1, item); _nbFilters++;
FilterEditorItem* item = new FilterEditorItem();
_filterLayout->insertWidget(_nbFilters, item);
}
} }
else if(_nbFilters > nb) else if(_nbFilters > nb)
{ {
_filterLayout->removeItem(_filterLayout->itemAt(_nbFilters)); while(_nbFilters != nb){
_filterLayout->removeItem(_filterLayout->itemAt(_nbFilters));
_nbFilters--;
}
} }
_nbFilters = nb; _nbFilters = nb;
} }
...@@ -53,12 +53,15 @@ namespace filtrme ...@@ -53,12 +53,15 @@ namespace filtrme
void cancel(); void cancel();
void nbFiltersChanged(const int); void nbFiltersChanged(const int);
void nameChanged(QString); void nameChanged(QString);
void saveFile();
private: private:
void initUI(); void initUI();
void saveXML(std::vector<imagein::algorithm::Filter*> filter); void saveXML(std::vector<imagein::algorithm::Filter*> filter);
std::vector<imagein::algorithm::Filter*> validFilters(bool* ok); std::vector<imagein::algorithm::Filter*> validFilters(bool* ok);
QPushButton* _buttonPath;
QLineEdit* _linePath;
QVBoxLayout* _filterLayout; QVBoxLayout* _filterLayout;
QLineEdit* _name; QLineEdit* _name;
int _nbFilters; int _nbFilters;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment