diff --git a/core/columndialog.cpp b/core/columndialog.cpp new file mode 100644 index 0000000..4c42a9d --- /dev/null +++ b/core/columndialog.cpp @@ -0,0 +1,59 @@ +#include "columndialog.h" +#include "ui_columndialog.h" + +#include +#include + +ColumnDialog::ColumnDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ColumnDialog) +{ + ui->setupUi(this); +} + +ColumnDialog::~ColumnDialog() +{ + delete ui; +} + +void ColumnDialog::setTable(QTableView *table) +{ + ui->tableWidget->clear(); + ui->tableWidget->setColumnCount(1); + ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Column")); + ui->tableWidget->setRowCount(table->model()->columnCount()); + for (int i = 0; i < table->model()->columnCount(); i++) + { + QVariant data = table->model()->headerData(i, Qt::Horizontal); + QTableWidgetItem *item = new QTableWidgetItem(data.toString()); + + if (table->isColumnHidden(i)) + { + item->setCheckState(Qt::Unchecked); + } + else + { + item->setCheckState(Qt::Checked); + } + ui->tableWidget->setItem(i, 0, item); + } + + QHeaderView *horzHdr = ui->tableWidget->horizontalHeader(); + horzHdr->setStretchLastSection(true); +} + +QList ColumnDialog::columnsToHide() +{ + QList list; + + for (int i = 0; i < ui->tableWidget->rowCount(); i++) + { + if (ui->tableWidget->item(i, 0)->checkState() == Qt::Unchecked) + { + list.append(i); + } + } + + return list; +} + diff --git a/core/columndialog.h b/core/columndialog.h new file mode 100644 index 0000000..9adb6b0 --- /dev/null +++ b/core/columndialog.h @@ -0,0 +1,28 @@ +#ifndef COLUMNDIALOG_H +#define COLUMNDIALOG_H + +#include +#include +#include +#include + +namespace Ui { +class ColumnDialog; +} + +class ColumnDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ColumnDialog(QWidget *parent = 0); + ~ColumnDialog(); + + void setTable(QTableView *table); + QList columnsToHide(); + +private: + Ui::ColumnDialog *ui; +}; + +#endif // COLUMNDIALOG_H diff --git a/core/columndialog.ui b/core/columndialog.ui new file mode 100644 index 0000000..4e1b943 --- /dev/null +++ b/core/columndialog.ui @@ -0,0 +1,77 @@ + + + ColumnDialog + + + + 0 + 0 + 473 + 390 + + + + Select columns + + + + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ColumnDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ColumnDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/core/core.pro b/core/core.pro index 14183f3..ffedd33 100644 --- a/core/core.pro +++ b/core/core.pro @@ -27,7 +27,8 @@ SOURCES += \ users/users.cpp \ users/usersui.cpp \ users/tablemodel.cpp \ - users/userform.cpp + users/userform.cpp \ + columndialog.cpp HEADERS += core.h\ core_global.h \ @@ -54,7 +55,8 @@ HEADERS += core.h\ users/users.h \ users/usersui.h \ users/tablemodel.h \ - users/userform.h + users/userform.h \ + columndialog.h unix { target.path = /usr/lib @@ -81,7 +83,8 @@ DISTFILES += \ FORMS += \ gridform.ui \ formdialog.ui \ - users/userform.ui + users/userform.ui \ + columndialog.ui OTHER_FILES += \ users/metaData.json diff --git a/core/gridform.h b/core/gridform.h index 9874dce..27b43e3 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -3,6 +3,7 @@ #include #include +#include #include "autoform.h" #include "autotablemodel.h" @@ -64,6 +65,15 @@ public slots: m_tableModel->setData(service()->all()); tableView()->setModel(m_tableModel); + + QList varList = Context::instance().settings()->value("grids/" + pluginId() + "/hide").toList(); + QList hide; + + foreach (QVariant var, varList) { + hide.append(var.toInt()); + } + + hideColumns(hide); } private: diff --git a/core/gridform.ui b/core/gridform.ui index 00bda1c..e09120b 100644 --- a/core/gridform.ui +++ b/core/gridform.ui @@ -70,6 +70,9 @@ + + Qt::CustomContextMenu + QAbstractItemView::SingleSelection @@ -82,6 +85,11 @@ + + + Select columns + + diff --git a/core/igridform.cpp b/core/igridform.cpp index 0ffc3a9..3f2634a 100644 --- a/core/igridform.cpp +++ b/core/igridform.cpp @@ -1,12 +1,20 @@ #include "igridform.h" - #include "ui_gridform.h" +#include + +#include "context.h" + IGridForm::IGridForm(QWidget *parent) : QWidget(parent), ui(new Ui::GridForm) { ui->setupUi(this); + 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() @@ -28,6 +36,13 @@ QTableView *IGridForm::tableView() return ui->tableView; } +void IGridForm::hideColumns(const QList &cols) +{ + foreach (int col, cols) { + tableView()->setColumnHidden(col, true); + } +} + void IGridForm::on_btnNew_clicked() { @@ -43,3 +58,33 @@ 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)); +} diff --git a/core/igridform.h b/core/igridform.h index 8ed7e45..7c676a9 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -4,7 +4,10 @@ #include #include #include +#include +#include +#include "columndialog.h" #include "defaultformhandler.h" #include "core_global.h" @@ -35,16 +38,22 @@ protected: virtual void handleEditRecord() = 0; virtual void handleDeleteRecord() = 0; + void hideColumns(const QList &cols); + private slots: void on_btnNew_clicked(); void on_btnEdit_clicked(); - void on_btnDelete_clicked(); + void on_tableView_customContextMenuRequested(const QPoint &pos); + void on_actionSelectColumns_triggered(); + void columnsAccepted(); private: QString m_pluginId; IFormHandler *m_formHandler; Ui::GridForm *ui; + QMenu *m_contextMenu; + ColumnDialog *m_columnDialog; }; #endif // IGRIDFORM_H diff --git a/core/imetadataplugin.cpp b/core/imetadataplugin.cpp index c9e502a..2c92307 100644 --- a/core/imetadataplugin.cpp +++ b/core/imetadataplugin.cpp @@ -9,10 +9,15 @@ IMetaDataPlugin::IMetaDataPlugin() { + m_service = NULL; } IMetaDataPlugin::~IMetaDataPlugin() { + if (m_service != NULL) + { + delete m_service; + } } QString IMetaDataPlugin::pluginName()