#include "QueryParamListController.h" #include "OpenDatabase.h" #include "PgDatabaseCatalog.h" #include "PgTypeContainer.h" #include QueryParamListController::QueryParamListController(QTableView *tv, std::shared_ptr opendb, QWidget *parent) : QObject(parent) , paramTableView(tv) , m_openDatabase(opendb) { if (opendb) { m_typeDelegate.setTypeSelectionModel(opendb->typeSelectionModel()); } paramTableView->setModel(&m_paramList); paramTableView->setItemDelegateForColumn(1, &m_typeDelegate); } Pgsql::Params QueryParamListController::params() const { Pgsql::Params params; auto types = m_openDatabase->catalog()->types(); for (auto e : m_paramList.GetParams()) { // some types have two names that are in seperate fields // this function only checks one field currently :( // for example integer vs int4, bigint vs int8 Oid oid = types->getByName(e.type)->oid(); params.add(e.value, oid); } return params; } bool QueryParamListController::empty() const { return m_paramList.rowCount() == 0; } void QueryParamListController::on_addParam() { m_paramList.insertRows(m_paramList.rowCount(), 1); } void QueryParamListController::on_removeParam() { auto rc = m_paramList.rowCount(); if (rc > 0) m_paramList.removeRows(rc-1, 1); }