Merge remote-tracking branch 'origin/QetGraphicsTableItem'

This commit is contained in:
Laurent Trinques
2020-04-12 18:51:38 +02:00
parent 41541dde2c
commit 73149973e3
38 changed files with 3232 additions and 528 deletions

View File

@@ -0,0 +1,229 @@
/*
Copyright 2006-2020 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 "nomenclaturemodel.h"
#include "qetapp.h"
#include "qetproject.h"
#include <QModelIndex>
#include <QFont>
/**
* @brief NomenclatureModel::NomenclatureModel
* @param project :project of this nomenclature
* @param parent : parent QObject
*/
NomenclatureModel::NomenclatureModel(QETProject *project, QObject *parent) :
QAbstractTableModel(parent),
m_project(project)
{
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
}
/**
* @brief NomenclatureModel::rowCount
* Reimplemented for QAbstractTableModel
* @param parent
* @return
*/
int NomenclatureModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_record.count();
}
/**
* @brief NomenclatureModel::columnCount
* Reimplemented for QAbstractTableModel
* @param parent
* @return
*/
int NomenclatureModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
if (m_record.count()) {
return m_record.first().count();
}
return 0;
}
/**
* @brief NomenclatureModel::setHeaderData
* Reimplemented from QAbstractTableModel.
* Only horizontal orientation is accepted.
* @param section
* @param orientation
* @param value
* @param role
* @return
*/
bool NomenclatureModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
{
if (orientation == Qt::Vertical) {
return false;
}
auto hash_ = m_header_data.value(section);
hash_.insert(role, value);
m_header_data.insert(section, hash_);
headerDataChanged(orientation, section, section);
return true;
}
/**
* @brief NomenclatureModel::headerData
* Reimplemented from QAbstractTableModel.
* @param section
* @param orientation
* @param role
* @return
*/
QVariant NomenclatureModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Vertical) {
return QVariant();
}
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 QVariant();
}
/**
* @brief NomenclatureModel::setData
* Only store the data for the index 0.0
* @param index
* @param value
* @param role
* @return
*/
bool NomenclatureModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || index.row() != 0 || index.column() != 0) {
return false;
}
m_index_0_0_data.insert(role, value);
emit dataChanged(index, index, QVector<int>(role));
return true;
}
/**
* @brief NomenclatureModel::data
* Reimplemented for QAbstractTableModel
* @param index
* @param role
* @return
*/
QVariant NomenclatureModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() == 0 &&
index.column() == 0 &&
role != Qt::DisplayRole) {
return m_index_0_0_data.value(role);
}
if (role == Qt::DisplayRole) {
QVariant v(m_record.at(index.row()).at(index.column()));
return v;
}
return QVariant();
}
/**
* @brief NomenclatureModel::query
* Query the internall bd with @query.
* @param query
*/
void NomenclatureModel::query(const QString &query)
{
auto rm_ = m_query != query;
if (rm_) {
emit beginResetModel();
}
m_query = query;
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();
}
/**
* @brief NomenclatureModel::autoHeaders
* Try to determine the name of each columns header
*/
void NomenclatureModel::autoHeaders()
{
auto headers = projectDataBase::headersFromElementsInfoQuery(m_query);
for (auto i=0 ; i<headers.size() ; ++i) {
this->setHeaderData(i, Qt::Horizontal, headers.at(i));
}
}
/**
* @brief NomenclatureModel::dataBaseUpdated
* slot called when the project database is updated
*/
void NomenclatureModel::dataBaseUpdated()
{
auto new_record = m_project->dataBase()->elementsInfoFromQuery(m_query);
//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));
}
}

View File

