Files
qelectrotech-source-mirror/sources/newelementwizard.cpp
T
ispyisail f5962ecd06 Make English the source language of the interface text
Every tr() source string in the code and the forms is now the English
text, and French is a translation (qet_fr.ts) like the other languages.
Generated, not hand-edited: master ef795a21e5 converted by
qet-en-source (harness 4c4ddc9).

3144 messages get an English source, 665 already had one, 0 left French; 8 shared-wording pairs disambiguated.
C++: 2904 literals in 233 files. Forms: 809 strings in 65 files. All 34 .ts files re-keyed; qet_fr.ts filled.
lupdate check: PASS. What each of 38 languages shows, old vs new: same 118266, English instead of French 38433, comment fallback 51, differences 0.
2026-10-08 12:50:13 +13:00

263 lines
7.1 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "newelementwizard.h"
#include "ElementsCollection/elementcollectionitem.h"
#include "ElementsCollection/elementscollectionmodel.h"
#include "ElementsCollection/elementstreeview.h"
#include "NameList/ui/namelistwidget.h"
#include "editor/ui/qetelementeditor.h"
#include "qetmessagebox.h"
#include "qfilenameedit.h"
#include <QIcon>
#include <QTreeView>
#include <QVBoxLayout>
#include <QLabel>
/**
Constructeur
@param parent QWidget parent de ce dialogue
@param f flags pour le dialogue
*/
NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
QWizard(parent, f)
{
setOptions(options() & ~QWizard::NoCancelButton);
#ifdef Q_OS_WIN
setWizardStyle(QWizard::AeroStyle);
#elif defined(Q_OS_MAC)
setWizardStyle(QWizard::MacStyle);
#endif
setPixmap(LogoPixmap, QIcon::fromTheme("qelectrotech").pixmap(64, 64));
setWindowTitle(tr("Create a new element: wizard", "window title"));
setButtonText(QWizard::NextButton, tr("&Next >"));
addPage(buildStep1());
addPage(buildStep2());
addPage(buildStep3());
}
/**
Destructeur
*/
NewElementWizard::~NewElementWizard()
{
}
/**
@brief NewElementWizard::preselectedLocation
Select item in the tree view represented by location,
@param location
*/
void NewElementWizard::preselectedLocation(const ElementsLocation &location)
{
QModelIndex index = m_model->indexFromLocation(location);
if (index.isValid()) {
m_tree_view->scrollTo(index);
m_tree_view->setCurrentIndex(index);
}
}
/**
@brief NewElementWizard::buildStep1
@return
*/
QWizardPage *NewElementWizard::buildStep1()
{
QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Category);
page -> setTitle(tr("Step 1 of 3: Parent category", "wizard page title"));
page -> setSubTitle(tr("Select a category which to save the new element in.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout();
m_tree_view = new ElementsTreeView(this);
m_model = new ElementsCollectionModel(m_tree_view);
m_model->hideElement();
m_model->addCustomCollection();
m_model->addCompanyCollection();
m_tree_view->setModel(m_model);
m_tree_view->setHeaderHidden(true);
m_tree_view->setAnimated(true);
layout->addWidget(m_tree_view);
page->setLayout(layout);
return(page);
}
/**
@brief NewElementWizard::buildStep2
@return
*/
QWizardPage *NewElementWizard::buildStep2()
{
QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Filename);
page -> setTitle(tr("Step 2 of 3: Filename", "wizard page title"));
page -> setSubTitle(tr("Enter the name of the file for the new element.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout();
m_qle_filename = new QFileNameEdit(tr("new_element"));
m_qle_filename -> selectAll();
QLabel *explication2 = new QLabel(tr("You don't have to specify the *.elmt extension. It will be added automatically."));
explication2 -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
explication2 -> setWordWrap(true);
layout -> addWidget(m_qle_filename);
layout -> addWidget(explication2);
layout -> addSpacing(100);
page -> setLayout(layout);
return(page);
}
/**
@brief NewElementWizard::buildStep3
@return
*/
QWizardPage *NewElementWizard::buildStep3()
{
QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Names);
page -> setTitle(tr("Step 3 of 3: Element names", "wizard page title"));
page -> setSubTitle(tr("Enter one or more names for the element.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout();
m_names_list = new NameListWidget(this);
NamesList hash_name;
hash_name.addName(QLocale::system().name().left(2), tr("New element name", "default name when creating a new element"));
m_names_list -> setNames(hash_name);
layout -> addWidget(m_names_list);
page -> setLayout(layout);
return(page);
}
/**
@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 (!m_names_list->isEmpty()) {
createNewElement();
}
return true;
}
else return(true);
}
/**
@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;
QModelIndex index = m_tree_view->currentIndex();
if (index.isValid()) {
ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(m_model->itemFromIndex(index));
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("Error", "message box title"),
tr("You must select a category.", "message box content"));
}
return(step1_ok);
}
/**
@brief NewElementWizard::validStep2
Valid the step 2
@return true if step is valid
*/
bool NewElementWizard::validStep2()
{
QString file_name = m_qle_filename -> text();
if (file_name.isEmpty()) {
QET::QetMessageBox::critical(this,
tr("Error", "message box title"),
tr("You must enter a filename", "message box content"));
return false;
}
if (!file_name.endsWith(".elmt")) {
file_name += ".elmt";
}
ElementsLocation loc_ = m_chosen_location;
loc_.addToPath(file_name);
if (loc_.exist()) {
QET::QetMessageBox::critical(this,
tr("Error", "message box title"),
tr("An element with the same name already exists"));
return false;
}
m_chosen_file = file_name;
return(true);
}
/**
@brief NewElementWizard::createNewElement
Launch an element editor to create the new element
*/
void NewElementWizard::createNewElement()
{
QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
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();
// Without this, the just-closed wizard can leave the main window
// as the active/key window (bugtracker #281, reported on macOS):
// the new editor is created and shown, but stays behind the main
// window and doesn't surface in the Dock/Windows menu.
edit_new_element -> raise();
edit_new_element -> activateWindow();
}