mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
NameList widget : add a combo box for easily paste texts, like the variables for title block.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5687 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -94,7 +94,9 @@ INCLUDEPATH += sources \
|
|||||||
sources/autoNum/ui \
|
sources/autoNum/ui \
|
||||||
sources/ui/configpage \
|
sources/ui/configpage \
|
||||||
sources/SearchAndReplace \
|
sources/SearchAndReplace \
|
||||||
sources/SearchAndReplace/ui
|
sources/SearchAndReplace/ui \
|
||||||
|
sources/NameList \
|
||||||
|
sources/NameList/ui
|
||||||
|
|
||||||
|
|
||||||
# Fichiers sources
|
# Fichiers sources
|
||||||
@@ -117,7 +119,9 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
|
|||||||
$$files(sources/autoNum/ui/*.h) \
|
$$files(sources/autoNum/ui/*.h) \
|
||||||
$$files(sources/ui/configpage/*.h) \
|
$$files(sources/ui/configpage/*.h) \
|
||||||
$$files(sources/SearchAndReplace/*.h) \
|
$$files(sources/SearchAndReplace/*.h) \
|
||||||
$$files(sources/SearchAndReplace/ui/*.h)
|
$$files(sources/SearchAndReplace/ui/*.h) \
|
||||||
|
$$files(sources/NameList/*.h) \
|
||||||
|
$$files(sources/NameList/ui/*.h)
|
||||||
|
|
||||||
SOURCES += $$files(sources/*.cpp) \
|
SOURCES += $$files(sources/*.cpp) \
|
||||||
$$files(sources/editor/*.cpp) \
|
$$files(sources/editor/*.cpp) \
|
||||||
@@ -139,7 +143,9 @@ SOURCES += $$files(sources/*.cpp) \
|
|||||||
$$files(sources/autoNum/ui/*.cpp) \
|
$$files(sources/autoNum/ui/*.cpp) \
|
||||||
$$files(sources/ui/configpage/*.cpp) \
|
$$files(sources/ui/configpage/*.cpp) \
|
||||||
$$files(sources/SearchAndReplace/*.cpp) \
|
$$files(sources/SearchAndReplace/*.cpp) \
|
||||||
$$files(sources/SearchAndReplace/ui/*.cpp)
|
$$files(sources/SearchAndReplace/ui/*.cpp) \
|
||||||
|
$$files(sources/NameList/*.cpp) \
|
||||||
|
$$files(sources/NameList/ui/*.cpp)
|
||||||
|
|
||||||
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
|
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
|
||||||
RESOURCES += qelectrotech.qrc
|
RESOURCES += qelectrotech.qrc
|
||||||
@@ -160,7 +166,8 @@ FORMS += $$files(sources/richtext/*.ui) \
|
|||||||
$$files(sources/ElementsCollection/ui/*.ui) \
|
$$files(sources/ElementsCollection/ui/*.ui) \
|
||||||
$$files(sources/autoNum/ui/*.ui) \
|
$$files(sources/autoNum/ui/*.ui) \
|
||||||
$$files(sources/ui/configpage/*.ui) \
|
$$files(sources/ui/configpage/*.ui) \
|
||||||
$$files(sources/SearchAndReplace/ui/*.ui)
|
$$files(sources/SearchAndReplace/ui/*.ui) \
|
||||||
|
$$files(sources/NameList/ui/*.ui)
|
||||||
|
|
||||||
UI_SOURCES_DIR = sources/ui/
|
UI_SOURCES_DIR = sources/ui/
|
||||||
UI_HEADERS_DIR = sources/ui/
|
UI_HEADERS_DIR = sources/ui/
|
||||||
|
|||||||
67
sources/NameList/ui/namelistdialog.cpp
Normal file
67
sources/NameList/ui/namelistdialog.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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 "namelistdialog.h"
|
||||||
|
#include "ui_namelistdialog.h"
|
||||||
|
#include "namelistwidget.h"
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
NameListDialog::NameListDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::NameListDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
m_namelist_widget = new NameListWidget(this);
|
||||||
|
ui->m_main_layout->insertWidget(1, m_namelist_widget);
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
this->setWindowFlags(Qt::Sheet);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
NameListDialog::~NameListDialog() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameListDialog::setInformationText(const QString &text) {
|
||||||
|
ui->m_top_label->setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListDialog::namelistWidget
|
||||||
|
* @return the name list widget used by this dialog.
|
||||||
|
* The ownership of the namelistwidget stay to this dialog
|
||||||
|
*/
|
||||||
|
NameListWidget *NameListDialog::namelistWidget() const {
|
||||||
|
return m_namelist_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameListDialog::setHelpText(const QString &text)
|
||||||
|
{
|
||||||
|
m_help_text = text;
|
||||||
|
if (!m_help_text.isEmpty())
|
||||||
|
{
|
||||||
|
QPushButton *button = ui->m_button_box->addButton(QDialogButtonBox::Help);
|
||||||
|
connect(button, &QPushButton::clicked, this, &NameListDialog::showHelpDialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameListDialog::showHelpDialog() {
|
||||||
|
QMessageBox::information(this, tr("Variables de cartouche"), m_help_text);
|
||||||
|
}
|
||||||
52
sources/NameList/ui/namelistdialog.h
Normal file
52
sources/NameList/ui/namelistdialog.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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/>.
|
||||||
|
*/
|
||||||
|
#ifndef NAMELISTDIALOG_H
|
||||||
|
#define NAMELISTDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
class NameListWidget;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class NameListDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The NameListDialog class
|
||||||
|
* Provide a dialog for let user define localized string;
|
||||||
|
*/
|
||||||
|
class NameListDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NameListDialog(QWidget *parent = nullptr);
|
||||||
|
~NameListDialog();
|
||||||
|
|
||||||
|
void setInformationText(const QString &text);
|
||||||
|
NameListWidget *namelistWidget() const;
|
||||||
|
void setHelpText(const QString &text);
|
||||||
|
void showHelpDialog();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::NameListDialog *ui;
|
||||||
|
NameListWidget *m_namelist_widget = nullptr;
|
||||||
|
QString m_help_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAMELISTDIALOG_H
|
||||||
77
sources/NameList/ui/namelistdialog.ui
Normal file
77
sources/NameList/ui/namelistdialog.ui
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NameListDialog</class>
|
||||||
|
<widget class="QDialog" name="NameListDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>507</width>
|
||||||
|
<height>370</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="m_main_layout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="m_top_label">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="m_button_box">
|
||||||
|
<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>m_button_box</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>NameListDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>m_button_box</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>NameListDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
168
sources/NameList/ui/namelistwidget.cpp
Normal file
168
sources/NameList/ui/namelistwidget.cpp
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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 "namelistwidget.h"
|
||||||
|
#include "ui_namelistwidget.h"
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
|
NameListWidget::NameListWidget(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::NameListWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->m_clipboard_cb->setHidden(true);
|
||||||
|
connect(ui->m_add_line_pb, &QPushButton::clicked, this, &NameListWidget::addLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
NameListWidget::~NameListWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::addLine
|
||||||
|
* Add a new line to the name list widget
|
||||||
|
*/
|
||||||
|
void NameListWidget::addLine()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
if (m_read_only) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem();
|
||||||
|
qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
|
ui->m_tree->addTopLevelItem(qtwi);
|
||||||
|
ui->m_tree->setCurrentItem(qtwi);
|
||||||
|
ui->m_tree->editItem(qtwi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::setNames
|
||||||
|
* Set the current names of this dialog from @name_list
|
||||||
|
* @param name_list
|
||||||
|
*/
|
||||||
|
void NameListWidget::setNames(const NamesList &name_list)
|
||||||
|
{
|
||||||
|
for (QString lang : name_list.langs())
|
||||||
|
{
|
||||||
|
QString value = name_list[lang];
|
||||||
|
QStringList values;
|
||||||
|
values << lang << value;
|
||||||
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem(values);
|
||||||
|
if (!m_read_only) {
|
||||||
|
qtwi->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
|
}
|
||||||
|
ui->m_tree->addTopLevelItem(qtwi);
|
||||||
|
ui->m_tree->sortItems(0, Qt::AscendingOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::names
|
||||||
|
* @return the current name list edited by this dialog
|
||||||
|
*/
|
||||||
|
NamesList NameListWidget::names() const
|
||||||
|
{
|
||||||
|
NamesList nl_;
|
||||||
|
|
||||||
|
int names_count = ui->m_tree->topLevelItemCount();
|
||||||
|
for (int i = 0 ; i < names_count ; ++ i)
|
||||||
|
{
|
||||||
|
QString lang = ui->m_tree->topLevelItem(i)->text(0);
|
||||||
|
QString value = ui->m_tree->topLevelItem(i)->text(1);
|
||||||
|
if (lang != "" && value != "") {
|
||||||
|
nl_.addName(lang, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nl_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::setReadOnly
|
||||||
|
* Set this dialog to read only or not.
|
||||||
|
* @param ro
|
||||||
|
*/
|
||||||
|
void NameListWidget::setReadOnly(bool ro)
|
||||||
|
{
|
||||||
|
m_read_only = ro;
|
||||||
|
|
||||||
|
int names_count = ui->m_tree->topLevelItemCount() - 1;
|
||||||
|
for (int i = names_count ; i >= 0 ; -- i)
|
||||||
|
{
|
||||||
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
if (!m_read_only) {
|
||||||
|
flags |= Qt::ItemIsEditable;
|
||||||
|
}
|
||||||
|
ui->m_tree->topLevelItem(i)->setFlags(flags);
|
||||||
|
}
|
||||||
|
ui->m_add_line_pb->setEnabled(!ro);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::isEmpty
|
||||||
|
* @return true if empty.
|
||||||
|
* An empty dialog, is a dialog without any edited lang.
|
||||||
|
*/
|
||||||
|
bool NameListWidget::isEmpty() const {
|
||||||
|
return names().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameListWidget::setClipboardValue(QHash<QString, QString> value)
|
||||||
|
{
|
||||||
|
if (value.isEmpty()) {
|
||||||
|
ui->m_clipboard_cb->setHidden(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->m_clipboard_cb->setVisible(true);
|
||||||
|
|
||||||
|
QStringList list = value.keys();
|
||||||
|
list.sort();
|
||||||
|
for (QString key : list) {
|
||||||
|
ui->m_clipboard_cb->addItem(key, value.value(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief NameListWidget::clean
|
||||||
|
* Clean the lists of names by removing the emtpy lines
|
||||||
|
*/
|
||||||
|
void NameListWidget::clean()
|
||||||
|
{
|
||||||
|
int names_count = ui->m_tree->topLevelItemCount() - 1;
|
||||||
|
for (int i = names_count ; i >= 0 ; -- i)
|
||||||
|
{
|
||||||
|
if (ui->m_tree->topLevelItem(i)->text(0).isEmpty() &&
|
||||||
|
ui->m_tree->topLevelItem(i)->text(1).isEmpty())
|
||||||
|
{
|
||||||
|
ui->m_tree->takeTopLevelItem(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameListWidget::on_m_clipboard_cb_activated(int index)
|
||||||
|
{
|
||||||
|
Q_UNUSED(index);
|
||||||
|
|
||||||
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
clipboard->setText(ui->m_clipboard_cb->currentData().toString());
|
||||||
|
ui->m_clipboard_cb->setCurrentIndex(0);
|
||||||
|
}
|
||||||
58
sources/NameList/ui/namelistwidget.h
Normal file
58
sources/NameList/ui/namelistwidget.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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/>.
|
||||||
|
*/
|
||||||
|
#ifndef NAMELISTWIDGET_H
|
||||||
|
#define NAMELISTWIDGET_H
|
||||||
|
|
||||||
|
#include "nameslist.h"
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class NameListWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The NameListWidget class
|
||||||
|
* Provide a widget for let user define localized string;
|
||||||
|
*/
|
||||||
|
class NameListWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NameListWidget(QWidget *parent = nullptr);
|
||||||
|
~NameListWidget();
|
||||||
|
|
||||||
|
void addLine();
|
||||||
|
void setNames (const NamesList &name_list);
|
||||||
|
NamesList names() const;
|
||||||
|
void setReadOnly(bool ro);
|
||||||
|
bool isEmpty() const;
|
||||||
|
void setClipboardValue (QHash <QString, QString> value);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_m_clipboard_cb_activated(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::NameListWidget *ui;
|
||||||
|
bool m_read_only = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAMELISTWIDGET_H
|
||||||
65
sources/NameList/ui/namelistwidget.ui
Normal file
65
sources/NameList/ui/namelistwidget.ui
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NameListWidget</class>
|
||||||
|
<widget class="QWidget" name="NameListWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="m_tree">
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Langue</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Texte</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="m_add_line_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Ajouter une ligne</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="m_clipboard_cb">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Copier dans le presse papier</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/edit-paste.png</normaloff>:/ico/16x16/edit-paste.png</iconset>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2017 The QElectroTech Team
|
Copyright 2006-2018 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -28,12 +28,13 @@
|
|||||||
#include "partarc.h"
|
#include "partarc.h"
|
||||||
#include "editorcommands.h"
|
#include "editorcommands.h"
|
||||||
#include "elementcontent.h"
|
#include "elementcontent.h"
|
||||||
#include "nameslist.h"
|
|
||||||
#include "ui/elementpropertieseditorwidget.h"
|
#include "ui/elementpropertieseditorwidget.h"
|
||||||
#include "eseventinterface.h"
|
#include "eseventinterface.h"
|
||||||
#include "QetGraphicsItemModeler/qetgraphicshandleritem.h"
|
#include "QetGraphicsItemModeler/qetgraphicshandleritem.h"
|
||||||
#include "partdynamictextfield.h"
|
#include "partdynamictextfield.h"
|
||||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include "namelistdialog.h"
|
||||||
|
#include "namelistwidget.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@@ -725,44 +726,31 @@ void ElementScene::slot_editProperties()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Lance un dialogue pour editer les noms de cet element
|
* @brief ElementScene::slot_editNames
|
||||||
*/
|
* Launch a dialog for edit the names of the edited element
|
||||||
void ElementScene::slot_editNames() {
|
*/
|
||||||
|
void ElementScene::slot_editNames()
|
||||||
|
{
|
||||||
bool is_read_only = m_element_editor && m_element_editor -> isReadOnly();
|
bool is_read_only = m_element_editor && m_element_editor -> isReadOnly();
|
||||||
|
|
||||||
// cree un dialogue
|
NameListDialog dialog_(m_element_editor);
|
||||||
QDialog dialog(m_element_editor);
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
dialog.setWindowFlags(Qt::Sheet);
|
|
||||||
#endif
|
|
||||||
dialog.setModal(true);
|
|
||||||
dialog.setMinimumSize(400, 330);
|
|
||||||
dialog.setWindowTitle(tr("Éditer les noms", "window title"));
|
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog);
|
|
||||||
|
|
||||||
// ajoute un champ explicatif au dialogue
|
dialog_.setModal(true);
|
||||||
QLabel *information_label = new QLabel(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
|
dialog_.setMinimumSize(400, 330);
|
||||||
information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
dialog_.setWindowTitle(tr("Éditer les noms", "window title"));
|
||||||
information_label -> setWordWrap(true);
|
|
||||||
dialog_layout -> addWidget(information_label);
|
|
||||||
|
|
||||||
// ajoute un NamesListWidget au dialogue
|
dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
|
||||||
NamesListWidget *names_widget = new NamesListWidget();
|
|
||||||
names_widget -> setNames(m_names_list);
|
|
||||||
names_widget -> setReadOnly(is_read_only);
|
|
||||||
dialog_layout -> addWidget(names_widget);
|
|
||||||
|
|
||||||
// ajoute deux boutons au dialogue
|
NameListWidget *nlw_ = dialog_.namelistWidget();
|
||||||
QDialogButtonBox *dialog_buttons = new QDialogButtonBox(is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
nlw_->setNames(m_names_list);
|
||||||
dialog_layout -> addWidget(dialog_buttons);
|
nlw_->setReadOnly(is_read_only);
|
||||||
connect(dialog_buttons, SIGNAL(accepted()), names_widget, SLOT(check()));
|
|
||||||
connect(names_widget, SIGNAL(inputChecked()), &dialog, SLOT(accept()));
|
|
||||||
connect(dialog_buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
|
||||||
|
|
||||||
// lance le dialogue
|
if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty())
|
||||||
if (dialog.exec() == QDialog::Accepted && !is_read_only) {
|
{
|
||||||
NamesList new_names(names_widget -> names());
|
NamesList new_names = nlw_->names();
|
||||||
if (new_names != m_names_list) undoStack().push(new ChangeNamesCommand(this, m_names_list, new_names));
|
if (new_names != m_names_list) {
|
||||||
|
undoStack().push(new ChangeNamesCommand(this, m_names_list, new_names));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
#define ELEMENT_SCENE_H
|
#define ELEMENT_SCENE_H
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <QtXml>
|
#include <QtXml>
|
||||||
#include "nameslistwidget.h"
|
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include "elementcontent.h"
|
#include "elementcontent.h"
|
||||||
#include "diagramcontext.h"
|
#include "diagramcontext.h"
|
||||||
|
#include "nameslist.h"
|
||||||
|
|
||||||
class CustomElementPart;
|
class CustomElementPart;
|
||||||
class ElementEditionCommand;
|
class ElementEditionCommand;
|
||||||
|
|||||||
@@ -16,11 +16,16 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "elementscategoryeditor.h"
|
#include "elementscategoryeditor.h"
|
||||||
#include "nameslistwidget.h"
|
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
#include "qfilenameedit.h"
|
#include "qfilenameedit.h"
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
#include "elementcollectionhandler.h"
|
#include "elementcollectionhandler.h"
|
||||||
|
#include "namelistwidget.h"
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementsCategoryEditor::ElementsCategoryEditor
|
* @brief ElementsCategoryEditor::ElementsCategoryEditor
|
||||||
@@ -102,7 +107,7 @@ void ElementsCategoryEditor::setUpWidget()
|
|||||||
QVBoxLayout *editor_layout = new QVBoxLayout();
|
QVBoxLayout *editor_layout = new QVBoxLayout();
|
||||||
setLayout(editor_layout);
|
setLayout(editor_layout);
|
||||||
|
|
||||||
m_names_list = new NamesListWidget();
|
m_names_list = new NameListWidget(this);
|
||||||
m_file_name = new QLabel(tr("Nom interne : "));
|
m_file_name = new QLabel(tr("Nom interne : "));
|
||||||
m_file_line_edit = new QFileNameEdit();
|
m_file_line_edit = new QFileNameEdit();
|
||||||
|
|
||||||
@@ -130,7 +135,7 @@ void ElementsCategoryEditor::acceptCreation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//there must be at least one name
|
//there must be at least one name
|
||||||
if (!m_names_list -> checkOneName()) {
|
if (m_names_list->isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +186,7 @@ void ElementsCategoryEditor::acceptUpdate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//There must be at least one name
|
//There must be at least one name
|
||||||
if (!m_names_list -> checkOneName()) {
|
if (m_names_list->isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "elementslocation.h"
|
#include "elementslocation.h"
|
||||||
|
|
||||||
class NamesListWidget;
|
class NameListWidget;
|
||||||
class QFileNameEdit;
|
class QFileNameEdit;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
@@ -45,7 +45,7 @@ class ElementsCategoryEditor : public QDialog
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QDialogButtonBox *m_buttons;
|
QDialogButtonBox *m_buttons;
|
||||||
NamesListWidget *m_names_list;
|
NameListWidget *m_names_list;
|
||||||
QLabel *m_file_name;
|
QLabel *m_file_name;
|
||||||
QFileNameEdit *m_file_line_edit;
|
QFileNameEdit *m_file_line_edit;
|
||||||
bool m_edit_mode;
|
bool m_edit_mode;
|
||||||
|
|||||||
@@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2017 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 "nameslistwidget.h"
|
|
||||||
#include "qetmessagebox.h"
|
|
||||||
#include "qeticons.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param parent QWidget parent de la liste de noms
|
|
||||||
*/
|
|
||||||
NamesListWidget::NamesListWidget(QWidget *parent) : QWidget(parent), read_only(false) {
|
|
||||||
QVBoxLayout *names_list_layout = new QVBoxLayout();
|
|
||||||
setLayout(names_list_layout);
|
|
||||||
|
|
||||||
tree_names = new QTreeWidget();
|
|
||||||
tree_names -> setRootIsDecorated(false);
|
|
||||||
tree_names -> setColumnCount(2);
|
|
||||||
QStringList headers;
|
|
||||||
headers << tr("Langue") << tr("Texte");
|
|
||||||
tree_names -> setHeaderLabels(headers);
|
|
||||||
tree_names -> setWhatsThis(
|
|
||||||
tr(
|
|
||||||
"Cette liste vous permet de saisir un court texte de façon à ce"
|
|
||||||
" qu'il soit traduisible dans d'autres langues. Pour ce faire, elle"
|
|
||||||
" associe des codes ISO 639-1 de langues (ex. : \"fr\" pour"
|
|
||||||
" français) aux traductions du texte en question dans ces"
|
|
||||||
" mêmes langues.",
|
|
||||||
"\"What's this\" tip"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
button_add_line = new QPushButton(QET::Icons::Add, tr("Ajouter une ligne"));
|
|
||||||
button_add_line -> setWhatsThis(
|
|
||||||
tr(
|
|
||||||
"Ce bouton permet d'ajouter une association langue / traduction "
|
|
||||||
"dans la liste ci-dessus.",
|
|
||||||
"\"What's this\" tip"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
connect(button_add_line, SIGNAL(released()), this, SLOT(addLine()));
|
|
||||||
|
|
||||||
names_list_layout -> addWidget(tree_names);
|
|
||||||
names_list_layout -> addWidget(button_add_line);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Destructeur
|
|
||||||
*/
|
|
||||||
NamesListWidget::~NamesListWidget() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ajoute une ligne a l'editeur
|
|
||||||
*/
|
|
||||||
void NamesListWidget::addLine() {
|
|
||||||
clean();
|
|
||||||
if (read_only) return;
|
|
||||||
QTreeWidgetItem *qtwi = new QTreeWidgetItem();
|
|
||||||
qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
||||||
tree_names -> addTopLevelItem(qtwi);
|
|
||||||
tree_names -> setCurrentItem(qtwi);
|
|
||||||
tree_names -> editItem(qtwi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Verifie qu'il y a au moins un nom
|
|
||||||
*/
|
|
||||||
bool NamesListWidget::checkOneName() {
|
|
||||||
updateHash();
|
|
||||||
if (!hash_names.count()) {
|
|
||||||
QET::QetMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("Il doit y avoir au moins un nom.", "message box title"),
|
|
||||||
tr("Vous devez entrer au moins un nom.", "message box content")
|
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Lit les noms valides dans hash_names
|
|
||||||
*/
|
|
||||||
void NamesListWidget::updateHash() {
|
|
||||||
hash_names.clearNames();
|
|
||||||
int names_count = tree_names -> topLevelItemCount();
|
|
||||||
for (int i = 0 ; i < names_count ; ++ i) {
|
|
||||||
QString lang = tree_names -> topLevelItem(i) -> text(0);
|
|
||||||
QString value = tree_names -> topLevelItem(i) -> text(1);
|
|
||||||
if (lang != "" && value != "") hash_names.addName(lang, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Nettoie la liste des noms en enlevant les lignes vides
|
|
||||||
*/
|
|
||||||
void NamesListWidget::clean() {
|
|
||||||
int names_count = tree_names -> topLevelItemCount() - 1;
|
|
||||||
for (int i = names_count ; i >= 0 ; -- i) {
|
|
||||||
if (
|
|
||||||
tree_names -> topLevelItem(i) -> text(0).isEmpty() &&\
|
|
||||||
tree_names -> topLevelItem(i) -> text(1).isEmpty()
|
|
||||||
) {
|
|
||||||
tree_names -> takeTopLevelItem(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return Les noms entres dans la Names List
|
|
||||||
*/
|
|
||||||
NamesList NamesListWidget::names() {
|
|
||||||
updateHash();
|
|
||||||
return(hash_names);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Definit les noms que le widget doit afficher
|
|
||||||
*/
|
|
||||||
void NamesListWidget::setNames(const NamesList &provided_names) {
|
|
||||||
foreach(QString lang, provided_names.langs()) {
|
|
||||||
QString value = provided_names[lang];
|
|
||||||
QStringList values;
|
|
||||||
values << lang << value;
|
|
||||||
QTreeWidgetItem *qtwi = new QTreeWidgetItem(values);
|
|
||||||
if (!read_only) qtwi -> setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
||||||
tree_names -> addTopLevelItem(qtwi);
|
|
||||||
tree_names -> sortItems(0, Qt::AscendingOrder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Verifie qu'il y a au moins un nom de saisi - si c'est le cas, le signal
|
|
||||||
imputChecked() est emis.
|
|
||||||
*/
|
|
||||||
void NamesListWidget::check() {
|
|
||||||
if (checkOneName()) emit(inputChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Definit le mode d'edition du widget
|
|
||||||
@param ro true pour que la liste de noms soit en lecture seule, false sinon
|
|
||||||
*/
|
|
||||||
void NamesListWidget::setReadOnly(bool ro) {
|
|
||||||
read_only = ro;
|
|
||||||
int names_count = tree_names -> topLevelItemCount() - 1;
|
|
||||||
for (int i = names_count ; i >= 0 ; -- i) {
|
|
||||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
||||||
if (!read_only) flags |= Qt::ItemIsEditable;
|
|
||||||
tree_names -> topLevelItem(i) -> setFlags(flags);
|
|
||||||
}
|
|
||||||
button_add_line -> setEnabled(!read_only);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @return true si la liste de noms est en lecture seule, false sinon
|
|
||||||
bool NamesListWidget::isReadOnly() const {
|
|
||||||
return(read_only);
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2017 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/>.
|
|
||||||
*/
|
|
||||||
#ifndef NAMES_LIST_WIDGET_H
|
|
||||||
#define NAMES_LIST_WIDGET_H
|
|
||||||
#include <QtWidgets>
|
|
||||||
#include "nameslist.h"
|
|
||||||
/**
|
|
||||||
This class provides a widget enabling users to enter localized names for
|
|
||||||
categories and elements.
|
|
||||||
*/
|
|
||||||
class NamesListWidget : public QWidget {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// constructors, destructor
|
|
||||||
public:
|
|
||||||
NamesListWidget(QWidget * = nullptr);
|
|
||||||
~NamesListWidget() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
NamesListWidget(const NamesListWidget &);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
private:
|
|
||||||
QTreeWidget *tree_names;
|
|
||||||
QPushButton *button_add_line;
|
|
||||||
NamesList hash_names;
|
|
||||||
bool read_only;
|
|
||||||
|
|
||||||
// methods
|
|
||||||
public:
|
|
||||||
bool checkOneName();
|
|
||||||
NamesList names();
|
|
||||||
void setNames(const NamesList &);
|
|
||||||
void setReadOnly(bool);
|
|
||||||
bool isReadOnly() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void clean();
|
|
||||||
void updateHash();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void addLine();
|
|
||||||
void check();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
/**
|
|
||||||
Signal emitted after the widget successfully checked there was at least one
|
|
||||||
name entered
|
|
||||||
*/
|
|
||||||
void inputChecked();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
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 "nameslistwidget.h"
|
#include "namelistwidget.h"
|
||||||
#include "qetelementeditor.h"
|
#include "qetelementeditor.h"
|
||||||
#include "qfilenameedit.h"
|
#include "qfilenameedit.h"
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
@@ -130,7 +130,7 @@ 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();
|
||||||
|
|
||||||
m_names_list = new NamesListWidget();
|
m_names_list = new NameListWidget(this);
|
||||||
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"));
|
||||||
m_names_list -> setNames(hash_name);
|
m_names_list -> setNames(hash_name);
|
||||||
@@ -144,14 +144,22 @@ QWizardPage *NewElementWizard::buildStep3() {
|
|||||||
* @brief NewElementWizard::validateCurrentPage
|
* @brief NewElementWizard::validateCurrentPage
|
||||||
* @return true if the current step is valid
|
* @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());
|
|
||||||
else if (wizard_state == Filename) return(validStep2());
|
if (wizard_state == Category) {
|
||||||
else if (wizard_state == Names) {
|
return(validStep1());
|
||||||
|
}
|
||||||
|
else if (wizard_state == Filename) {
|
||||||
|
return(validStep2());
|
||||||
|
}
|
||||||
|
else if (wizard_state == Names)
|
||||||
|
{
|
||||||
// must have one name minimum
|
// must have one name minimum
|
||||||
if (m_names_list -> checkOneName())
|
if (!m_names_list->isEmpty()) {
|
||||||
createNewElement();
|
createNewElement();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return(true);
|
else return(true);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <QWizard>
|
#include <QWizard>
|
||||||
#include "elementslocation.h"
|
#include "elementslocation.h"
|
||||||
|
|
||||||
class NamesListWidget;
|
class NameListWidget;
|
||||||
class QFileNameEdit;
|
class QFileNameEdit;
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
class ElementsCollectionModel;
|
class ElementsCollectionModel;
|
||||||
@@ -53,7 +53,7 @@ class NewElementWizard : public QWizard
|
|||||||
private:
|
private:
|
||||||
enum WizardState { Category, Filename, Names };
|
enum WizardState { Category, Filename, Names };
|
||||||
QFileNameEdit *m_qle_filename;
|
QFileNameEdit *m_qle_filename;
|
||||||
NamesListWidget *m_names_list;
|
NameListWidget *m_names_list;
|
||||||
QString m_chosen_file;
|
QString m_chosen_file;
|
||||||
QTreeView *m_tree_view = nullptr;
|
QTreeView *m_tree_view = nullptr;
|
||||||
ElementsLocation m_chosen_location;
|
ElementsLocation m_chosen_location;
|
||||||
|
|||||||
128
sources/qetinformation.cpp
Normal file
128
sources/qetinformation.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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 "qetinformation.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QETInformation::titleblockInfoKeys
|
||||||
|
* @return all available key for use with a titleblock
|
||||||
|
*/
|
||||||
|
QStringList QETInformation::titleblockInfoKeys()
|
||||||
|
{
|
||||||
|
QStringList info_list;
|
||||||
|
info_list << "author";
|
||||||
|
info_list << "date";
|
||||||
|
info_list << "title";
|
||||||
|
info_list << "filename";
|
||||||
|
info_list << "plant";
|
||||||
|
info_list << "locmach";
|
||||||
|
info_list << "indexrev";
|
||||||
|
info_list << "version";
|
||||||
|
info_list << "folio";
|
||||||
|
info_list << "folio-id";
|
||||||
|
info_list << "folio-total";
|
||||||
|
info_list << "previous-folio-num";
|
||||||
|
info_list << "next-folio-num";
|
||||||
|
info_list << "projecttitle";
|
||||||
|
info_list << "projectpath";
|
||||||
|
info_list << "projectfilename";
|
||||||
|
info_list << "saveddate";
|
||||||
|
info_list << "savedtime";
|
||||||
|
info_list << "savedfilename";
|
||||||
|
info_list << "savedfilepath";
|
||||||
|
|
||||||
|
return info_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QETInformation::titleblockTranslatedInfoKey
|
||||||
|
* @param info : info key to be translated
|
||||||
|
* @return the translated information given by @info
|
||||||
|
* If @info don't match, return an empty string
|
||||||
|
*/
|
||||||
|
QString QETInformation::titleblockTranslatedInfoKey(const QString &info)
|
||||||
|
{
|
||||||
|
if (info == "author") return QObject::tr("Auteur");
|
||||||
|
else if (info == "date") return QObject::tr("Date");
|
||||||
|
else if (info == "title") return QObject::tr("Titre");
|
||||||
|
else if (info == "filename") return QObject::tr("Fichier");
|
||||||
|
else if (info == "plant") return QObject::tr("Installation (=)");
|
||||||
|
else if (info == "locmach") return QObject::tr("Localisation (+)");
|
||||||
|
else if (info == "indexrev") return QObject::tr("Indice de révision");
|
||||||
|
else if (info == "version") return QObject::tr("Version de QElectroTech");
|
||||||
|
else if (info == "folio") return QObject::tr("Numéro de folio");
|
||||||
|
else if (info == "folio-id") return QObject::tr("Position du folio");
|
||||||
|
else if (info == "folio-total") return QObject::tr("Nombre de folio");
|
||||||
|
else if (info == "previous-folio-num") return QObject::tr("Numéro du folio précédent");
|
||||||
|
else if (info == "next-folio-num") return QObject::tr("Numéro du folio suivant");
|
||||||
|
else if (info == "projecttitle") return QObject::tr("Titre du projet");
|
||||||
|
else if (info == "projectpath") return QObject::tr("Chemin du fichier du projet");
|
||||||
|
else if (info == "projectfilename") return QObject::tr("Nom du fichier");
|
||||||
|
else if (info == "saveddate") return QObject::tr("Date d'enregistrement du fichier");
|
||||||
|
else if (info == "savedtime") return QObject::tr("Heure d'enregistrement du fichier");
|
||||||
|
else if (info == "savedfilename") return QObject::tr("Nom du fichier enregistré");
|
||||||
|
else if (info == "savedfilepath") return QObject::tr("Chemin du fichier enregistré");
|
||||||
|
else return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QETInformation::titleblockInfoKeysToVar
|
||||||
|
* @param info
|
||||||
|
* @return var in form %{my-var} corresponding to the info.
|
||||||
|
* if there is not available var for the given info, the returned var is %{void}
|
||||||
|
*/
|
||||||
|
QString QETInformation::titleblockInfoKeysToVar(const QString &info)
|
||||||
|
{
|
||||||
|
if (info == "author") return QString("%{author}");
|
||||||
|
else if (info == "date") return QString("%{date}");
|
||||||
|
else if (info == "title") return QString("%{title}");
|
||||||
|
else if (info == "filename") return QString("%{filename}");
|
||||||
|
else if (info == "plant") return QString("%{plant}");
|
||||||
|
else if (info == "locmach") return QString("%{locmach}");
|
||||||
|
else if (info == "indexrev") return QString("%{indexrev}");
|
||||||
|
else if (info == "version") return QString("%{version}");
|
||||||
|
else if (info == "folio") return QString("%{folio}");
|
||||||
|
else if (info == "folio-id") return QString("%{folio-id}");
|
||||||
|
else if (info == "folio-total") return QString("%{folio-total}");
|
||||||
|
else if (info == "previous-folio-num") return QString("%{previous-folio-num}");
|
||||||
|
else if (info == "next-folio-num") return QString("%{next-folio-num}");
|
||||||
|
else if (info == "projecttitle") return QString("%{projecttitle}");
|
||||||
|
else if (info == "projectpath") return QString("%{projectpath}");
|
||||||
|
else if (info == "projectfilename") return QString("%{projectfilename}");
|
||||||
|
else if (info == "saveddate") return QString("%{saveddate}");
|
||||||
|
else if (info == "savedtime") return QString("%{savedtime}");
|
||||||
|
else if (info == "savedfilename") return QString("%{savedfilename}");
|
||||||
|
else if (info == "savedfilepath") return QString("%{savedfilepath}");
|
||||||
|
else return QString("%{void");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QETInformation::titleblockTranslatedKeyHashVar
|
||||||
|
* @return a QHash with for key, the translated information key of title block,
|
||||||
|
* and for value the corresponding var.
|
||||||
|
*/
|
||||||
|
QHash<QString, QString> QETInformation::titleblockTranslatedKeyHashVar()
|
||||||
|
{
|
||||||
|
QHash <QString, QString> hash_;
|
||||||
|
for (QString str : titleblockInfoKeys()) {
|
||||||
|
hash_.insert(titleblockTranslatedInfoKey(str), titleblockInfoKeysToVar(str));
|
||||||
|
}
|
||||||
|
return hash_;
|
||||||
|
}
|
||||||
31
sources/qetinformation.h
Normal file
31
sources/qetinformation.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2018 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/>.
|
||||||
|
*/
|
||||||
|
#ifndef QETINFORMATION_H
|
||||||
|
#define QETINFORMATION_H
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace QETInformation
|
||||||
|
{
|
||||||
|
QStringList titleblockInfoKeys();
|
||||||
|
QString titleblockTranslatedInfoKey(const QString &info);
|
||||||
|
QString titleblockInfoKeysToVar(const QString &info);
|
||||||
|
QHash <QString, QString> titleblockTranslatedKeyHashVar();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // QETINFORMATION_H
|
||||||
@@ -18,10 +18,12 @@
|
|||||||
#include "templatecellwidget.h"
|
#include "templatecellwidget.h"
|
||||||
#include "titleblockcell.h"
|
#include "titleblockcell.h"
|
||||||
#include "nameslist.h"
|
#include "nameslist.h"
|
||||||
#include "nameslistwidget.h"
|
|
||||||
#include "titleblocktemplate.h"
|
#include "titleblocktemplate.h"
|
||||||
#include "templatecommands.h"
|
#include "templatecommands.h"
|
||||||
#include "qeticons.h"
|
#include "qeticons.h"
|
||||||
|
#include "namelistdialog.h"
|
||||||
|
#include "namelistwidget.h"
|
||||||
|
#include "qetinformation.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructor
|
Constructor
|
||||||
@@ -374,33 +376,20 @@ bool TitleBlockTemplateCellWidget::isReadOnly() const {
|
|||||||
@param attribute Name of the edited cell attribute
|
@param attribute Name of the edited cell attribute
|
||||||
@param title Title of the dialog window
|
@param title Title of the dialog window
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplateCellWidget::editTranslatableValue(NamesList &names, const QString &attribute, const QString &title) const {
|
void TitleBlockTemplateCellWidget::editTranslatableValue(NamesList &names, const QString &attribute, const QString &title) const
|
||||||
NamesListWidget *names_widget = new NamesListWidget();
|
{
|
||||||
names_widget -> setNames(names);
|
NameListDialog dialog_;
|
||||||
QDialogButtonBox * buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
||||||
|
|
||||||
QLabel *information = new QLabel(labelValueInformationString());
|
dialog_.setWindowTitle(title);
|
||||||
information -> setTextFormat(Qt::RichText);
|
dialog_.setInformationText(labelValueInformationString());
|
||||||
information -> setWordWrap(true);
|
dialog_.setHelpText(defaultVariablesString());
|
||||||
|
|
||||||
QLabel *def_var_label = new QLabel(defaultVariablesString());
|
NameListWidget *nlw_ = dialog_.namelistWidget();
|
||||||
def_var_label -> setTextFormat(Qt::RichText);
|
nlw_->setNames(names);
|
||||||
def_var_label -> setTextInteractionFlags(Qt::TextSelectableByMouse);
|
nlw_->setClipboardValue(QETInformation::titleblockTranslatedKeyHashVar());
|
||||||
|
|
||||||
QVBoxLayout *editor_layout = new QVBoxLayout();
|
|
||||||
editor_layout -> addWidget(information);
|
|
||||||
editor_layout -> addWidget(names_widget);
|
|
||||||
editor_layout -> addWidget(def_var_label);
|
|
||||||
editor_layout -> addWidget(buttons);
|
|
||||||
|
|
||||||
QDialog edit_dialog;
|
|
||||||
edit_dialog.setWindowTitle(title);
|
|
||||||
connect(buttons, SIGNAL(rejected()), &edit_dialog, SLOT(reject()));
|
|
||||||
connect(buttons, SIGNAL(accepted()), &edit_dialog, SLOT(accept()));
|
|
||||||
edit_dialog.setLayout(editor_layout);
|
|
||||||
if (edit_dialog.exec() == QDialog::Accepted) {
|
|
||||||
emitModification(attribute, qVariantFromValue(names_widget -> names()));
|
|
||||||
|
|
||||||
|
if(dialog_.exec() == QDialog::Accepted) {
|
||||||
|
emitModification(attribute, qVariantFromValue(nlw_->names()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user