#include "igridform.h" #include "ui_gridform.h" #include #include "context.h" #include "filterui.h" IGridForm::IGridForm(QWidget *parent) : QWidget(parent), ui(new Ui::GridForm) { ui->setupUi(this); ui->filterWidget->setVisible(false); m_contextMenu = new QMenu(this); m_contextMenu->addAction(ui->actionSelectColumns); m_columnDialog = new ColumnDialog(this); connect(m_columnDialog, SIGNAL(accepted()), this, SLOT(columnsAccepted())); } IGridForm::~IGridForm() { } void IGridForm::setPluginId(const QString &pluginId) { m_pluginId = pluginId; } QString IGridForm::pluginId() { return m_pluginId; } QTableView *IGridForm::tableView() { return ui->tableView; } void IGridForm::hideColumns(const QList &cols) { foreach (int col, cols) { tableView()->setColumnHidden(col, true); } } QWidget *IGridForm::filterWidget() { return ui->filterWidget; } void IGridForm::on_btnNew_clicked() { handleNewRecord(); } void IGridForm::on_btnEdit_clicked() { handleEditRecord(); } void IGridForm::on_btnDelete_clicked() { handleDeleteRecord(); } void IGridForm::on_tableView_customContextMenuRequested(const QPoint &pos) { m_contextMenu->popup(tableView()->viewport()->mapToGlobal(pos)); } void IGridForm::on_actionSelectColumns_triggered() { m_columnDialog->setTable(tableView()); m_columnDialog->show(); } void IGridForm::columnsAccepted() { for(int i = 0; i < tableView()->model()->columnCount(); i++) { tableView()->setColumnHidden(i, false); } QList hide = m_columnDialog->columnsToHide(); hideColumns(hide); QList varList; foreach (int i, hide) { varList.append(i); } Context::instance().settings()->setValue("grids/" + pluginId() + "/hide", QVariant::fromValue(varList)); } void IGridForm::on_btnFilter_toggled(bool checked) { if (checked) { ui->filterWidget->setVisible(true); } else { ui->filterWidget->setVisible(false); } }