Added Column dialog for selecting visible columns. Selection is stored to settings.

print
Josef Rokos 9 years ago
parent d99267e488
commit 37d2371148

@ -0,0 +1,59 @@
#include "columndialog.h"
#include "ui_columndialog.h"
#include <QTableWidgetItem>
#include <QHeaderView>
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<int> ColumnDialog::columnsToHide()
{
QList<int> list;
for (int i = 0; i < ui->tableWidget->rowCount(); i++)
{
if (ui->tableWidget->item(i, 0)->checkState() == Qt::Unchecked)
{
list.append(i);
}
}
return list;
}

@ -0,0 +1,28 @@
#ifndef COLUMNDIALOG_H
#define COLUMNDIALOG_H
#include <QDialog>
#include <QObject>
#include <QTableView>
#include <QList>
namespace Ui {
class ColumnDialog;
}
class ColumnDialog : public QDialog
{
Q_OBJECT
public:
explicit ColumnDialog(QWidget *parent = 0);
~ColumnDialog();
void setTable(QTableView *table);
QList<int> columnsToHide();
private:
Ui::ColumnDialog *ui;
};
#endif // COLUMNDIALOG_H

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ColumnDialog</class>
<widget class="QDialog" name="ColumnDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>390</height>
</rect>
</property>
<property name="windowTitle">
<string>Select columns</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ColumnDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ColumnDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

@ -27,7 +27,8 @@ SOURCES += \
users/users.cpp \ users/users.cpp \
users/usersui.cpp \ users/usersui.cpp \
users/tablemodel.cpp \ users/tablemodel.cpp \
users/userform.cpp users/userform.cpp \
columndialog.cpp
HEADERS += core.h\ HEADERS += core.h\
core_global.h \ core_global.h \
@ -54,7 +55,8 @@ HEADERS += core.h\
users/users.h \ users/users.h \
users/usersui.h \ users/usersui.h \
users/tablemodel.h \ users/tablemodel.h \
users/userform.h users/userform.h \
columndialog.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
@ -81,7 +83,8 @@ DISTFILES += \
FORMS += \ FORMS += \
gridform.ui \ gridform.ui \
formdialog.ui \ formdialog.ui \
users/userform.ui users/userform.ui \
columndialog.ui
OTHER_FILES += \ OTHER_FILES += \
users/metaData.json users/metaData.json

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include <QMessageBox> #include <QMessageBox>
#include <QHeaderView>
#include "autoform.h" #include "autoform.h"
#include "autotablemodel.h" #include "autotablemodel.h"
@ -64,6 +65,15 @@ public slots:
m_tableModel->setData(service()->all()); m_tableModel->setData(service()->all());
tableView()->setModel(m_tableModel); tableView()->setModel(m_tableModel);
QList<QVariant> varList = Context::instance().settings()->value("grids/" + pluginId() + "/hide").toList();
QList<int> hide;
foreach (QVariant var, varList) {
hide.append(var.toInt());
}
hideColumns(hide);
} }
private: private:

@ -70,6 +70,9 @@
</item> </item>
<item> <item>
<widget class="QTableView" name="tableView"> <widget class="QTableView" name="tableView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
@ -82,6 +85,11 @@
</widget> </widget>
</item> </item>
</layout> </layout>
<action name="actionSelectColumns">
<property name="text">
<string>Select columns</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

@ -1,12 +1,20 @@
#include "igridform.h" #include "igridform.h"
#include "ui_gridform.h" #include "ui_gridform.h"
#include <QList>
#include "context.h"
IGridForm::IGridForm(QWidget *parent) : IGridForm::IGridForm(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::GridForm) ui(new Ui::GridForm)
{ {
ui->setupUi(this); 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() IGridForm::~IGridForm()
@ -28,6 +36,13 @@ QTableView *IGridForm::tableView()
return ui->tableView; return ui->tableView;
} }
void IGridForm::hideColumns(const QList<int> &cols)
{
foreach (int col, cols) {
tableView()->setColumnHidden(col, true);
}
}
void IGridForm::on_btnNew_clicked() void IGridForm::on_btnNew_clicked()
{ {
@ -43,3 +58,33 @@ void IGridForm::on_btnDelete_clicked()
{ {
handleDeleteRecord(); 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<int> hide = m_columnDialog->columnsToHide();
hideColumns(hide);
QList<QVariant> varList;
foreach (int i, hide) {
varList.append(i);
}
Context::instance().settings()->setValue("grids/" + pluginId() + "/hide", QVariant::fromValue(varList));
}

@ -4,7 +4,10 @@
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include <QTableView> #include <QTableView>
#include <QMenu>
#include <QList>
#include "columndialog.h"
#include "defaultformhandler.h" #include "defaultformhandler.h"
#include "core_global.h" #include "core_global.h"
@ -35,16 +38,22 @@ protected:
virtual void handleEditRecord() = 0; virtual void handleEditRecord() = 0;
virtual void handleDeleteRecord() = 0; virtual void handleDeleteRecord() = 0;
void hideColumns(const QList<int> &cols);
private slots: private slots:
void on_btnNew_clicked(); void on_btnNew_clicked();
void on_btnEdit_clicked(); void on_btnEdit_clicked();
void on_btnDelete_clicked(); void on_btnDelete_clicked();
void on_tableView_customContextMenuRequested(const QPoint &pos);
void on_actionSelectColumns_triggered();
void columnsAccepted();
private: private:
QString m_pluginId; QString m_pluginId;
IFormHandler *m_formHandler; IFormHandler *m_formHandler;
Ui::GridForm *ui; Ui::GridForm *ui;
QMenu *m_contextMenu;
ColumnDialog *m_columnDialog;
}; };
#endif // IGRIDFORM_H #endif // IGRIDFORM_H

@ -9,10 +9,15 @@
IMetaDataPlugin::IMetaDataPlugin() IMetaDataPlugin::IMetaDataPlugin()
{ {
m_service = NULL;
} }
IMetaDataPlugin::~IMetaDataPlugin() IMetaDataPlugin::~IMetaDataPlugin()
{ {
if (m_service != NULL)
{
delete m_service;
}
} }
QString IMetaDataPlugin::pluginName() QString IMetaDataPlugin::pluginName()

Loading…
Cancel
Save