#include "igridform.h" #include "ui_gridform.h" #include #include #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_form = NULL; m_columnDialog = new ColumnDialog(this); connect(m_columnDialog, SIGNAL(accepted()), this, SLOT(columnsAccepted())); } IGridForm::~IGridForm() { delete ui; } void IGridForm::setPluginId(const QString &pluginId) { m_pluginId = pluginId; if (m_filterUi != NULL) { m_filterUi->setPluginId(pluginId); } if (m_form != NULL) { m_form->setPluginId(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::widthChanged(int logicalIndex, int oldSize, int newSize) { Q_UNUSED(oldSize); QMap widths = Context::instance().settings()->value("grids/" + pluginId() + "/widths").toMap(); widths[QString::number(logicalIndex)] = newSize; Context::instance().settings()->setValue("grids/" + pluginId() + "/widths", QVariant::fromValue(widths)); } void IGridForm::on_btnFilter_toggled(bool checked) { if (checked) { ui->filterWidget->setVisible(true); } else { ui->filterWidget->setVisible(false); } } void IGridForm::on_tableView_clicked(const QModelIndex &index) { if (ui->tableView->currentIndex().isValid()) { ui->btnEdit->setEnabled(true); ui->btnDelete->setEnabled(true); } }