2017-12-09 10:45:13 +01:00
|
|
|
|
#ifndef DATABASESTABLEMODEL_H
|
2017-02-12 14:03:42 +01:00
|
|
|
|
#define DATABASESTABLEMODEL_H
|
|
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
#include "BaseTableModel.h"
|
2022-01-19 19:10:05 +01:00
|
|
|
|
#include "catalog/PgDatabase.h"
|
2017-12-09 20:21:22 +01:00
|
|
|
|
#include <memory>
|
2017-02-12 14:03:42 +01:00
|
|
|
|
|
2022-01-19 19:10:05 +01:00
|
|
|
|
class OpenDatabase;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
class PgDatabaseCatalog;
|
2017-02-12 14:03:42 +01:00
|
|
|
|
|
|
|
|
|
|
/** Class for displaying the list of databases of a server in a QTableView
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2017-12-09 10:45:13 +01:00
|
|
|
|
class DatabasesTableModel : public BaseTableModel
|
2017-02-12 14:03:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2021-12-30 18:54:26 +01:00
|
|
|
|
using RowItem = PgDatabase;
|
|
|
|
|
|
|
2017-02-12 14:03:42 +01:00
|
|
|
|
enum e_Columns : int { NameCol, DbaCol, EncodingCol, CollateCol,
|
|
|
|
|
|
CTypeCol, IsTemplateCol, AllowConnCol, ConnLimitCol,
|
2021-03-11 06:59:31 +01:00
|
|
|
|
TablespaceCol, CommentCol, SizeCol, AclCol, COL_COUNT };
|
2017-02-12 14:03:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-19 19:10:05 +01:00
|
|
|
|
explicit DatabasesTableModel(std::shared_ptr<OpenDatabase> opendatabase, QObject *parent);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
|
2017-12-10 10:35:46 +01:00
|
|
|
|
void setDatabaseList(std::shared_ptr<const PgDatabaseCatalog> cat);
|
2017-02-12 14:03:42 +01:00
|
|
|
|
|
|
|
|
|
|
// Header:
|
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
|
|
|
|
// Basic functionality:
|
|
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
virtual Oid getType(int column) const override;
|
|
|
|
|
|
virtual QVariant getData(const QModelIndex &index) const override;
|
|
|
|
|
|
|
2021-03-31 16:06:45 +02:00
|
|
|
|
protected:
|
|
|
|
|
|
virtual QVariant getDataMeaning(const QModelIndex &index) const override;
|
2017-02-12 14:03:42 +01:00
|
|
|
|
private:
|
2022-01-19 19:10:05 +01:00
|
|
|
|
class DatabaseSize {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Oid oid;
|
|
|
|
|
|
int64_t totalBytes;
|
|
|
|
|
|
|
|
|
|
|
|
DatabaseSize()
|
|
|
|
|
|
: oid(InvalidOid)
|
|
|
|
|
|
, totalBytes(-1)
|
|
|
|
|
|
{}
|
|
|
|
|
|
};
|
|
|
|
|
|
using DatabaseSizes = std::vector<DatabaseSize>;
|
|
|
|
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
|
|
public:
|
|
|
|
|
|
PgDatabase database;
|
|
|
|
|
|
DatabaseSize size;
|
|
|
|
|
|
|
|
|
|
|
|
Database(const PgDatabase &db)
|
|
|
|
|
|
: database(db)
|
|
|
|
|
|
{}
|
|
|
|
|
|
};
|
|
|
|
|
|
using Databases = std::vector<Database>;
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<OpenDatabase> openDatabase;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
2022-01-19 19:10:05 +01:00
|
|
|
|
Databases databases;
|
|
|
|
|
|
|
|
|
|
|
|
void StartLoadDatabaseSizes(std::map<Oid, int> oidIndex);
|
|
|
|
|
|
DatabaseSizes QueryDatabaseSizes();
|
|
|
|
|
|
void PopulateSizes(std::map<Oid, int> oidIndex, DatabaseSizes sizes);
|
2017-02-12 14:03:42 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // DATABASESTABLEMODEL_H
|