mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-29 06:19:57 +01:00
Query can be edited. Project database can be exported
User can now define the information to display in the nomenclature table. WIP The internal database of project can be exported to file.
This commit is contained in:
@@ -102,11 +102,15 @@ QVariant NomenclatureModel::headerData(int section, Qt::Orientation orientation,
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto hash_ = m_header_data.value(section);
|
||||
if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt
|
||||
return hash_.value(Qt::EditRole);
|
||||
if (m_header_data.contains(section))
|
||||
{
|
||||
auto hash_ = m_header_data.value(section);
|
||||
if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt
|
||||
return hash_.value(Qt::EditRole);
|
||||
}
|
||||
return m_header_data.value(section).value(role);
|
||||
}
|
||||
return m_header_data.value(section).value(role);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,11 +164,35 @@ QVariant NomenclatureModel::data(const QModelIndex &index, int role) const
|
||||
*/
|
||||
void NomenclatureModel::query(const QString &query)
|
||||
{
|
||||
auto rm_ = m_query != query;
|
||||
if (rm_)
|
||||
{
|
||||
auto headers = projectDataBase::headersFromElementsInfoQuery(query);
|
||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
||||
this->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
||||
}
|
||||
emit beginResetModel();
|
||||
}
|
||||
|
||||
m_query = query;
|
||||
|
||||
if (m_project) {
|
||||
if (m_project)
|
||||
{
|
||||
if (rm_) {
|
||||
disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
m_project->dataBase()->updateDB();
|
||||
if (rm_) {
|
||||
m_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
if (rm_) { emit endResetModel();}
|
||||
}
|
||||
|
||||
QETProject *NomenclatureModel::project() const {
|
||||
return m_project.data();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,10 +201,22 @@ void NomenclatureModel::query(const QString &query)
|
||||
*/
|
||||
void NomenclatureModel::dataBaseUpdated()
|
||||
{
|
||||
m_record.clear();
|
||||
m_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
|
||||
auto new_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
|
||||
|
||||
auto row = m_record.size();
|
||||
auto col = row ? m_record.first().count() : 1;
|
||||
emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector<int>(Qt::DisplayRole));
|
||||
//This a very special case, if this nomenclature model is added
|
||||
//befor any element, column count return 0, so in this case we emit column inserted
|
||||
if (new_record.size() != m_record.size())
|
||||
{
|
||||
emit beginInsertColumns(index(0,0), 0, m_record.size()-1);
|
||||
m_record = new_record;
|
||||
emit endInsertColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_record = new_record;
|
||||
auto row = m_record.size();
|
||||
auto col = row ? m_record.first().count() : 1;
|
||||
|
||||
emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector<int>(Qt::DisplayRole));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ class NomenclatureModel : public QAbstractTableModel
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void query(const QString &query);
|
||||
QETProject *project() const;
|
||||
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
|
||||
@@ -42,10 +42,14 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
}
|
||||
|
||||
m_model = model;
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
@@ -264,3 +268,11 @@ void QetGraphicsHeaderItem::adjustSize()
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void QetGraphicsHeaderItem::modelReseted()
|
||||
{
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
void setUpBoundingRect();
|
||||
void headerDataChanged(Qt::Orientations orientation, int first, int last);
|
||||
void adjustSize();
|
||||
void modelReseted();
|
||||
|
||||
private:
|
||||
QRectF m_bounding_rect;
|
||||
|
||||
@@ -66,8 +66,10 @@ QetGraphicsTableItem::~QetGraphicsTableItem()
|
||||
*/
|
||||
void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
if (m_model)
|
||||
{
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
m_model = model;
|
||||
m_header_item->setModel(model);
|
||||
@@ -77,6 +79,7 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
|
||||
m_header_item->setPos(0, -m_header_item->rect().height());
|
||||
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,6 +277,10 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
|
||||
return false;
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::modelReseted() {
|
||||
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize
|
||||
* Calcule the minimum row height and the minimum column width for each columns
|
||||
@@ -377,7 +384,8 @@ void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0
|
||||
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i) {
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(i), m_header_item->minimumSectionWidth().at(i)) + b);
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(std::min(m_minimum_column_width.size()-1, i)),
|
||||
m_header_item->minimumSectionWidth().at(std::min(m_header_item->minimumSectionWidth().size()-1, i))) + b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +399,6 @@ void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelI
|
||||
setUpColumnAndRowMinimumSize();
|
||||
adjustSize();
|
||||
setSize(size_);
|
||||
qDebug() << "data changed";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include "nomenclaturemodelpropertieswidget.h"
|
||||
#include "ui_nomenclaturemodelpropertieswidget.h"
|
||||
#include "nomenclaturemodel.h"
|
||||
#include "qetproject.h"
|
||||
#include "elementquerywidget.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget
|
||||
@@ -49,11 +53,30 @@ void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) {
|
||||
m_model = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked
|
||||
*/
|
||||
void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
{}
|
||||
{
|
||||
QDialog d(this);
|
||||
auto l = new QVBoxLayout(this);
|
||||
d.setLayout(l);
|
||||
|
||||
void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
if (m_model) {
|
||||
m_model->query("SELECT plant, location, label, comment, description FROM element_info ORDER BY plant, location, label, comment, description");
|
||||
auto query_widget = new ElementQueryWidget(&d);
|
||||
l->addWidget(query_widget);
|
||||
|
||||
auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
l->addWidget(button_box);
|
||||
connect(button_box, &QDialogButtonBox::accepted, &d, &QDialog::accept);
|
||||
connect(button_box, &QDialogButtonBox::rejected, &d, &QDialog::reject);
|
||||
|
||||
if (d.exec()) {
|
||||
m_model->query(query_widget->queryStr());
|
||||
}
|
||||
}
|
||||
|
||||
void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
if (m_model && m_model->project()) {
|
||||
m_model->project()->dataBase()->updateDB();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user