mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
NewElementWizard class : remove the use of ElementsCategoriesWidget and ElementsCategory
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4483 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -378,7 +378,6 @@ void ElementsCollectionWidget::newElement()
|
|||||||
if (!selected_category) return;
|
if (!selected_category) return;
|
||||||
|
|
||||||
NewElementWizard elmt_wizard(this);
|
NewElementWizard elmt_wizard(this);
|
||||||
elmt_wizard.preselectCategory(selected_category);
|
|
||||||
elmt_wizard.exec();
|
elmt_wizard.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,12 +377,7 @@ void ElementsPanelWidget::removeTitleBlockTemplate() {
|
|||||||
Appelle l'assistant de creation de nouvel element
|
Appelle l'assistant de creation de nouvel element
|
||||||
*/
|
*/
|
||||||
void ElementsPanelWidget::newElement() {
|
void ElementsPanelWidget::newElement() {
|
||||||
ElementsCategory *selected_category = writableSelectedCategory();
|
|
||||||
|
|
||||||
NewElementWizard new_element_wizard(this);
|
NewElementWizard new_element_wizard(this);
|
||||||
if (selected_category) {
|
|
||||||
new_element_wizard.preselectCategory(selected_category);
|
|
||||||
}
|
|
||||||
new_element_wizard.exec();
|
new_element_wizard.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,12 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "newelementwizard.h"
|
#include "newelementwizard.h"
|
||||||
#include "elementscategory.h"
|
|
||||||
#include "elementscategorieswidget.h"
|
|
||||||
#include "elementscategorieslist.h"
|
|
||||||
#include "nameslistwidget.h"
|
#include "nameslistwidget.h"
|
||||||
#include "qetgraphicsitem/element.h"
|
|
||||||
#include "qetelementeditor.h"
|
#include "qetelementeditor.h"
|
||||||
#include "qet.h"
|
|
||||||
#include "qetapp.h"
|
|
||||||
#include "elementscollectionitem.h"
|
|
||||||
#include "qfilenameedit.h"
|
#include "qfilenameedit.h"
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
|
#include "elementscollectionmodel.h"
|
||||||
|
#include "elementcollectionitem.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -34,8 +29,7 @@
|
|||||||
@param f flags pour le dialogue
|
@param f flags pour le dialogue
|
||||||
*/
|
*/
|
||||||
NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
|
NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
|
||||||
QWizard(parent, f),
|
QWizard(parent, f)
|
||||||
chosen_category(0)
|
|
||||||
{
|
{
|
||||||
setOptions(options() & ~QWizard::NoCancelButton);
|
setOptions(options() & ~QWizard::NoCancelButton);
|
||||||
|
|
||||||
@@ -61,36 +55,9 @@ NewElementWizard::~NewElementWizard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return la categorie parente selectionnee, ou 0 si celle-ci n'a pas encore
|
* @brief NewElementWizard::buildStep1
|
||||||
ete choisie.
|
* @return
|
||||||
*/
|
*/
|
||||||
ElementsCategory *NewElementWizard::selectedCategory() const {
|
|
||||||
return(chosen_category);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param category Categorie d'elements dans laquelle le nouvel element sera
|
|
||||||
place
|
|
||||||
@return true si ce choix est possible et a ete pris en compte, false sinon
|
|
||||||
*/
|
|
||||||
bool NewElementWizard::preselectCategory(ElementsCategory *category) {
|
|
||||||
// verifie si la categorie est utilisable
|
|
||||||
if (!category || !category -> exists() || !category -> isWritable()) {
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// selectionne la categorie ainsi demandee dans la liste
|
|
||||||
if (categories_list -> elementsCategoriesList().selectLocation(category -> location())) {
|
|
||||||
chosen_category = category;
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Met en place l'etape 1 : Categorie
|
|
||||||
*/
|
|
||||||
QWizardPage *NewElementWizard::buildStep1() {
|
QWizardPage *NewElementWizard::buildStep1() {
|
||||||
QWizardPage *page = new QWizardPage();
|
QWizardPage *page = new QWizardPage();
|
||||||
page -> setProperty("WizardState", Category);
|
page -> setProperty("WizardState", Category);
|
||||||
@@ -98,16 +65,22 @@ QWizardPage *NewElementWizard::buildStep1() {
|
|||||||
page -> setSubTitle(tr("Sélectionnez une catégorie dans laquelle enregistrer le nouvel élément.", "wizard page subtitle"));
|
page -> setSubTitle(tr("Sélectionnez une catégorie dans laquelle enregistrer le nouvel élément.", "wizard page subtitle"));
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
QVBoxLayout *layout = new QVBoxLayout();
|
||||||
|
|
||||||
categories_list = new ElementsCategoriesWidget();
|
m_tree_view = new QTreeView(this);
|
||||||
layout -> addWidget(categories_list);
|
ElementsCollectionModel *model_ = new ElementsCollectionModel(m_tree_view);
|
||||||
|
model_->addCustomCollection();
|
||||||
|
m_tree_view->setModel(model_);
|
||||||
|
m_tree_view->setHeaderHidden(true);
|
||||||
|
layout->addWidget(m_tree_view);
|
||||||
|
|
||||||
|
|
||||||
page -> setLayout(layout);
|
page -> setLayout(layout);
|
||||||
return(page);
|
return(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met en place l'etape 2 : Nom du fichier
|
* @brief NewElementWizard::buildStep2
|
||||||
*/
|
* @return
|
||||||
|
*/
|
||||||
QWizardPage *NewElementWizard::buildStep2() {
|
QWizardPage *NewElementWizard::buildStep2() {
|
||||||
QWizardPage *page = new QWizardPage();
|
QWizardPage *page = new QWizardPage();
|
||||||
page -> setProperty("WizardState", Filename);
|
page -> setProperty("WizardState", Filename);
|
||||||
@@ -115,12 +88,12 @@ QWizardPage *NewElementWizard::buildStep2() {
|
|||||||
page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel élément.", "wizard page subtitle"));
|
page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel élément.", "wizard page subtitle"));
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
QVBoxLayout *layout = new QVBoxLayout();
|
||||||
|
|
||||||
qle_filename = new QFileNameEdit(tr("nouvel_element"));
|
m_qle_filename = new QFileNameEdit(tr("nouvel_element"));
|
||||||
qle_filename -> selectAll();
|
m_qle_filename -> selectAll();
|
||||||
QLabel *explication2 = new QLabel(tr("Vous n'êtes pas obligé de préciser l'extension *.elmt. Elle sera ajoutée automatiquement."));
|
QLabel *explication2 = new QLabel(tr("Vous n'êtes pas obligé de préciser l'extension *.elmt. Elle sera ajoutée automatiquement."));
|
||||||
explication2 -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
explication2 -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
||||||
explication2 -> setWordWrap(true);
|
explication2 -> setWordWrap(true);
|
||||||
layout -> addWidget(qle_filename);
|
layout -> addWidget(m_qle_filename);
|
||||||
layout -> addWidget(explication2);
|
layout -> addWidget(explication2);
|
||||||
layout -> addSpacing(100);
|
layout -> addSpacing(100);
|
||||||
|
|
||||||
@@ -129,8 +102,9 @@ QWizardPage *NewElementWizard::buildStep2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met en place l'etape 3 : Noms de l'element
|
* @brief NewElementWizard::buildStep3
|
||||||
*/
|
* @return
|
||||||
|
*/
|
||||||
QWizardPage *NewElementWizard::buildStep3() {
|
QWizardPage *NewElementWizard::buildStep3() {
|
||||||
QWizardPage *page = new QWizardPage();
|
QWizardPage *page = new QWizardPage();
|
||||||
page -> setProperty("WizardState", Names);
|
page -> setProperty("WizardState", Names);
|
||||||
@@ -138,112 +112,107 @@ QWizardPage *NewElementWizard::buildStep3() {
|
|||||||
page -> setSubTitle(tr("Indiquez le ou les noms de l'élément.", "wizard page subtitle"));
|
page -> setSubTitle(tr("Indiquez le ou les noms de l'élément.", "wizard page subtitle"));
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
QVBoxLayout *layout = new QVBoxLayout();
|
||||||
|
|
||||||
element_names = new NamesListWidget();
|
m_names_list = new NamesListWidget();
|
||||||
NamesList hash_name;
|
NamesList hash_name;
|
||||||
hash_name.addName(QLocale::system().name().left(2), tr("Nom du nouvel élément", "default name when creating a new element"));
|
hash_name.addName(QLocale::system().name().left(2), tr("Nom du nouvel élément", "default name when creating a new element"));
|
||||||
element_names -> setNames(hash_name);
|
m_names_list -> setNames(hash_name);
|
||||||
layout -> addWidget(element_names);
|
layout -> addWidget(m_names_list);
|
||||||
|
|
||||||
page -> setLayout(layout);
|
page -> setLayout(layout);
|
||||||
return(page);
|
return(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return true si l'etape en cours est validee, false sinon
|
/**
|
||||||
|
* @brief NewElementWizard::validateCurrentPage
|
||||||
|
* @return true if the current step is valid
|
||||||
|
*/
|
||||||
bool NewElementWizard::validateCurrentPage() {
|
bool NewElementWizard::validateCurrentPage() {
|
||||||
WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt());
|
WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt());
|
||||||
if (wizard_state == Category) return(validStep1());
|
if (wizard_state == Category) return(validStep1());
|
||||||
else if (wizard_state == Filename) return(validStep2());
|
else if (wizard_state == Filename) return(validStep2());
|
||||||
else if (wizard_state == Names) {
|
else if (wizard_state == Names) {
|
||||||
// must have one name minimum
|
// must have one name minimum
|
||||||
if (element_names -> checkOneName())
|
if (m_names_list -> checkOneName())
|
||||||
createNewElement();
|
createNewElement();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else return(true);
|
else return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Valide l'etape 1
|
* @brief NewElementWizard::validStep1
|
||||||
@return true si l'etape est validee, false sinon
|
* Valid the setp 1
|
||||||
*/
|
* @return trie if the step is valid.
|
||||||
bool NewElementWizard::validStep1() {
|
*/
|
||||||
// il doit y avoir une categorie selectionnee
|
bool NewElementWizard::validStep1()
|
||||||
|
{
|
||||||
|
//They must be one directory selected
|
||||||
bool step1_ok = false;
|
bool step1_ok = false;
|
||||||
ElementsLocation selected_location = categories_list -> elementsCategoriesList().selectedLocation();
|
|
||||||
if (ElementsCollectionItem *collection_item = QETApp::collectionItem(selected_location, false)) {
|
QModelIndex index = m_tree_view->currentIndex();
|
||||||
if (collection_item -> isCategory()) {
|
if (index.isValid()) {
|
||||||
chosen_category = qobject_cast<ElementsCategory *>(collection_item);
|
|
||||||
step1_ok = chosen_category;
|
ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(index.internalPointer());
|
||||||
|
if (eci && eci->isDir()) {
|
||||||
|
ElementsLocation loc(eci->collectionPath());
|
||||||
|
if (loc.exist()) {
|
||||||
|
m_chosen_location = loc;
|
||||||
|
step1_ok = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!step1_ok) {
|
if (!step1_ok) {
|
||||||
QET::QetMessageBox::critical(
|
QET::QetMessageBox::critical(parentWidget(),
|
||||||
parentWidget(),
|
tr("Erreur", "message box title"),
|
||||||
tr("Erreur", "message box title"),
|
tr("Vous devez sélectionner une catégorie.", "message box content"));
|
||||||
tr("Vous devez sélectionner une catégorie.", "message box content")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(step1_ok);
|
return(step1_ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Valide l'etape 2
|
* @brief NewElementWizard::validStep2
|
||||||
@return true si l'etape est validee, false sinon
|
* Valid the step 2
|
||||||
*/
|
* @return true if step is valid
|
||||||
|
*/
|
||||||
bool NewElementWizard::validStep2() {
|
bool NewElementWizard::validStep2() {
|
||||||
// il doit y avoir une categorie selectionnee
|
QString file_name = m_qle_filename -> text();
|
||||||
if (!chosen_category) return(false);
|
|
||||||
QString file_name = qle_filename -> text();
|
|
||||||
|
|
||||||
// un nom doit avoir ete entre
|
|
||||||
if (file_name.isEmpty()) {
|
if (file_name.isEmpty()) {
|
||||||
QET::QetMessageBox::critical(
|
QET::QetMessageBox::critical(this,
|
||||||
this,
|
tr("Erreur", "message box title"),
|
||||||
tr("Erreur", "message box title"),
|
tr("Vous devez entrer un nom de fichier", "message box content"));
|
||||||
tr("Vous devez entrer un nom de fichier", "message box content")
|
return false;
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_name.endsWith(".elmt")) file_name += ".elmt";
|
if (!file_name.endsWith(".elmt")) {
|
||||||
|
file_name += ".elmt";
|
||||||
// le nom de fichier contient peut etre des caracteres interdits
|
|
||||||
if (QET::containsForbiddenCharacters(file_name)) {
|
|
||||||
QET::QetMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("Erreur", "message box title"),
|
|
||||||
tr("Merci de ne pas utiliser les caractères suivants : \\ / : * ? \" < > |", "message box content")
|
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// le fichier existe peut etre deja
|
ElementsLocation loc_ = m_chosen_location;
|
||||||
if (chosen_category -> element(file_name)) {
|
loc_.addToPath(file_name);
|
||||||
QMessageBox::StandardButton answer = QET::QetMessageBox::question(
|
if (loc_.exist()) {
|
||||||
this,
|
QET::QetMessageBox::critical(this,
|
||||||
"Écraser le fichier ?",
|
tr("Erreur", "message box title"),
|
||||||
"Le fichier existe déjà. Souhaitez-vous l'écraser ?",
|
tr("Un élément portant le même nom existe déjà"));
|
||||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
return false;
|
||||||
QMessageBox::No
|
|
||||||
);
|
|
||||||
return(answer == QMessageBox::Yes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chosen_file = file_name;
|
m_chosen_file = file_name;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cree le nouvel element
|
* @brief NewElementWizard::createNewElement
|
||||||
*/
|
* Lauch an element editor for create the new element
|
||||||
|
*/
|
||||||
void NewElementWizard::createNewElement() {
|
void NewElementWizard::createNewElement() {
|
||||||
QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
|
QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
|
||||||
edit_new_element -> setNames(element_names -> names());
|
edit_new_element -> setNames(m_names_list -> names());
|
||||||
|
|
||||||
ElementsLocation new_element_location = chosen_category -> location();
|
ElementsLocation loc_ = m_chosen_location;
|
||||||
new_element_location.addToPath(chosen_file);
|
loc_.addToPath(m_chosen_file);
|
||||||
edit_new_element -> setLocation(new_element_location);
|
edit_new_element -> setLocation(loc_);
|
||||||
edit_new_element -> show();
|
edit_new_element -> show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef NEW_ELEMENT_WIZARD_H
|
#ifndef NEW_ELEMENT_WIZARD_H
|
||||||
#define NEW_ELEMENT_WIZARD_H
|
#define NEW_ELEMENT_WIZARD_H
|
||||||
#include <QtWidgets>
|
|
||||||
class ElementsCategoriesWidget;
|
#include <QWizard>
|
||||||
class ElementsCategory;
|
#include "elementslocation.h"
|
||||||
|
|
||||||
class NamesListWidget;
|
class NamesListWidget;
|
||||||
class QFileNameEdit;
|
class QFileNameEdit;
|
||||||
|
class QTreeView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a wizard dialog enabling users to to specify the basic
|
This class provides a wizard dialog enabling users to to specify the basic
|
||||||
parameters of the electrical elements they intend to draw.
|
parameters of the electrical elements they intend to draw.
|
||||||
@@ -42,20 +45,14 @@ class NewElementWizard : public QWizard {
|
|||||||
private:
|
private:
|
||||||
NewElementWizard(const NewElementWizard &);
|
NewElementWizard(const NewElementWizard &);
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
ElementsCategory *selectedCategory() const;
|
|
||||||
bool preselectCategory(ElementsCategory *);
|
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
enum WizardState { Category, Filename, Names };
|
enum WizardState { Category, Filename, Names };
|
||||||
ElementsCategoriesWidget *categories_list;
|
QFileNameEdit *m_qle_filename;
|
||||||
QFileNameEdit *qle_filename;
|
NamesListWidget *m_names_list;
|
||||||
NamesListWidget *element_names;
|
QString m_chosen_file;
|
||||||
WizardState current_state;
|
QTreeView *m_tree_view = nullptr;
|
||||||
QString chosen_file;
|
ElementsLocation m_chosen_location;
|
||||||
ElementsCategory *chosen_category;
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -385,38 +385,6 @@ QList<QChar> QET::forbiddenCharacters() {
|
|||||||
return(QList<QChar>() << '\\' << '/' << ':' << '*' << '?' << '"' << '<' << '>' << '|');
|
return(QList<QChar>() << '\\' << '/' << ':' << '*' << '?' << '"' << '<' << '>' << '|');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return une chaine listant les caracteres interdits dans les noms de fichiers sous
|
|
||||||
Windows
|
|
||||||
@param escape true pour remplacer les caracteres < et > par leurs entites HTML
|
|
||||||
*/
|
|
||||||
QString QET::forbiddenCharactersString(bool escape) {
|
|
||||||
QString result;
|
|
||||||
foreach(QChar c, QET::forbiddenCharacters()) {
|
|
||||||
if (escape) {
|
|
||||||
if (c == '<') result += "<";
|
|
||||||
else if (c == '>') result += ">";
|
|
||||||
else result += QString(c);
|
|
||||||
} else {
|
|
||||||
result += QString(c);
|
|
||||||
}
|
|
||||||
result += " ";
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param string une chaine de caracteres
|
|
||||||
@return true si string contient un caractere interdit dans les noms de
|
|
||||||
fichiers sous Windows
|
|
||||||
*/
|
|
||||||
bool QET::containsForbiddenCharacters(const QString &string) {
|
|
||||||
foreach(QChar c, QET::forbiddenCharacters()) {
|
|
||||||
if (string.contains(c)) return(true);
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cette fonction transforme une chaine de caracteres (typiquement : un nom de
|
Cette fonction transforme une chaine de caracteres (typiquement : un nom de
|
||||||
schema, de projet, d'element) en un nom de fichier potable.
|
schema, de projet, d'element) en un nom de fichier potable.
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ namespace QET {
|
|||||||
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
||||||
QList<QChar> forbiddenCharacters();
|
QList<QChar> forbiddenCharacters();
|
||||||
QString forbiddenCharactersString(bool = false);
|
QString forbiddenCharactersString(bool = false);
|
||||||
bool containsForbiddenCharacters(const QString &);
|
|
||||||
QString stringToFileName(const QString &);
|
QString stringToFileName(const QString &);
|
||||||
QString escapeSpaces(const QString &);
|
QString escapeSpaces(const QString &);
|
||||||
QString unescapeSpaces(const QString &);
|
QString unescapeSpaces(const QString &);
|
||||||
|
|||||||
Reference in New Issue
Block a user