mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02: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:
parent
d36fe97611
commit
3261809227
@ -378,7 +378,6 @@ void ElementsCollectionWidget::newElement()
|
||||
if (!selected_category) return;
|
||||
|
||||
NewElementWizard elmt_wizard(this);
|
||||
elmt_wizard.preselectCategory(selected_category);
|
||||
elmt_wizard.exec();
|
||||
}
|
||||
|
||||
|
@ -376,13 +376,8 @@ void ElementsPanelWidget::removeTitleBlockTemplate() {
|
||||
/**
|
||||
Appelle l'assistant de creation de nouvel element
|
||||
*/
|
||||
void ElementsPanelWidget::newElement() {
|
||||
ElementsCategory *selected_category = writableSelectedCategory();
|
||||
|
||||
void ElementsPanelWidget::newElement() {
|
||||
NewElementWizard new_element_wizard(this);
|
||||
if (selected_category) {
|
||||
new_element_wizard.preselectCategory(selected_category);
|
||||
}
|
||||
new_element_wizard.exec();
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,12 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "newelementwizard.h"
|
||||
#include "elementscategory.h"
|
||||
#include "elementscategorieswidget.h"
|
||||
#include "elementscategorieslist.h"
|
||||
#include "nameslistwidget.h"
|
||||
#include "qetgraphicsitem/element.h"
|
||||
#include "qetelementeditor.h"
|
||||
#include "qet.h"
|
||||
#include "qetapp.h"
|
||||
#include "elementscollectionitem.h"
|
||||
#include "qfilenameedit.h"
|
||||
#include "qetmessagebox.h"
|
||||
#include "elementscollectionmodel.h"
|
||||
#include "elementcollectionitem.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@ -34,8 +29,7 @@
|
||||
@param f flags pour le dialogue
|
||||
*/
|
||||
NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
|
||||
QWizard(parent, f),
|
||||
chosen_category(0)
|
||||
QWizard(parent, f)
|
||||
{
|
||||
setOptions(options() & ~QWizard::NoCancelButton);
|
||||
|
||||
@ -61,53 +55,32 @@ NewElementWizard::~NewElementWizard() {
|
||||
}
|
||||
|
||||
/**
|
||||
@return la categorie parente selectionnee, ou 0 si celle-ci n'a pas encore
|
||||
ete choisie.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
* @brief NewElementWizard::buildStep1
|
||||
* @return
|
||||
*/
|
||||
QWizardPage *NewElementWizard::buildStep1() {
|
||||
QWizardPage *page = new QWizardPage();
|
||||
page -> setProperty("WizardState", Category);
|
||||
page -> setTitle(tr("Étape 1/3 : Catégorie parente", "wizard page title"));
|
||||
page -> setSubTitle(tr("Sélectionnez une catégorie dans laquelle enregistrer le nouvel élément.", "wizard page subtitle"));
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
|
||||
categories_list = new ElementsCategoriesWidget();
|
||||
layout -> addWidget(categories_list);
|
||||
|
||||
m_tree_view = new QTreeView(this);
|
||||
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);
|
||||
return(page);
|
||||
}
|
||||
|
||||
/**
|
||||
Met en place l'etape 2 : Nom du fichier
|
||||
*/
|
||||
* @brief NewElementWizard::buildStep2
|
||||
* @return
|
||||
*/
|
||||
QWizardPage *NewElementWizard::buildStep2() {
|
||||
QWizardPage *page = new QWizardPage();
|
||||
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"));
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
|
||||
qle_filename = new QFileNameEdit(tr("nouvel_element"));
|
||||
qle_filename -> selectAll();
|
||||
m_qle_filename = new QFileNameEdit(tr("nouvel_element"));
|
||||
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."));
|
||||
explication2 -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
||||
explication2 -> setWordWrap(true);
|
||||
layout -> addWidget(qle_filename);
|
||||
layout -> addWidget(m_qle_filename);
|
||||
layout -> addWidget(explication2);
|
||||
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 *page = new QWizardPage();
|
||||
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"));
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
|
||||
element_names = new NamesListWidget();
|
||||
m_names_list = new NamesListWidget();
|
||||
NamesList hash_name;
|
||||
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);
|
||||
layout -> addWidget(element_names);
|
||||
m_names_list -> setNames(hash_name);
|
||||
layout -> addWidget(m_names_list);
|
||||
|
||||
page -> setLayout(layout);
|
||||
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() {
|
||||
WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt());
|
||||
if (wizard_state == Category) return(validStep1());
|
||||
else if (wizard_state == Filename) return(validStep2());
|
||||
else if (wizard_state == Names) {
|
||||
// must have one name minimum
|
||||
if (element_names -> checkOneName())
|
||||
if (m_names_list -> checkOneName())
|
||||
createNewElement();
|
||||
return true;
|
||||
|
||||
}
|
||||
else return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Valide l'etape 1
|
||||
@return true si l'etape est validee, false sinon
|
||||
*/
|
||||
bool NewElementWizard::validStep1() {
|
||||
// il doit y avoir une categorie selectionnee
|
||||
* @brief NewElementWizard::validStep1
|
||||
* Valid the setp 1
|
||||
* @return trie if the step is valid.
|
||||
*/
|
||||
bool NewElementWizard::validStep1()
|
||||
{
|
||||
//They must be one directory selected
|
||||
bool step1_ok = false;
|
||||
ElementsLocation selected_location = categories_list -> elementsCategoriesList().selectedLocation();
|
||||
if (ElementsCollectionItem *collection_item = QETApp::collectionItem(selected_location, false)) {
|
||||
if (collection_item -> isCategory()) {
|
||||
chosen_category = qobject_cast<ElementsCategory *>(collection_item);
|
||||
step1_ok = chosen_category;
|
||||
|
||||
QModelIndex index = m_tree_view->currentIndex();
|
||||
if (index.isValid()) {
|
||||
|
||||
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) {
|
||||
QET::QetMessageBox::critical(
|
||||
parentWidget(),
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Vous devez sélectionner une catégorie.", "message box content")
|
||||
);
|
||||
QET::QetMessageBox::critical(parentWidget(),
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Vous devez sélectionner une catégorie.", "message box content"));
|
||||
}
|
||||
|
||||
return(step1_ok);
|
||||
}
|
||||
|
||||
/**
|
||||
Valide l'etape 2
|
||||
@return true si l'etape est validee, false sinon
|
||||
*/
|
||||
* @brief NewElementWizard::validStep2
|
||||
* Valid the step 2
|
||||
* @return true if step is valid
|
||||
*/
|
||||
bool NewElementWizard::validStep2() {
|
||||
// il doit y avoir une categorie selectionnee
|
||||
if (!chosen_category) return(false);
|
||||
QString file_name = qle_filename -> text();
|
||||
|
||||
// un nom doit avoir ete entre
|
||||
QString file_name = m_qle_filename -> text();
|
||||
|
||||
if (file_name.isEmpty()) {
|
||||
QET::QetMessageBox::critical(
|
||||
this,
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Vous devez entrer un nom de fichier", "message box content")
|
||||
);
|
||||
return(false);
|
||||
QET::QetMessageBox::critical(this,
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Vous devez entrer un nom de fichier", "message box content"));
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!file_name.endsWith(".elmt")) {
|
||||
file_name += ".elmt";
|
||||
}
|
||||
|
||||
// le fichier existe peut etre deja
|
||||
if (chosen_category -> element(file_name)) {
|
||||
QMessageBox::StandardButton answer = QET::QetMessageBox::question(
|
||||
this,
|
||||
"Écraser le fichier ?",
|
||||
"Le fichier existe déjà. Souhaitez-vous l'écraser ?",
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
||||
QMessageBox::No
|
||||
);
|
||||
return(answer == QMessageBox::Yes);
|
||||
|
||||
ElementsLocation loc_ = m_chosen_location;
|
||||
loc_.addToPath(file_name);
|
||||
if (loc_.exist()) {
|
||||
QET::QetMessageBox::critical(this,
|
||||
tr("Erreur", "message box title"),
|
||||
tr("Un élément portant le même nom existe déjà"));
|
||||
return false;
|
||||
}
|
||||
|
||||
chosen_file = file_name;
|
||||
|
||||
m_chosen_file = file_name;
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Cree le nouvel element
|
||||
*/
|
||||
* @brief NewElementWizard::createNewElement
|
||||
* Lauch an element editor for create the new element
|
||||
*/
|
||||
void NewElementWizard::createNewElement() {
|
||||
QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
|
||||
edit_new_element -> setNames(element_names -> names());
|
||||
|
||||
ElementsLocation new_element_location = chosen_category -> location();
|
||||
new_element_location.addToPath(chosen_file);
|
||||
edit_new_element -> setLocation(new_element_location);
|
||||
edit_new_element -> setNames(m_names_list -> names());
|
||||
|
||||
ElementsLocation loc_ = m_chosen_location;
|
||||
loc_.addToPath(m_chosen_file);
|
||||
edit_new_element -> setLocation(loc_);
|
||||
edit_new_element -> show();
|
||||
}
|
||||
|
@ -17,11 +17,14 @@
|
||||
*/
|
||||
#ifndef NEW_ELEMENT_WIZARD_H
|
||||
#define NEW_ELEMENT_WIZARD_H
|
||||
#include <QtWidgets>
|
||||
class ElementsCategoriesWidget;
|
||||
class ElementsCategory;
|
||||
|
||||
#include <QWizard>
|
||||
#include "elementslocation.h"
|
||||
|
||||
class NamesListWidget;
|
||||
class QFileNameEdit;
|
||||
class QTreeView;
|
||||
|
||||
/**
|
||||
This class provides a wizard dialog enabling users to to specify the basic
|
||||
parameters of the electrical elements they intend to draw.
|
||||
@ -42,20 +45,14 @@ class NewElementWizard : public QWizard {
|
||||
private:
|
||||
NewElementWizard(const NewElementWizard &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
ElementsCategory *selectedCategory() const;
|
||||
bool preselectCategory(ElementsCategory *);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
enum WizardState { Category, Filename, Names };
|
||||
ElementsCategoriesWidget *categories_list;
|
||||
QFileNameEdit *qle_filename;
|
||||
NamesListWidget *element_names;
|
||||
WizardState current_state;
|
||||
QString chosen_file;
|
||||
ElementsCategory *chosen_category;
|
||||
QFileNameEdit *m_qle_filename;
|
||||
NamesListWidget *m_names_list;
|
||||
QString m_chosen_file;
|
||||
QTreeView *m_tree_view = nullptr;
|
||||
ElementsLocation m_chosen_location;
|
||||
|
||||
// methods
|
||||
private:
|
||||
|
@ -385,38 +385,6 @@ QList<QChar> QET::forbiddenCharacters() {
|
||||
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
|
||||
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<QChar> forbiddenCharacters();
|
||||
QString forbiddenCharactersString(bool = false);
|
||||
bool containsForbiddenCharacters(const QString &);
|
||||
QString stringToFileName(const QString &);
|
||||
QString escapeSpaces(const QString &);
|
||||
QString unescapeSpaces(const QString &);
|
||||
|
Loading…
x
Reference in New Issue
Block a user