mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user