@@ -0,0 +1,59 @@
/*
Copyright 2006-2020 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 NOMENCLATUREMODEL_H
#define NOMENCLATUREMODEL_H
#include <QAbstractTableModel>
#include <QPointer>
class QETProject;
/**
* @brief The NomenclatureModel class
* An element nomenclature Model.
* This model represent a 2D data.
*/
class NomenclatureModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit NomenclatureModel(QETProject *project, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
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;
void autoHeaders();
private:
void dataBaseUpdated();
private:
QPointer<QETProject> m_project;
QString m_query;
QVector<QStringList> m_record;
QHash<int, QHash<int, QVariant>> m_header_data;
QHash<int, QVariant> m_index_0_0_data;
};
#endif // NOMENCLATUREMODEL_H

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2019 QElectroTech Team
Copyright 2006-2020 QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
@@ -21,6 +21,8 @@
#include <QFontMetrics>
#include <QPainter>
static int no_model_height = 20;
static int no_model_width = 40;
/**
* @brief QetGraphicsHeaderItem::QetGraphicsHeaderItem
* @param parent
@@ -42,13 +44,23 @@ 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);
setUpMinimumSectionsSize();
m_current_sections_width.clear();
m_current_sections_width.resize(m_sections_minimum_width.size());
if (m_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());
} else {
setUpMinimumSectionsSize();
}
adjustSize();
}
@@ -93,7 +105,6 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
painter->setBrush(brush);
painter->setPen(pen);
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
painter->drawRect(m_current_rect);
if (!m_model)
@@ -101,6 +112,7 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
painter->restore();
return;
}
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
//Draw vertical lines
auto offset= 0;
@@ -141,7 +153,20 @@ QRect QetGraphicsHeaderItem::rect() const {
* @param size
*/
void QetGraphicsHeaderItem::resizeSection(int logicalIndex, int size)
{
{
if (!m_model)
{
m_current_sections_width.clear();
m_current_sections_width.append(no_model_width);
m_sections_minimum_width.clear();
m_sections_minimum_width.append(no_model_width);
m_current_rect.setWidth(no_model_width);
setUpBoundingRect();
update();
emit sectionResized(0, no_model_width);
return;
}
if (logicalIndex >= m_current_sections_width.size() ||
m_current_sections_width.at(logicalIndex) == size) {
return;
@@ -191,7 +216,12 @@ void QetGraphicsHeaderItem::setMargins(const QMargins &margins)
*/
void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
{
if (!m_model) {
if (!m_model)
{
m_minimum_section_height = no_model_height;
m_sections_minimum_width.clear();
m_sections_minimum_width.append(no_model_width);
m_minimum_width = no_model_width;
return;
}
@@ -264,3 +294,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();
}

View File

@@ -46,7 +46,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject
enum { Type = UserType + 1301 };
int type() const override { return Type; }
void setModel(QAbstractItemModel *model);
void setModel(QAbstractItemModel *model = nullptr);
QAbstractItemModel *model() const;
virtual QRectF boundingRect() const override;
@@ -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;

View File

@@ -26,6 +26,9 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
static int no_model_height = 20;
static int no_model_width = 40;
/**
* @brief QetGraphicsTableItem::QetGraphicsTableItem
* Default constructor
@@ -52,31 +55,6 @@ QetGraphicsTableItem::QetGraphicsTableItem(QGraphicsItem *parent) :
connect(m_header_item, &QetGraphicsHeaderItem::heightResized, this, [this]() {
m_header_item->setPos(0, 0-m_header_item->rect().height());
});
/*******ONLY FOR TEST DURING DEVEL*********/
auto model = new QStandardItemModel(this);
int r = 20;
int c = 5;
for (int row = 0; row < r; ++row)
{
for (int column = 0; column < c; ++column) {
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
model->setItem(row, column, item);
}
}
model->setData(model->index(0,0), Qt::AlignLeft, Qt::TextAlignmentRole);
model->setData(model->index(0,0), QETApp::diagramTextsFont(), Qt::FontRole);
model->setHeaderData(0, Qt::Horizontal, Qt::AlignHCenter, Qt::TextAlignmentRole);
model->setHeaderData(0, Qt::Horizontal, QETApp::diagramTextsFont(), Qt::FontRole);
model->setHeaderData(0, Qt::Horizontal, "Label");
model->setHeaderData(1, Qt::Horizontal, "Folio");
model->setHeaderData(2, Qt::Horizontal, "Fonction");
model->setHeaderData(3, Qt::Horizontal, "Fabricant");
model->setHeaderData(4, Qt::Horizontal, "Installation");
this->setModel(model);
this->setPos(50,50);
/******************************************/
}
QetGraphicsTableItem::~QetGraphicsTableItem()
@@ -91,8 +69,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);
@@ -101,7 +81,11 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
adjustSize();
m_header_item->setPos(0, -m_header_item->rect().height());
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
if (m_model)
{
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
}
}
/**
@@ -139,15 +123,25 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
pen.setWidthF(0.7);
pen.setColor(Qt::black);
painter->setPen(pen);
painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value<QFont>());
painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height());
if (isSelected())
{
painter->save();
QColor color(Qt::darkBlue);
color.setAlpha(20);
painter->setBrush(QBrush (color));
painter->setPen(Qt::NoPen);
painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height());
painter->restore();
}
if(!m_model)
{
painter->restore();
return;
}
painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value<QFont>());
//Draw vertical lines
auto offset= 0;
@@ -159,9 +153,18 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
offset += m_header_item->sectionSize(i);
}
//Calcule the number of rows to display.
auto row_count = m_model->rowCount();
if (m_previous_table) //Remove the number of row already displayed by previous tables
row_count -= m_previous_table->displayNRowOffset();
if (m_number_of_displayed_row > 0) //User override the number of row to display
row_count = std::min(row_count, m_number_of_displayed_row);
//Draw horizontal lines
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(m_model->rowCount());
for(auto i= 1 ; i-1<m_model->rowCount() ; ++i)
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
for(auto i= 1 ; i-1<row_count ; ++i)
{
QPointF p1(m_header_item->rect().left(), cell_height*i);
QPointF p2(m_header_item->rect().right(), cell_height*i);
@@ -169,7 +172,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
}
//Write text of each cell
for (auto i= 0 ; i<m_model->rowCount() ; ++i)
for (auto i=0 ; i<row_count ; ++i)
{
QPointF top_left(m_margin.left(), i==0? m_margin.top() : cell_height*i + m_margin.top());
@@ -181,9 +184,10 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
}
QSize size(m_header_item->sectionSize(j) - m_margin.left() - m_margin.right(),
static_cast<int>(cell_height) - m_margin.top() - m_margin.bottom());
auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i;
painter->drawText(QRectF(top_left, size),
m_model->data(m_model->index(0,0), Qt::TextAlignmentRole).toInt(),
m_model->index(i, j).data().toString());
m_model->index(index_row, j).data().toString());
}
}
@@ -240,10 +244,155 @@ QSize QetGraphicsTableItem::size() const
*/
QSize QetGraphicsTableItem::minimumSize() const
{
QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*m_model->rowCount());
if (!m_model) {
return QSize(no_model_width, no_model_height);
}
auto row_count = m_model->rowCount();
if (m_previous_table) {
row_count -= m_previous_table->displayNRowOffset();
}
if (m_number_of_displayed_row > 0)
row_count = std::min(row_count, m_number_of_displayed_row);
QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*row_count);
return s;
}
/**
* @brief QetGraphicsTableItem::setDisplayNRow
* Limit the number of row to display
* @param number : set to 0 or less to disabled the limit of row to display
*/
void QetGraphicsTableItem::setDisplayNRow(const int &number) {
m_number_of_displayed_row = number;
setToMinimumHeight();
if (m_next_table)
m_next_table->previousTableDisplayRowChanged();
}
/**
* @brief QetGraphicsTableItem::displayNRow
* @return the number of row displayed.
* A value of 0 or less mean there is no limit
*/
int QetGraphicsTableItem::displayNRow() const {
return m_number_of_displayed_row;
}
/**
* @brief QetGraphicsTableItem::setPreviousTable
* Set the previous table to @table.
* If this table already have a previous table, the previous table will be replaced.
* Set new table to nullptr to remove an existing previous table.
* The table uses the model of the new previous table.
* Since the table does not take ownership of the model, it is your responsibility to manage the old model.
* Linked tables (table with next and/or previous table) share the same model, a table always take the model of the previous table..
* When remove a previous table (set to nullptr) from a table, the model is also removed, you need to set a new model
* @param table
*/
void QetGraphicsTableItem::setPreviousTable(QetGraphicsTableItem *table)
{
if (m_previous_table == table) {
return;
}
auto old_previous_table = m_previous_table;
m_previous_table = table;
if (m_previous_table) //set previous table and get her model
{
m_previous_table->setNextTable(this);
setModel(m_previous_table->m_model);
}
else //Remove model
{
setModel(nullptr);
}
if (old_previous_table &&
old_previous_table->nextTable() == this) {
old_previous_table->setNextTable(nullptr);
}
//Set the m_model to every next table
auto next_ = m_next_table;
while (next_) {
next_->setModel(m_model);
next_ = next_->nextTable();
}
}
/**
* @brief QetGraphicsTableItem::setNextTable
* Set the next table to @table
* nullptr will remove an existing next table.
* @param table
*/
void QetGraphicsTableItem::setNextTable(QetGraphicsTableItem *table)
{
if (m_next_table == table) {
return;
}
auto old_next_table = m_next_table;
m_next_table = table;
if (m_next_table) {
m_next_table->setPreviousTable(this);
}
if (old_next_table &&
old_next_table->previousTable() == this) {
old_next_table->setPreviousTable(nullptr);
}
}
void QetGraphicsTableItem::setTableName(const QString &name) {
m_name = name;
}
QString QetGraphicsTableItem::tableName() const {
return m_name;
}
/**
* @brief QetGraphicsTableItem::displayNRowOffset
* @return the offset (aka the last displayed row) of displayed row.
* If this item have a previous table, the previous offset is added.
*/
int QetGraphicsTableItem::displayNRowOffset() const
{
auto offset_ = m_number_of_displayed_row;
if(m_previous_table)
offset_ += m_previous_table->displayNRowOffset();
return offset_;
}
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const {
return m_previous_table;
}
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const {
return m_next_table;
}
/**
* @brief QetGraphicsTableItem::setToMinimumHeight
* Set the height to the the minimum.
* The width stay unchanged.
*/
void QetGraphicsTableItem::setToMinimumHeight()
{
auto size_ = size();
size_.setHeight(1);
setSize(size_);
}
/**
* @brief QetGraphicsTableItem::hoverEnterEvent
* Reimplemented from QetGraphicsItem
@@ -251,9 +400,12 @@ QSize QetGraphicsTableItem::minimumSize() const
*/
void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
adjustHandlerPos();
this->scene()->addItem(&m_handler_item);
m_handler_item.installSceneEventFilter(this);
if (m_model)
{
adjustHandlerPos();
this->scene()->addItem(&m_handler_item);
m_handler_item.installSceneEventFilter(this);
}
QGraphicsObject::hoverEnterEvent(event);
}
@@ -264,7 +416,9 @@ void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
*/
void QetGraphicsTableItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
m_handler_item.scene()->removeItem(&m_handler_item);
if (m_model) {
m_handler_item.scene()->removeItem(&m_handler_item);
}
QGraphicsObject::hoverLeaveEvent(event);
}
@@ -299,6 +453,11 @@ 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>());
setToMinimumHeight();
}
/**
* @brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize
* Calcule the minimum row height and the minimum column width for each columns
@@ -306,7 +465,10 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
*/
void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
{
if (!m_model) {
if (!m_model)
{
m_minimum_row_height = no_model_height;
m_minimum_column_width = m_header_item->minimumSectionWidth();
return;
}
@@ -358,6 +520,8 @@ void QetGraphicsTableItem::setUpHandler()
void QetGraphicsTableItem::handlerMousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
diagram()->clearSelection();
this->setSelected(true);
m_old_size = size();
//User start to resize the table, disconnect the signal to avoid double paint.
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
@@ -398,11 +562,21 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *ev
*/
void QetGraphicsTableItem::adjustColumnsWidth()
{
if (!m_model)
{
auto h_ = m_header_item->minimumSectionWidth();
for (auto i=0 ; i<h_.size() ; ++i) {
m_header_item->resizeSection(i, h_.at(i));
}
return;
}
auto a = m_current_size.width() - minimumSize().width();
auto b = a/m_model->columnCount();
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);
}
}
@@ -440,6 +614,12 @@ void QetGraphicsTableItem::headerSectionResized()
*/
void QetGraphicsTableItem::adjustSize()
{
//If there is no model, set the size to minimum
if (!m_model) {
setSize(minimumSize());
return;
}
if (m_current_size.height() < minimumSize().height())
{
prepareGeometryChange();
@@ -457,3 +637,10 @@ void QetGraphicsTableItem::adjustSize()
update();
}
}
void QetGraphicsTableItem::previousTableDisplayRowChanged() {
setToMinimumHeight();
if (m_next_table) {
m_next_table->previousTableDisplayRowChanged();
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2020 QElectroTech Team
This file is part of QElectroTech.
@@ -35,6 +35,8 @@ class QetGraphicsHeaderItem;
* Text font.
* Text alignment in the cell
* These two last parameters are not settable directly with the table but trough the model to be displayed by the table.
* The table search for font and alignment only in the index(0,0) for all the table.
* By consequence, set data in other index than 0,0 is useless also the alignment and font can't be set individually for each cell.
*/
class QetGraphicsTableItem : public QetGraphicsItem
{
@@ -42,6 +44,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
Q_PROPERTY(QSize size READ size WRITE setSize)
Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow)
public:
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
@@ -50,7 +53,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
enum { Type = UserType + 1300 };
int type() const override { return Type; }
void setModel(QAbstractItemModel *model);
void setModel(QAbstractItemModel *model = nullptr);
QAbstractItemModel *model() const;
virtual QRectF boundingRect() const override;
@@ -61,6 +64,16 @@ class QetGraphicsTableItem : public QetGraphicsItem
void setSize(const QSize &size);
QSize size() const;
QSize minimumSize() const;
void setDisplayNRow(const int &number);
int displayNRow() const;
void setPreviousTable(QetGraphicsTableItem *table = nullptr);
void setNextTable(QetGraphicsTableItem *table = nullptr);
void setTableName(const QString &name);
QString tableName() const;
int displayNRowOffset() const;
QetGraphicsTableItem *previousTable() const;
QetGraphicsTableItem *nextTable() const;
void setToMinimumHeight();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
@@ -80,6 +93,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void headerSectionResized();
void adjustSize();
void previousTableDisplayRowChanged();
private:
QAbstractItemModel *m_model= nullptr;
@@ -87,6 +101,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
QMargins m_margin;
QVector<int> m_minimum_column_width;
int m_minimum_row_height;
int m_number_of_displayed_row = 0;
QSize m_current_size,
m_old_size;
@@ -95,6 +110,11 @@ class QetGraphicsTableItem : public QetGraphicsItem
QetGraphicsHandlerItem m_handler_item;
QetGraphicsHeaderItem *m_header_item = nullptr;
QetGraphicsTableItem *m_previous_table = nullptr,
*m_next_table = nullptr;
QString m_name;
};
#endif // QetGraphicsTableItem_H

View File

@@ -22,6 +22,8 @@
#include "diagram.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "itemmodelcommand.h"
#include "propertieseditorfactory.h"
#include "elementprovider.h"
#include <QAbstractItemModel>
#include <QFontDialog>
@@ -69,6 +71,12 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table)
for (auto c : m_connect_list) {
disconnect(c);
}
if (m_current_model_editor)
{
ui->m_content_layout->removeWidget(m_current_model_editor);
m_current_model_editor->deleteLater();
m_current_model_editor = nullptr;
}
}
m_table_item = table;
@@ -76,6 +84,12 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table)
m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::xChanged, this, &GraphicsTablePropertiesEditor::updateUi);
m_connect_list << connect(m_table_item.data(), &QetGraphicsTableItem::yChanged, this, &GraphicsTablePropertiesEditor::updateUi);
if (auto editor = PropertiesEditorFactory::propertiesEditor(table->model(), this))
{
ui->m_content_layout->insertWidget(0, editor);
m_current_model_editor = editor;
}
updateUi();
}
@@ -117,6 +131,12 @@ QUndoCommand *GraphicsTablePropertiesEditor::associatedUndo() const
return undo;
}
if (ui->m_display_n_row_sb->value() != m_table_item->displayNRow()) {
auto undo = new QPropertyUndoCommand(m_table_item.data(), "displayNRow", m_table_item->displayNRow(), ui->m_display_n_row_sb->value());
undo->setText(tr("Modifier le nombre de ligne affiché par un tableau"));
return undo;
}
QMargins header_margins(ui->m_header_left_margin->value(),
ui->m_header_top_margin->value(),
ui->m_header_right_margin->value(),
@@ -229,8 +249,33 @@ void GraphicsTablePropertiesEditor::updateUi()
}
m_edit_connection.clear();
ui->m_table_name_le->setText(m_table_item->tableName());
ui->m_x_pos->setValue(m_table_item->pos().x());
ui->m_y_pos->setValue(m_table_item->pos().y());
ui->m_display_n_row_sb->setValue(m_table_item->displayNRow());
ui->m_previous_table_cb->clear();
m_other_table_vector.clear();
ui->m_previous_table_cb->addItem(tr("Aucun")); //Add no previous table
if (auto item_ = m_table_item->previousTable()) //Add the current previous table
{
m_other_table_vector.append(item_);
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
ui->m_previous_table_cb->setCurrentIndex(ui->m_previous_table_cb->findData(m_other_table_vector.indexOf(item_)));
}
ElementProvider ep(m_table_item->diagram()->project());
for (auto item_ : ep.table(m_table_item, m_table_item->model())) //Add available tables
{
if (item_ != m_table_item &&
item_->nextTable() == nullptr)
{
m_other_table_vector.append(item_);
ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_));
}
}
auto margin = m_table_item->headerItem()->margins();
ui->m_header_top_margin ->setValue(margin.top());
@@ -249,8 +294,10 @@ void GraphicsTablePropertiesEditor::updateUi()
return;
}
m_header_button_group->button(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt())->setChecked(true);
m_table_button_group->button(m_table_item->model()->data(m_table_item->model()->index(0,0), Qt::TextAlignmentRole).toInt())->setChecked(true);
if (auto button = m_header_button_group->button(m_table_item->model()->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt()))
button->setChecked(true);
if (auto button = m_table_button_group->button(m_table_item->model()->data(m_table_item->model()->index(0,0), Qt::TextAlignmentRole).toInt()))
button->setChecked(true);
setUpEditConnection();
}
@@ -280,5 +327,19 @@ void GraphicsTablePropertiesEditor::setUpEditConnection()
m_edit_connection << connect(ui->m_table_bottom_margin, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply);
m_edit_connection << connect(m_table_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply);
m_edit_connection << connect(m_header_button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply);
m_edit_connection << connect(ui->m_display_n_row_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply);
}
}
void GraphicsTablePropertiesEditor::on_m_table_name_le_textEdited(const QString &arg1) {
m_table_item->setTableName(arg1);
}
void GraphicsTablePropertiesEditor::on_m_previous_table_cb_activated(int index)
{
if (index == 0) {
m_table_item->setPreviousTable();
} else {
m_table_item->setPreviousTable(m_other_table_vector.at(ui->m_previous_table_cb->currentData().toInt()));
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
@@ -51,8 +51,10 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
void on_m_header_font_pb_clicked();
void on_m_table_font_pb_clicked();
virtual void updateUi() override;
void on_m_table_name_le_textEdited(const QString &arg1);
void on_m_previous_table_cb_activated(int index);
private:
private:
void setUpEditConnection();
private:
@@ -62,6 +64,8 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget
m_edit_connection;
QButtonGroup *m_header_button_group = nullptr,
*m_table_button_group = nullptr;
QWidget *m_current_model_editor = nullptr;
QVector<QetGraphicsTableItem *> m_other_table_vector;
};
Q_DECLARE_METATYPE(QMargins)

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>484</height>
<width>467</width>
<height>672</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,239 +15,528 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position</string>
<widget class="QTabWidget" name="m_tab">
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="m_display_tab">
<attribute name="title">
<string>Affichage</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLineEdit" name="m_table_name_le">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Nom du tableau</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position et lignes</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="4" colspan="2">
<widget class="QComboBox" name="m_previous_table_cb">
<property name="insertPolicy">
<enum>QComboBox::InsertAtBottom</enum>
</property>
<item>
<property name="text">
<string>Aucun</string>
</property>
</item>
</widget>
</item>
<item row="0" column="6" colspan="2">
<widget class="QSpinBox" name="m_display_n_row_sb">
<property name="specialValueText">
<string>Toutes</string>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label">
<property name="text">
<string>Lignes à afficher :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="7">
<widget class="QPushButton" name="m_next_pb">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tableau suivant</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="6">
<widget class="QPushButton" name="m_previous_cb">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tableau précédent</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="7">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="0" column="4">
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="0" column="8">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tableau précédent :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>En tête</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="4">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_header_left_margin">
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="m_header_top_margin"/>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Aligement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_header_font_pb">
<property name="text">
<string>Police</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Tableau</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="2">
<widget class="QSpinBox" name="m_table_bottom_margin"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_table_left_margin"/>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="m_table_top_margin"/>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="m_table_right_margin"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Alignement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_table_font_pb">
<property name="text">
<string>Police</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_content_tab">
<attribute name="title">
<string>Contenu</string>
</attribute>
<layout class="QVBoxLayout" name="m_content_layout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>534</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>En tête</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QSpinBox" name="m_header_left_margin"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_header_top_margin"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Aligement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_header_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_header_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Tableau</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="2">
<widget class="QSpinBox" name="m_table_right_margin"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="m_table_top_margin"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_table_bottom_margin"/>
</item>
<item row="1" column="0">
<widget class="QSpinBox" name="m_table_left_margin"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Alignement :</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_left_rb">
<property name="text">
<string>Gauche</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_center_rb">
<property name="text">
<string>Centré</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="m_table_align_right_rb">
<property name="text">
<string>Droite</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_table_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,87 @@
/*
Copyright 2006-2020 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 "nomenclaturemodelpropertieswidget.h"
#include "ui_nomenclaturemodelpropertieswidget.h"
#include "nomenclaturemodel.h"
#include "qetproject.h"
#include "elementquerywidget.h"
#include <QDialogButtonBox>
/**
* @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget
* @param model
* @param parent
*/
NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget(NomenclatureModel *model, QWidget *parent) :
PropertiesEditorWidget(parent),
ui(new Ui::NomenclatureModelPropertiesWidget)
{
ui->setupUi(this);
setModel(model);
}
/**
* @brief NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget
*/
NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget() {
delete ui;
}
/**
* @brief NomenclatureModelPropertiesWidget::setModel
* @param model
*/
void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) {
m_model = model;
ui->m_edit_query_pb->setEnabled(m_model);
ui->m_refresh_pb->setEnabled(m_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);
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());
auto headers = query_widget->header();
for (auto i=0 ; i<headers.size() ; ++i) {
m_model->setHeaderData(i, Qt::Horizontal, headers.at(i));
}
}
}
void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() {
if (m_model && m_model->project()) {
m_model->project()->dataBase()->updateDB();
}
}

