pgLab/pglab/QueryParamListController.cpp
eelke 0cbd0d16a1 Seperated the Param data from the model.
This makes saving and loading the parameter data easier to do without cluttering up the model class.
2017-12-09 15:46:33 +01:00

49 lines
1.1 KiB
C++

#include "QueryParamListController.h"
#include "OpenDatabase.h"
#include "PgDatabaseCatalogue.h"
#include "PgTypeContainer.h"
#include <QTableView>
QueryParamListController::QueryParamListController(QTableView *tv,
OpenDatabase *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->catalogue()->types();
for (auto e : m_paramList.GetParams()) {
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);
}