diff --git a/sources/dataBase/projectdatabase.cpp b/sources/dataBase/projectdatabase.cpp index ac53e5b48..58e5a109c 100644 --- a/sources/dataBase/projectdatabase.cpp +++ b/sources/dataBase/projectdatabase.cpp @@ -84,57 +84,6 @@ QVector projectDataBase::elementsInfoFromQuery(const QString &query return result_; } -/** - * @brief projectDataBase::headersFromElementsInfoQuery - * @param query - * @return the header according to @query. - * Header can be false, notably when user create is own query. - */ -QStringList projectDataBase::headersFromElementNomenclatureViewQuery(const QString &query) -{ - QStringList header_string; - if (!query.startsWith("SELECT ") && !query.contains("FROM")) { - return header_string; - } - - auto header = query; - header.remove(0, 7); //Remove SELECT from the string; - header.truncate(header.indexOf("FROM")); //Now we only have the string between SELECT and FROM - header.replace(" ", ""); //remove white space - QStringList list = header.split(","); //split each column - - if (list.isEmpty()) { - return header_string; - } - - for (int i=0 ; i elementsInfoFromQuery(const QString &query); void updateDB(); QETProject *project() const; - - static QStringList headersFromElementNomenclatureViewQuery(const QString &query); + QSqlQuery newQuery(const QString &query = QString()); signals: void dataBaseUpdated(); diff --git a/sources/factory/qetgraphicstablefactory.cpp b/sources/factory/qetgraphicstablefactory.cpp index 80aaa9116..bb813b86a 100644 --- a/sources/factory/qetgraphicstablefactory.cpp +++ b/sources/factory/qetgraphicstablefactory.cpp @@ -97,7 +97,6 @@ QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTab { auto model = new NomenclatureModel(diagram->project(), diagram->project()); model->query(dialog->queryStr()); - model->autoHeaders(); model->setData(model->index(0,0), int(dialog->tableAlignment()), Qt::TextAlignmentRole); model->setData(model->index(0,0), dialog->tableFont(), Qt::FontRole); model->setData(model->index(0,0), QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1); diff --git a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp index 39ecdf704..c65e5bc44 100644 --- a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp +++ b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.cpp @@ -22,6 +22,9 @@ #include #include +#include +#include + /** * @brief NomenclatureModel::NomenclatureModel @@ -179,12 +182,15 @@ void NomenclatureModel::query(const QString &query) } m_project->dataBase()->updateDB(); if (rm_) { + setHeaderString(); m_record = m_project->dataBase()->elementsInfoFromQuery(m_query); connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated); } } if (rm_) { emit endResetModel();} + + } /** @@ -199,18 +205,6 @@ 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::headersFromElementNomenclatureViewQuery(m_query); - for (auto i=0 ; isetHeaderData(i, Qt::Horizontal, headers.at(i)); - } -} - /** * @brief NomenclatureModel::toXml * Save the model to xml,since model can have unlimited data we only save few data (only these used by qelectrotech). @@ -263,7 +257,6 @@ void NomenclatureModel::fromXml(const QDomElement &element) return; query(element.firstChildElement("query").text()); - autoHeaders(); //Index 0,0 auto index_00 = element.firstChildElement("index00"); @@ -302,3 +295,30 @@ void NomenclatureModel::dataBaseUpdated() emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); } } + +void NomenclatureModel::setHeaderString() +{ + auto q = m_project->dataBase()->newQuery(m_query); + auto record = q.record(); + + for (auto i=0 ; isetHeaderData(i, Qt::Horizontal, header_name); + } +} diff --git a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h index 98bdaa8cf..6f6ad7c13 100644 --- a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h +++ b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h @@ -48,7 +48,6 @@ class NomenclatureModel : public QAbstractTableModel void query(const QString &query); QString queryString() const; QETProject *project() const; - void autoHeaders(); QDomElement toXml(QDomDocument &document) const; void fromXml(const QDomElement &element); @@ -56,6 +55,7 @@ class NomenclatureModel : public QAbstractTableModel private: void dataBaseUpdated(); + void setHeaderString(); private: QPointer m_project;