#include "CrudTab.h" #include "ui_CrudTab.h" #include "CrudModel.h" #include "MainWindow.h" #include "ResultTableModelUtil.h" #include "PgLabItemDelegate.h" 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 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 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 ¤t, 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 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; }