View File

@@ -0,0 +1,52 @@
/*
Copyright 2006-2020 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 NOMENCLATUREMODELPROPERTIESWIDGET_H
#define NOMENCLATUREMODELPROPERTIESWIDGET_H
#include "PropertiesEditor/propertieseditorwidget.h"
class NomenclatureModel;
namespace Ui {
class NomenclatureModelPropertiesWidget;
}
/**
* @brief The NomenclatureModelPropertiesWidget class
* This class is an editor for a NomenclatureModel
*/
class NomenclatureModelPropertiesWidget : public PropertiesEditorWidget
{
Q_OBJECT
public:
explicit NomenclatureModelPropertiesWidget(NomenclatureModel *model = nullptr, QWidget *parent = nullptr);
~NomenclatureModelPropertiesWidget();
void setModel(NomenclatureModel *model);
private slots:
void on_m_edit_query_pb_clicked();
void on_m_refresh_pb_clicked();
private:
Ui::NomenclatureModelPropertiesWidget *ui;
NomenclatureModel *m_model = nullptr;
};
#endif // NOMENCLATUREMODELPROPERTIESWIDGET_H

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NomenclatureModelPropertiesWidget</class>
<widget class="QWidget" name="NomenclatureModelPropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>106</width>
<height>92</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="m_edit_query_pb">
<property name="text">
<string>Requête</string>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/edit-rename.png</normaloff>:/ico/16x16/edit-rename.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_refresh_pb">
<property name="text">
<string>Recharger</string>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/view-refresh.png</normaloff>:/ico/16x16/view-refresh.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="../../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>