PgAttribute loading + ColummnTableModel

Required enchancement to PgContainer to make multifield key work.
This commit is contained in:
eelke 2017-12-12 20:13:53 +01:00
parent f9caadb59e
commit e9d72d391d
32 changed files with 698 additions and 99 deletions

View file

@ -2,6 +2,7 @@
#define PGCONTAINER_H
#include "Pgsql_declare.h"
#include "Pgsql_Result.h"
#include <QString>
#include <memory>
#include <vector>
@ -18,7 +19,7 @@ public:
virtual void load(const Pgsql::Result &res) = 0;
};
template<typename T>
template<typename T, typename K=Oid>
class PgContainer: public IPgContainter {
public:
using t_Container = std::vector<T>; ///< Do not assume it will stay a vector only expect bidirectional access
@ -48,10 +49,10 @@ public:
return (int)m_container.size();
}
const T& getByOid(Oid oid) const
const T& getByKey(const K &key) const
{
auto lb_result = std::lower_bound(m_container.begin(), m_container.end(), oid);
if (lb_result != m_container.end() && lb_result->oid == oid)
auto lb_result = std::lower_bound(m_container.begin(), m_container.end(), key);
if (lb_result != m_container.end() && *lb_result == key)
return *lb_result;
return m_invalidInstance;
@ -71,9 +72,30 @@ public:
{
return m_container.at(idx);
}
/** Override to implement complete loading logic.
*
* Do not override this function if you only want to implement
* the loading of a single element. Override loadElem instead.
*/
virtual void load(const Pgsql::Result &res) override
{
m_container.clear();
m_container.reserve(res.rows());
for (auto row : res)
m_container.push_back(loadElem(row));
std::sort(m_container.begin(), m_container.end());
}
protected:
std::weak_ptr<PgDatabaseCatalog> m_catalogue;
t_Container m_container;
/** Override the implementation for this function to implement loading of single row.
*
* When overriding this function there is no need to override load.
*/
virtual T loadElem(const Pgsql::Row &) { return T(); }
private:
T m_invalidInstance;