2020-04-12 18:51:38 +02:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2020-06-18 18:52:29 +02:00
|
|
|
#include "projectdbmodelpropertieswidget.h"
|
|
|
|
#include "ui_projectdbmodelpropertieswidget.h"
|
|
|
|
#include "projectdbmodel.h"
|
2020-04-12 18:51:38 +02:00
|
|
|
#include "qetproject.h"
|
|
|
|
#include "elementquerywidget.h"
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
|
|
|
/**
|
2020-06-18 18:52:29 +02:00
|
|
|
* @brief projectDBModelPropertiesWidget::projectDBModelPropertiesWidget
|
2020-04-12 18:51:38 +02:00
|
|
|
* @param model
|
|
|
|
* @param parent
|
|
|
|
*/
|
2020-06-18 18:52:29 +02:00
|
|
|
ProjectDBModelPropertiesWidget::ProjectDBModelPropertiesWidget(ProjectDBModel *model, QWidget *parent) :
|
2020-04-12 18:51:38 +02:00
|
|
|
PropertiesEditorWidget(parent),
|
2020-06-18 18:52:29 +02:00
|
|
|
ui(new Ui::ProjectDBModelPropertiesWidget)
|
2020-04-12 18:51:38 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setModel(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-18 18:52:29 +02:00
|
|
|
* @brief projectDBModelPropertiesWidget::~projectDBModelPropertiesWidget
|
2020-04-12 18:51:38 +02:00
|
|
|
*/
|
2020-06-18 18:52:29 +02:00
|
|
|
ProjectDBModelPropertiesWidget::~ProjectDBModelPropertiesWidget() {
|
2020-04-12 18:51:38 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-18 18:52:29 +02:00
|
|
|
* @brief projectDBModelPropertiesWidget::setModel
|
2020-04-12 18:51:38 +02:00
|
|
|
* @param model
|
|
|
|
*/
|
2020-06-18 18:52:29 +02:00
|
|
|
void ProjectDBModelPropertiesWidget::setModel(ProjectDBModel *model) {
|
2020-04-12 18:51:38 +02:00
|
|
|
m_model = model;
|
|
|
|
ui->m_edit_query_pb->setEnabled(m_model);
|
|
|
|
ui->m_refresh_pb->setEnabled(m_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-18 18:52:29 +02:00
|
|
|
* @brief projectDBModelPropertiesWidget::on_m_edit_query_pb_clicked
|
2020-04-12 18:51:38 +02:00
|
|
|
*/
|
2020-06-18 18:52:29 +02:00
|
|
|
void ProjectDBModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
2020-04-12 18:51:38 +02:00
|
|
|
{
|
|
|
|
QDialog d(this);
|
2020-04-29 11:48:45 +02:00
|
|
|
auto l = new QVBoxLayout;
|
2020-04-12 18:51:38 +02:00
|
|
|
d.setLayout(l);
|
|
|
|
|
|
|
|
auto query_widget = new ElementQueryWidget(&d);
|
2020-04-29 11:48:45 +02:00
|
|
|
query_widget->setQuery(m_model->queryString());
|
2020-04-12 18:51:38 +02:00
|
|
|
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())
|
|
|
|
{
|
2020-06-18 18:52:29 +02:00
|
|
|
m_model->setQuery(query_widget->queryStr());
|
2020-04-12 18:51:38 +02:00
|
|
|
auto headers = query_widget->header();
|
|
|
|
for (auto i=0 ; i<headers.size() ; ++i) {
|
|
|
|
m_model->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:52:29 +02:00
|
|
|
void ProjectDBModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
2020-04-12 18:51:38 +02:00
|
|
|
if (m_model && m_model->project()) {
|
|
|
|
m_model->project()->dataBase()->updateDB();
|
|
|
|
}
|
|
|
|
}
|