pgLab/pglab/CrudTab.cpp
eelke fcb191f2cc Overview of triggers extended with function name and arguments.
Did a lot of refactoring on the catalog to keep things clean.
2018-11-18 19:30:45 +01:00

101 lines
2.7 KiB
C++

#include "CrudTab.h"
#include "ui_CrudTab.h"
#include "CrudModel.h"
#include "MainWindow.h"
#include "ResultTableModelUtil.h"
#include "PgLabItemDelegate.h"
#include <QMenu>
CrudTab::CrudTab(MainWindow *parent)
: PlgPage(parent)
, ui(new Ui::CrudTab)
, m_window(parent)
{
ui->setupUi(this);
SetTableViewDefault(ui->tableView);
auto delegate = new PgLabItemDelegate(ui->tableView);
ui->tableView->setItemDelegate(delegate);
m_crudModel = new CrudModel(parent);
ui->tableView->setModel(m_crudModel);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->addAction(ui->actionRemove_rows);
auto horizontal_header = ui->tableView->horizontalHeader();
horizontal_header->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(horizontal_header, &QHeaderView::customContextMenuRequested,
this, &CrudTab::headerCustomContextMenu);
//auto selection_model = ui->tableView->selectionModel();
// connect(ui->tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
// &CrudTab::tableView_currentRowChanged);
}
CrudTab::~CrudTab()
{
delete ui;
}
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);
}
//void CrudTab::tableView_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
//{
//}
void CrudTab::refresh()
{
m_crudModel->loadData();
}
void CrudTab::on_actionRemove_rows_triggered()
{
// determine selection
// ui->tableView->currentIndex()
// selectionModel()->
//ui->tableView->selectionModel()->selectedRows()
m_crudModel->removeRow(ui->tableView->currentIndex().row());
//removeRows();
}
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;
}
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));
}