Commit 03f5f426 authored by Yann Boucher's avatar Yann Boucher
Browse files

Implemented dialog for loading a model, and behavior for customizing it

parent 0cb352ba
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1101</width>
<height>706</height>
<width>1092</width>
<height>754</height>
</rect>
</property>
<property name="windowTitle">
......@@ -51,7 +51,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="simulation_tab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -395,153 +395,196 @@ pattern recorded :</string>
<property name="title">
<string>Rules</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="openRuleButton">
<property name="text">
<string>(file) Open rule</string>
<layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="rule_settings">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="statesNeighborhoodLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="neighborhoodLabel">
<property name="text">
<string>Neighborhood :</string>
</property>
<property name="buddy">
<cstring>neighborhood_list</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="neighborhood_list">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="statesSettingsButton">
<property name="text">
<string>States settings (color...)</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="cusumNeighborhoodButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Custom neighborhood</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="nbrStatesComboBox">
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
<property name="title">
<string>Settings</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="transitionFunctionLabel">
<property name="text">
<string>Transition function :</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="statesNeighborhoodLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="neighborhoodLabel">
<property name="text">
<string>Neighborhood :</string>
</property>
<property name="buddy">
<cstring>neighborhood_list</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="neighborhood_list">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="statesSettingsButton">
<property name="text">
<string>States settings (color...)</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="cusumNeighborhoodButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Custom neighborhood</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="nbrStatesComboBox">
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="nbrStatesLabel">
<property name="text">
<string>Number of states :</string>
</property>
<property name="buddy">
<cstring>nbrStatesComboBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="radiusLabel">
<property name="text">
<string>Radius r :</string>
</property>
<property name="buddy">
<cstring>radiusSpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="radiusSpinBox">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="transition_list"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="rule_settings_area">
<property name="title">
<string>Transition rule settings</string>
</property>
</item>
<item>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="informationLabel">
<property name="text">
<string>7</string>
<string>New rule must be saved before running simulation</string>
</property>
</item>
<item>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="saveRuleButton">
<property name="text">
<string>8</string>
<string>Save rule</string>
</property>
</item>
</widget>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QPushButton" name="openRuleButton">
<property name="text">
<string>Load rule</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="customize_button">
<property name="text">
<string>Customize...</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_2">
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="nbrStatesLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Number of states :</string>
</property>
<property name="buddy">
<cstring>nbrStatesComboBox</cstring>
<string>Name : </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="radiusLabel">
<property name="text">
<string>Radius r :</string>
</property>
<property name="buddy">
<cstring>radiusSpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="radiusSpinBox">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="transitionFunctionLabel">
<item row="0" column="1">
<widget class="QLabel" name="rule_name">
<property name="text">
<string>Transition function :</string>
<string>RuleName</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="transition_list"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="rule_settings_area">
<property name="title">
<string>Transition rule settings</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="informationLabel">
<property name="text">
<string>New rule must be saved before running simulation</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveRuleButton">
<property name="text">
<string>Save rule</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -577,7 +620,7 @@ pattern recorded :</string>
<rect>
<x>0</x>
<y>0</y>
<width>1101</width>
<width>1092</width>
<height>25</height>
</rect>
</property>
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ModelLoadingDialog</class>
<widget class="QDialog" name="ModelLoadingDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>385</width>
<height>639</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTreeWidget" name="tree">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>5</verstretch>
</sizepolicy>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Title : </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="title">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_struct_author">
<property name="text">
<string>Author : </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="author">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Date : </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="date">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Description : </string>
</property>
<property name="buddy">
<cstring>desc</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPlainTextEdit" name="desc">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ModelLoadingDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>229</x>
<y>617</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ModelLoadingDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>297</x>
<y>623</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -66,6 +66,8 @@ private slots:
void on_saveRuleButton_clicked();
void on_customize_button_clicked();
private:
//! \brief Initialiser la liste des transitions et voisinages disponibles
void init_transition_neighborhood_list();
......@@ -73,6 +75,20 @@ private:
//! \brief Mets à jour le widget contenant les paramètres pour la règle de transition choisie
void update_transition_settings();
//! \brief Configure pour activer la customisation d'une règle actuelle
void enable_rule_customization();
//! \brief Configure pour désactiver la customisation d'une règle actuelle
void disable_rule_customization();
//! \brief Charge un modèle d'automate à partir d'un objet JSON
void load_model(const QJsonObject& obj);
//! \brief Déclenche la confirmation et la sauvegarde du modèle édité actuel
void save_model();
//! \brief Retourne le modèle par défaut à charger
QJsonObject default_model() const;
private:
Ui::MainWindow *ui;
};
......
#ifndef MODELLOADINGDIALOG_HPP
#define MODELLOADINGDIALOG_HPP
#include <QDialog>
#include <QDir>
#include <QTreeWidgetItem>
#include <QFileSystemWatcher>
#include <QJsonObject>
namespace Ui {
class ModelLoadingDialog;
}
class ModelLoadingException : public std::exception
{
std::string _msg;
public:
ModelLoadingException(const std::string& msg) : _msg(msg){}
virtual const char* what() const noexcept override
{
return _msg.c_str();
}
};
class ModelLoadingDialog : public QDialog
{
Q_OBJECT
public:
explicit ModelLoadingDialog(QWidget *parent = nullptr);
~ModelLoadingDialog();
//! \brief Retoure le modèle choisi en tant qu'objet JSON.
QJsonObject model() const;
protected:
void done(int r);
private:
void load_models();
QTreeWidgetItem *add_directory_contents(const QDir& dir);
private slots:
void update_info(QTreeWidgetItem* item, int column);
private:
Ui::ModelLoadingDialog *ui;
QFileSystemWatcher m_watcher;
QJsonObject m_current_model;
};
#endif // MODELLOADINGDIALOG_HPP
......@@ -159,7 +159,7 @@ struct IntegerProperty : public PropertyImpl<IntegerProperty>
public:
//! \brief Construit un objet IntegerProperty avec une valeur min et une valeur max, non borné par défaut.
IntegerProperty(int min_value = std::numeric_limits<int>::min(), int max_value = std::numeric_limits<int>::max())
: prop_min(min_value), prop_max(max_value)
: val(min_value), prop_min(min_value), prop_max(max_value)
{}
public:
......
......@@ -7,6 +7,7 @@
#include "transitionrule.hpp"
#include "neighborhoodrule.hpp"
#include "propertyvisitors.hpp"
#include "modelloadingdialog.hpp"
#include <QJsonArray>
......@@ -26,6 +27,8 @@ MainWindow::MainWindow(QWidget *parent)
{ update_transition_settings(); });