2018-01-09 20:39:43 +01:00
|
|
|
|
#include "CrudTab.h"
|
2018-01-08 20:45:52 +01:00
|
|
|
|
#include "ui_CrudTab.h"
|
2018-01-09 20:39:43 +01:00
|
|
|
|
#include "CrudModel.h"
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
|
#include "ResultTableModelUtil.h"
|
2018-01-15 13:30:30 +01:00
|
|
|
|
#include "PgLabItemDelegate.h"
|
2018-11-18 19:30:45 +01:00
|
|
|
|
#include <QMenu>
|
2018-01-08 20:45:52 +01:00
|
|
|
|
|
2018-01-09 20:39:43 +01:00
|
|
|
|
|
|
|
|
|
|
CrudTab::CrudTab(MainWindow *parent)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
: PlgPage(parent)
|
2018-01-09 20:39:43 +01:00
|
|
|
|
, ui(new Ui::CrudTab)
|
|
|
|
|
|
, m_window(parent)
|
2018-01-08 20:45:52 +01:00
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
2018-01-09 20:39:43 +01:00
|
|
|
|
|
|
|
|
|
|
SetTableViewDefault(ui->tableView);
|
2018-01-15 13:30:30 +01:00
|
|
|
|
|
|
|
|
|
|
auto delegate = new PgLabItemDelegate(ui->tableView);
|
|
|
|
|
|
ui->tableView->setItemDelegate(delegate);
|
|
|
|
|
|
|
2018-01-09 20:39:43 +01:00
|
|
|
|
m_crudModel = new CrudModel(parent);
|
|
|
|
|
|
ui->tableView->setModel(m_crudModel);
|
|
|
|
|
|
|
2018-02-05 21:42:54 +01:00
|
|
|
|
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
2018-04-08 09:02:22 +02:00
|
|
|
|
ui->tableView->addAction(ui->actionRemove_rows);
|
2018-11-18 19:30:45 +01:00
|
|
|
|
|
|
|
|
|
|
auto horizontal_header = ui->tableView->horizontalHeader();
|
|
|
|
|
|
horizontal_header->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
|
|
|
|
|
connect(horizontal_header, &QHeaderView::customContextMenuRequested,
|
|
|
|
|
|
this, &CrudTab::headerCustomContextMenu);
|
|
|
|
|
|
|
2018-02-05 21:42:54 +01:00
|
|
|
|
//auto selection_model = ui->tableView->selectionModel();
|
|
|
|
|
|
// connect(ui->tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
|
|
|
|
|
// &CrudTab::tableView_currentRowChanged);
|
2018-01-08 20:45:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CrudTab::~CrudTab()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
2018-01-09 20:39:43 +01:00
|
|
|
|
|
|
|
|
|
|
void CrudTab::setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_db = db;
|
|
|
|
|
|
m_table = table;
|
|
|
|
|
|
// m_catalog = cat;
|
|
|
|
|
|
// m_tablesModel->setCatalog(cat);
|
|
|
|
|
|
// ui->tableListTable->resizeColumnsToContents();
|
|
|
|
|
|
// m_namespaceFilterWidget->init(cat->namespaces());
|
|
|
|
|
|
|
|
|
|
|
|
// auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
|
|
|
|
|
|
// highlighter->setTypes(*cat->types());
|
|
|
|
|
|
m_crudModel->setConfig(db, table);
|
|
|
|
|
|
}
|
2018-02-05 21:42:54 +01:00
|
|
|
|
|
|
|
|
|
|
//void CrudTab::tableView_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
2018-02-05 22:40:17 +01:00
|
|
|
|
|
|
|
|
|
|
void CrudTab::refresh()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_crudModel->loadData();
|
|
|
|
|
|
}
|
2018-04-08 09:02:22 +02:00
|
|
|
|
|
|
|
|
|
|
void CrudTab::on_actionRemove_rows_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
// determine selection
|
|
|
|
|
|
|
|
|
|
|
|
// ui->tableView->currentIndex()
|
|
|
|
|
|
// selectionModel()->
|
|
|
|
|
|
|
|
|
|
|
|
//ui->tableView->selectionModel()->selectedRows()
|
|
|
|
|
|
m_crudModel->removeRow(ui->tableView->currentIndex().row());
|
|
|
|
|
|
//removeRows();
|
|
|
|
|
|
}
|
2018-05-20 13:42:30 +02:00
|
|
|
|
|
|
|
|
|
|
std::vector<QAction*> CrudTab::getToolbarActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (actions.empty()) {
|
|
|
|
|
|
QAction *action = new QAction(QIcon(":/icons/script_go.png"), tr("Refresh"), this);
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F5));
|
|
|
|
|
|
connect(action, &QAction::triggered, this, &CrudTab::refresh);
|
|
|
|
|
|
actions.push_back(action);
|
|
|
|
|
|
}
|
|
|
|
|
|
return actions;
|
|
|
|
|
|
}
|
2018-11-18 19:30:45 +01:00
|
|
|
|
|
|
|
|
|
|
void CrudTab::headerCustomContextMenu(const QPoint &pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto menu = new QMenu(this);
|
|
|
|
|
|
|
|
|
|
|
|
QAction *action = new QAction(QIcon(":/icons/script_go.png"), tr("Refresh"), this);
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F5));
|
|
|
|
|
|
connect(action, &QAction::triggered, this, &CrudTab::refresh);
|
|
|
|
|
|
menu->addAction(action);
|
|
|
|
|
|
|
|
|
|
|
|
auto horizontal_header = ui->tableView->horizontalHeader();
|
|
|
|
|
|
menu->popup(horizontal_header->mapToGlobal(pos));
|
|
|
|
|
|
}
|