mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Continue new summary feature
Header name is now well translated. Open the good dialog from the properties dock widget
This commit is contained in:
@@ -118,7 +118,7 @@ void ElementQueryWidget::setQuery(const QString &query)
|
|||||||
QString select = query;
|
QString select = query;
|
||||||
select.remove(0,7); //Remove SELECT
|
select.remove(0,7); //Remove SELECT
|
||||||
select.truncate(select.indexOf("FROM")); //Truncate at FROM
|
select.truncate(select.indexOf("FROM")); //Truncate at FROM
|
||||||
select.replace(" ", ""); //Remove withe space
|
select.replace(" ", ""); //Remove white space
|
||||||
|
|
||||||
//Get the select -> the item in the right list
|
//Get the select -> the item in the right list
|
||||||
QStringList split = select.split(",");
|
QStringList split = select.split(",");
|
||||||
@@ -367,25 +367,6 @@ QString ElementQueryWidget::queryStr() const
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ElementQueryWidget::header
|
|
||||||
* @return the name of each selected item is a QStringList.
|
|
||||||
* You can use the QStringList as header string of a table filled by the returned value of the query ElementQueryWidget::queryStr() to project database.
|
|
||||||
*/
|
|
||||||
QStringList ElementQueryWidget::header() const
|
|
||||||
{
|
|
||||||
//Made a string list with the colomns (keys) choosen by the user
|
|
||||||
QStringList headers;
|
|
||||||
int row = 0;
|
|
||||||
while (auto *item = ui->m_choosen_list->item(row))
|
|
||||||
{
|
|
||||||
headers.append(item->data(Qt::DisplayRole).toString());
|
|
||||||
++row;
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementQueryWidget::updateQueryLine
|
* @brief ElementQueryWidget::updateQueryLine
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class ElementQueryWidget : public QWidget
|
|||||||
|
|
||||||
void setQuery(const QString &query);
|
void setQuery(const QString &query);
|
||||||
QString queryStr() const;
|
QString queryStr() const;
|
||||||
QStringList header() const;
|
|
||||||
|
|
||||||
static QString modelIdentifier() {return "nomenclature";}
|
static QString modelIdentifier() {return "nomenclature";}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ SummaryQueryWidget::~SummaryQueryWidget()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SummaryQueryWidget::queryStr
|
* @brief SummaryQueryWidget::queryStr
|
||||||
* @return
|
* @return The current query string
|
||||||
*/
|
*/
|
||||||
QString SummaryQueryWidget::queryStr() const
|
QString SummaryQueryWidget::queryStr() const
|
||||||
{
|
{
|
||||||
@@ -78,6 +78,40 @@ QString SummaryQueryWidget::queryStr() const
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SummaryQueryWidget::setQuery
|
||||||
|
* @param query
|
||||||
|
* set the current query to @query.
|
||||||
|
* If it's possible, rebuild the state of the widget from the query
|
||||||
|
*/
|
||||||
|
void SummaryQueryWidget::setQuery(const QString &query)
|
||||||
|
{
|
||||||
|
if (query.startsWith("SELECT"))
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
ui->m_user_query_le->setText(query);
|
||||||
|
|
||||||
|
QString select = query;
|
||||||
|
select.remove(0,7); //remove SELECT
|
||||||
|
select.truncate(select.indexOf("FROM")); //Truncate at FROM
|
||||||
|
select.replace(" ",""); //Remove white
|
||||||
|
|
||||||
|
//Get the select -> the item in the right list
|
||||||
|
QStringList split = select.split(",");
|
||||||
|
for (auto str : split)
|
||||||
|
{
|
||||||
|
for (auto item : m_items_list)
|
||||||
|
{
|
||||||
|
if (item->data(Qt::UserRole).toString() == str) {
|
||||||
|
ui->m_available_list->takeItem(ui->m_available_list->row(item));
|
||||||
|
ui->m_choosen_list->addItem(item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SummaryQueryWidget::setUpItems
|
* @brief SummaryQueryWidget::setUpItems
|
||||||
*/
|
*/
|
||||||
@@ -97,6 +131,9 @@ void SummaryQueryWidget::setUpItems()
|
|||||||
m_items_list << item;
|
m_items_list << item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SummaryQueryWidget::fillSavedQuery
|
||||||
|
*/
|
||||||
void SummaryQueryWidget::fillSavedQuery()
|
void SummaryQueryWidget::fillSavedQuery()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -126,6 +163,11 @@ QStringList SummaryQueryWidget::selectedKeys() const
|
|||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SummaryQueryWidget::on_m_available_list_itemDoubleClicked
|
||||||
|
* @param item
|
||||||
|
*/
|
||||||
void SummaryQueryWidget::on_m_available_list_itemDoubleClicked(QListWidgetItem *item)
|
void SummaryQueryWidget::on_m_available_list_itemDoubleClicked(QListWidgetItem *item)
|
||||||
{
|
{
|
||||||
Q_UNUSED(item)
|
Q_UNUSED(item)
|
||||||
@@ -200,6 +242,9 @@ void SummaryQueryWidget::on_m_down_pb_clicked()
|
|||||||
updateQueryLine();
|
updateQueryLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SummaryQueryWidget::on_m_edit_sql_query_cb_clicked
|
||||||
|
*/
|
||||||
void SummaryQueryWidget::on_m_edit_sql_query_cb_clicked()
|
void SummaryQueryWidget::on_m_edit_sql_query_cb_clicked()
|
||||||
{
|
{
|
||||||
ui->m_user_query_le->setEnabled(ui->m_edit_sql_query_cb->isChecked());
|
ui->m_user_query_le->setEnabled(ui->m_edit_sql_query_cb->isChecked());
|
||||||
@@ -215,3 +260,16 @@ void SummaryQueryWidget::on_m_edit_sql_query_cb_clicked()
|
|||||||
updateQueryLine();
|
updateQueryLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SummaryQueryWidget::reset
|
||||||
|
* Clear this widget aka set to initial state
|
||||||
|
*/
|
||||||
|
void SummaryQueryWidget::reset()
|
||||||
|
{
|
||||||
|
//Ugly hack to force to remove all selected infos
|
||||||
|
while (auto item = ui->m_choosen_list->takeItem(0)) {
|
||||||
|
ui->m_available_list->addItem(item);
|
||||||
|
}
|
||||||
|
ui->m_user_query_le->clear();
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class SummaryQueryWidget : public QWidget
|
|||||||
|
|
||||||
static QString modelIdentifier() {return "summary";}
|
static QString modelIdentifier() {return "summary";}
|
||||||
QString queryStr() const;
|
QString queryStr() const;
|
||||||
|
void setQuery(const QString &query);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setUpItems();
|
void setUpItems();
|
||||||
@@ -51,6 +52,7 @@ class SummaryQueryWidget : public QWidget
|
|||||||
void on_m_remove_pb_clicked();
|
void on_m_remove_pb_clicked();
|
||||||
void on_m_down_pb_clicked();
|
void on_m_down_pb_clicked();
|
||||||
void on_m_edit_sql_query_cb_clicked();
|
void on_m_edit_sql_query_cb_clicked();
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SummaryQueryWidget *ui;
|
Ui::SummaryQueryWidget *ui;
|
||||||
|
|||||||
@@ -340,11 +340,8 @@ QString QETApp::elementTranslatedInfoKey(const QString &info)
|
|||||||
else if (info == "supplier") return tr("Fournisseur");
|
else if (info == "supplier") return tr("Fournisseur");
|
||||||
else if (info == "quantity") return tr("Quantité");
|
else if (info == "quantity") return tr("Quantité");
|
||||||
else if (info == "unity") return tr("Unité");
|
else if (info == "unity") return tr("Unité");
|
||||||
|
|
||||||
|
else return QString();
|
||||||
|
|
||||||
|
|
||||||
return (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -440,8 +437,9 @@ QString QETApp::diagramTranslatedInfoKey(const QString &key)
|
|||||||
else if (key == "folio") return tr("Folio");
|
else if (key == "folio") return tr("Folio");
|
||||||
else if (key == "plant") return tr("Installation");
|
else if (key == "plant") return tr("Installation");
|
||||||
else if (key == "locmach") return tr("Localisation");
|
else if (key == "locmach") return tr("Localisation");
|
||||||
else if (key == "indexrev") return tr("Indice Rev");
|
else if (key == "indexrev") return tr("Indice de révision");
|
||||||
else if (key == "date") return tr("Date");
|
else if (key == "date") return tr("Date");
|
||||||
|
else if (key == "pos") return tr("Position");
|
||||||
else return QString();
|
else return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ bool ProjectDBModel::setHeaderData(int section, Qt::Orientation orientation, con
|
|||||||
auto hash_ = m_header_data.value(section);
|
auto hash_ = m_header_data.value(section);
|
||||||
hash_.insert(role, value);
|
hash_.insert(role, value);
|
||||||
m_header_data.insert(section, hash_);
|
m_header_data.insert(section, hash_);
|
||||||
headerDataChanged(orientation, section, section);
|
emit headerDataChanged(orientation, section, section);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,29 +329,29 @@ void ProjectDBModel::dataBaseUpdated()
|
|||||||
|
|
||||||
void ProjectDBModel::setHeaderString()
|
void ProjectDBModel::setHeaderString()
|
||||||
{
|
{
|
||||||
auto q = m_project->dataBase()->newQuery(m_query);
|
auto q = m_project->dataBase()->newQuery(m_query);
|
||||||
auto record = q.record();
|
auto record = q.record();
|
||||||
|
|
||||||
for (auto i=0 ; i<record.count() ; ++i)
|
for (auto i=0 ; i<record.count() ; ++i)
|
||||||
{
|
{
|
||||||
auto field_name = record.fieldName(i);
|
auto field_name = record.fieldName(i);
|
||||||
QString header_name;
|
QString header_name;
|
||||||
|
|
||||||
if (field_name == "position") {
|
if (field_name == "position") {
|
||||||
header_name = tr("Position");
|
header_name = tr("Position");
|
||||||
} else if (field_name == "diagram_position") {
|
} else if (field_name == "diagram_position") {
|
||||||
header_name = tr("Position du folio");
|
header_name = tr("Position du folio");
|
||||||
} else {
|
} else {
|
||||||
header_name = QETApp::elementTranslatedInfoKey(field_name);
|
header_name = QETApp::elementTranslatedInfoKey(field_name);
|
||||||
if (header_name.isEmpty()) {
|
if (header_name.isEmpty()) {
|
||||||
header_name = QETApp::diagramTranslatedInfoKey(field_name);
|
header_name = QETApp::diagramTranslatedInfoKey(field_name);
|
||||||
}
|
}
|
||||||
if (header_name.isEmpty()) {
|
if (header_name.isEmpty()) {
|
||||||
header_name = field_name;
|
header_name = field_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->setHeaderData(i, Qt::Horizontal, header_name);
|
this->setHeaderData(i, Qt::Horizontal, header_name, Qt::DisplayRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectDBModel::fillValue()
|
void ProjectDBModel::fillValue()
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ class QETProject;
|
|||||||
* This class should be sufficient to display the content of the project data base from a query set by the method void ProjectDBModel::setQuery(const QString &query).
|
* This class should be sufficient to display the content of the project data base from a query set by the method void ProjectDBModel::setQuery(const QString &query).
|
||||||
* The indentifier method is used by widget editor to retrieve the good widget for edit the query. By defaut identifer return the string 'unknow'.
|
* The indentifier method is used by widget editor to retrieve the good widget for edit the query. By defaut identifer return the string 'unknow'.
|
||||||
* You should use setIdentfier method to set your custom identifier.
|
* You should use setIdentfier method to set your custom identifier.
|
||||||
|
* At the time this sentence is written, there is two identifier :
|
||||||
|
* nomenclature
|
||||||
|
* summary
|
||||||
*/
|
*/
|
||||||
class ProjectDBModel : public QAbstractTableModel
|
class ProjectDBModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
@@ -53,7 +56,7 @@ class ProjectDBModel : public QAbstractTableModel
|
|||||||
QDomElement toXml(QDomDocument &document) const;
|
QDomElement toXml(QDomDocument &document) const;
|
||||||
void fromXml(const QDomElement &element);
|
void fromXml(const QDomElement &element);
|
||||||
void setIdentifier(const QString &identifier);
|
void setIdentifier(const QString &identifier);
|
||||||
QString indentifier() const {return m_identifier;}
|
QString identifier() const {return m_identifier;}
|
||||||
static QString xmlTagName() {return QString("project_data_base_model");}
|
static QString xmlTagName() {return QString("project_data_base_model");}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
|||||||
QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(), m_section_height - margins_.top() - margins_.bottom());
|
QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(), m_section_height - margins_.top() - margins_.bottom());
|
||||||
painter->drawText(QRectF(top_left, size),
|
painter->drawText(QRectF(top_left, size),
|
||||||
m_model->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt(),
|
m_model->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt(),
|
||||||
m_model->headerData(i, Qt::Horizontal).toString());
|
m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||||
|
|
||||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,12 +56,10 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
|
|||||||
void on_m_previous_table_cb_activated(int index);
|
void on_m_previous_table_cb_activated(int index);
|
||||||
void on_m_previous_pb_clicked();
|
void on_m_previous_pb_clicked();
|
||||||
void on_m_next_pb_clicked();
|
void on_m_next_pb_clicked();
|
||||||
|
|
||||||
void on_m_auto_geometry_pb_clicked();
|
void on_m_auto_geometry_pb_clicked();
|
||||||
|
|
||||||
void on_m_apply_geometry_to_linked_table_pb_clicked();
|
void on_m_apply_geometry_to_linked_table_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setUpEditConnection();
|
void setUpEditConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "projectdbmodel.h"
|
#include "projectdbmodel.h"
|
||||||
#include "qetproject.h"
|
#include "qetproject.h"
|
||||||
#include "elementquerywidget.h"
|
#include "elementquerywidget.h"
|
||||||
|
#include "summaryquerywidget.h"
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
@@ -62,9 +63,20 @@ void ProjectDBModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
|||||||
auto l = new QVBoxLayout;
|
auto l = new QVBoxLayout;
|
||||||
d.setLayout(l);
|
d.setLayout(l);
|
||||||
|
|
||||||
auto query_widget = new ElementQueryWidget(&d);
|
ElementQueryWidget *nom_w = nullptr;
|
||||||
query_widget->setQuery(m_model->queryString());
|
SummaryQueryWidget *sum_w = nullptr;
|
||||||
l->addWidget(query_widget);
|
if (m_model->identifier() == "nomenclature")
|
||||||
|
{
|
||||||
|
nom_w = new ElementQueryWidget(&d);
|
||||||
|
nom_w->setQuery(m_model->queryString());
|
||||||
|
l->addWidget(nom_w);
|
||||||
|
}
|
||||||
|
else if (m_model->identifier() == "summary")
|
||||||
|
{
|
||||||
|
sum_w = new SummaryQueryWidget(&d);
|
||||||
|
sum_w->setQuery(m_model->queryString());
|
||||||
|
l->addWidget(sum_w);
|
||||||
|
}
|
||||||
|
|
||||||
auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
l->addWidget(button_box);
|
l->addWidget(button_box);
|
||||||
@@ -73,10 +85,10 @@ void ProjectDBModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
|||||||
|
|
||||||
if (d.exec())
|
if (d.exec())
|
||||||
{
|
{
|
||||||
m_model->setQuery(query_widget->queryStr());
|
if (nom_w) {
|
||||||
auto headers = query_widget->header();
|
m_model->setQuery(nom_w->queryStr());
|
||||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
} else if (sum_w) {
|
||||||
m_model->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
m_model->setQuery(sum_w->queryStr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user