diff --git a/core/gridform.h b/core/gridform.h index 2a1222e..354d22a 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -118,6 +118,10 @@ public slots: hideColumns(hide); enableButtons(); + connect(tableView()->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, const QModelIndex &){ + currentIndexChanged(current); + }); + return !m_permissionDenied; } diff --git a/core/igridform.cpp b/core/igridform.cpp index 66cce6a..cace158 100644 --- a/core/igridform.cpp +++ b/core/igridform.cpp @@ -24,10 +24,6 @@ IGridForm::IGridForm(QWidget *parent) : m_columnDialog = new ColumnDialog(this); connect(m_columnDialog, SIGNAL(accepted()), this, SLOT(columnsAccepted())); - connect(ui->tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, const QModelIndex &){ - currentIndexChanged(current); - }); - m_varFiller = new VariableFiller(); } @@ -93,6 +89,11 @@ QWidget *IGridForm::filterWidget() return ui->filterWidget; } +QVBoxLayout *IGridForm::mainLayout() +{ + return ui->verticalLayout; +} + void IGridForm::enableButtons() { ui->btnNew->setEnabled(canAddRecord()); @@ -179,7 +180,7 @@ void IGridForm::on_tableView_clicked(const QModelIndex &) void IGridForm::on_btnPrint_clicked() { - ReportDialog *dialog = new ReportDialog(this); + ReportDialog *dialog = new ReportDialog(currentRecordId() != 0, this); dialog->setAttribute(Qt::WA_DeleteOnClose); if (m_varFiller != NULL) diff --git a/core/igridform.h b/core/igridform.h index 81f8863..4cb87b8 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "columndialog.h" @@ -50,6 +51,7 @@ protected: virtual void currentIndexChanged(const QModelIndex ¤t) { Q_UNUSED(current) } void hideColumns(const QList &cols); QWidget *filterWidget(); + QVBoxLayout *mainLayout(); void enableButtons(); private slots: diff --git a/core/reporting/reportdialog.cpp b/core/reporting/reportdialog.cpp index 787831b..4bf81ee 100644 --- a/core/reporting/reportdialog.cpp +++ b/core/reporting/reportdialog.cpp @@ -6,11 +6,12 @@ #include "reportviewer.h" -ReportDialog::ReportDialog(QWidget *parent) : +ReportDialog::ReportDialog(bool recordSelected, QWidget *parent) : QDialog(parent), ui(new Ui::ReportDialog) { ui->setupUi(this); + m_recordSelected = recordSelected; } ReportDialog::~ReportDialog() @@ -33,6 +34,7 @@ void ReportDialog::setReports(ReportList reports) foreach (ReportPtr report, reports) { QStandardItem *item = new QStandardItem((report->listReport() ? QIcon(":/icons/list.svg") : QIcon(":/icons/report.svg")), report->name()); + item->setEnabled(report->listReport() || m_recordSelected); model->appendRow(item); } @@ -41,14 +43,13 @@ void ReportDialog::setReports(ReportList reports) connect(ui->listReports->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex, QModelIndex){ ui->textDescription->setText(m_reports[ui->listReports->currentIndex().row()]->description()); + ui->btnPreview->setEnabled(ui->listReports->currentIndex().isValid()); + ui->btnPrint->setEnabled(ui->listReports->currentIndex().isValid()); }); if (!reports.isEmpty()) { - ui->btnPreview->setEnabled(true); - ui->btnPrint->setEnabled(true); - ui->listReports->setCurrentIndex(model->index(0, 0)); } } diff --git a/core/reporting/reportdialog.h b/core/reporting/reportdialog.h index cc7795a..52f9a11 100644 --- a/core/reporting/reportdialog.h +++ b/core/reporting/reportdialog.h @@ -13,7 +13,7 @@ class ReportDialog : public QDialog Q_OBJECT public: - explicit ReportDialog(QWidget *parent = 0); + explicit ReportDialog(bool recordSelected = false, QWidget *parent = 0); ~ReportDialog(); void setReports(ReportList reports); @@ -28,6 +28,7 @@ private slots: private: Ui::ReportDialog *ui; ReportList m_reports; + bool m_recordSelected; }; #endif // REPORTDIALOG_H