Miscellaneous changes. Including a copy action.
This commit is contained in:
parent
242f5464df
commit
4a2c6cc396
19 changed files with 147 additions and 43 deletions
BIN
icons/page_white_copy.png
Normal file
BIN
icons/page_white_copy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 862 B |
|
|
@ -15,6 +15,7 @@
|
||||||
#include <querytab.h>
|
#include <querytab.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
|
#include "OpenDatabase.h"
|
||||||
|
|
||||||
namespace pg = Pgsql;
|
namespace pg = Pgsql;
|
||||||
|
|
||||||
|
|
@ -25,8 +26,9 @@ MainWindow::MainWindow(MasterController *master, QWidget *parent)
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->tabWidget->setDocumentMode(true);
|
ui->tabWidget->setDocumentMode(true);
|
||||||
|
|
||||||
|
|
||||||
//ui->tabWidget->setTabsClosable(true);
|
//ui->tabWidget->setTabsClosable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,6 +57,10 @@ QueryTab *MainWindow::GetActiveQueryTab()
|
||||||
void MainWindow::setConfig(const ConnectionConfig &config)
|
void MainWindow::setConfig(const ConnectionConfig &config)
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
|
auto res = OpenDatabase::createOpenDatabase(config);
|
||||||
|
if (res.valid()) {
|
||||||
|
m_database = res.get();
|
||||||
|
}
|
||||||
QString title = "pglab - ";
|
QString title = "pglab - ";
|
||||||
title += m_config.name().c_str();
|
title += m_config.name().c_str();
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
|
@ -140,7 +146,8 @@ void MainWindow::on_actionAbout_triggered()
|
||||||
" INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
" INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
||||||
"FOR A PARTICULAR PURPOSE.\n"
|
"FOR A PARTICULAR PURPOSE.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"This program is dynamically linked with Qt 5.7 Copyright (C) 2016 The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
"This program is dynamically linked with Qt 5.8 Copyright (C) 2016 "
|
||||||
|
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
||||||
"\n"
|
"\n"
|
||||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||||
"attribution 3.0 license\n"
|
"attribution 3.0 license\n"
|
||||||
|
|
@ -252,3 +259,15 @@ void MainWindow::on_actionShow_connection_manager_triggered()
|
||||||
{
|
{
|
||||||
m_masterController->showConnectionManager();
|
m_masterController->showConnectionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionCopy_triggered()
|
||||||
|
{
|
||||||
|
// What should be copied?
|
||||||
|
|
||||||
|
QWidget *w = QApplication::focusWidget();
|
||||||
|
QTableView *tv = dynamic_cast<QTableView*>(w);
|
||||||
|
if (tv) {
|
||||||
|
copySelectionToClipboard(tv);
|
||||||
|
}
|
||||||
|
//this->ui->
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ namespace Pgsql {
|
||||||
class QueryTab;
|
class QueryTab;
|
||||||
class MasterController;
|
class MasterController;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
|
class OpenDatabase;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
|
@ -43,13 +44,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void QueueTask(TSQueue::t_Callable c);
|
void QueueTask(TSQueue::t_Callable c);
|
||||||
|
|
||||||
|
OpenDatabase* getDatabase() { return m_database; }
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
TSQueue m_taskQueue;
|
TSQueue m_taskQueue;
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
|
OpenDatabase *m_database;
|
||||||
|
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
|
|
||||||
|
|
@ -78,6 +80,7 @@ private slots:
|
||||||
void on_tabWidget_tabCloseRequested(int index);
|
void on_tabWidget_tabCloseRequested(int index);
|
||||||
void on_actionExplain_triggered();
|
void on_actionExplain_triggered();
|
||||||
void on_actionShow_connection_manager_triggered();
|
void on_actionShow_connection_manager_triggered();
|
||||||
|
void on_actionCopy_triggered();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,14 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionShow_connection_manager"/>
|
<addaction name="actionShow_connection_manager"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuEdit">
|
||||||
|
<property name="title">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionCopy"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuTest"/>
|
<addaction name="menuTest"/>
|
||||||
|
<addaction name="menuEdit"/>
|
||||||
<addaction name="menuQuery"/>
|
<addaction name="menuQuery"/>
|
||||||
<addaction name="menuView"/>
|
<addaction name="menuView"/>
|
||||||
<addaction name="menuHelp"/>
|
<addaction name="menuHelp"/>
|
||||||
|
|
@ -101,6 +108,8 @@
|
||||||
<addaction name="actionExport_data"/>
|
<addaction name="actionExport_data"/>
|
||||||
<addaction name="actionClose"/>
|
<addaction name="actionClose"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionCopy"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExecute_SQL"/>
|
<addaction name="actionExecute_SQL"/>
|
||||||
<addaction name="actionExplain"/>
|
<addaction name="actionExplain"/>
|
||||||
<addaction name="actionExplain_Analyze"/>
|
<addaction name="actionExplain_Analyze"/>
|
||||||
|
|
@ -250,6 +259,19 @@
|
||||||
<string>Show connection manager</string>
|
<string>Show connection manager</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionCopy">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normalon>:/icons/page_white_copy.png</normalon>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+C</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "opendatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "pgsqldatabasecatalogue.h"
|
#include "pgsqldatabasecatalogue.h"
|
||||||
|
#include "PgsqlConn.h"
|
||||||
|
#include "typeselectionitemmodel.h"
|
||||||
|
|
||||||
Expected<OpenDatabase*> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
Expected<OpenDatabase*> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
||||||
{
|
{
|
||||||
|
|
@ -26,6 +28,26 @@ OpenDatabase::~OpenDatabase()
|
||||||
|
|
||||||
bool OpenDatabase::Init()
|
bool OpenDatabase::Init()
|
||||||
{
|
{
|
||||||
// m_catalogue->load(m_config);
|
Pgsql::Connection conn;
|
||||||
|
auto kw = m_config.getKeywords();
|
||||||
|
auto vals = m_config.getValues();
|
||||||
|
if (conn.connect(kw, vals, 0)) {
|
||||||
|
m_catalogue->loadAll(conn);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PgsqlDatabaseCatalogue* OpenDatabase::getCatalogue()
|
||||||
|
{
|
||||||
|
return m_catalogue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TypeSelectionItemModel* OpenDatabase::getTypeSelectionModel()
|
||||||
|
{
|
||||||
|
if (m_typeSelectionModel == nullptr) {
|
||||||
|
m_typeSelectionModel = new TypeSelectionItemModel(nullptr);
|
||||||
|
m_typeSelectionModel->setTypeList(m_catalogue->getTypes());
|
||||||
|
}
|
||||||
|
return m_typeSelectionModel;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "expected.h"
|
#include "expected.h"
|
||||||
|
|
||||||
class PgsqlDatabaseCatalogue;
|
class PgsqlDatabaseCatalogue;
|
||||||
|
class TypeSelectionItemModel;
|
||||||
|
|
||||||
/** Instances of this class represent a single database on which atleast one
|
/** Instances of this class represent a single database on which atleast one
|
||||||
* window is opened. This class is used to track details about that database.
|
* window is opened. This class is used to track details about that database.
|
||||||
|
|
@ -20,6 +21,8 @@ public:
|
||||||
OpenDatabase& operator=(const OpenDatabase &) = delete;
|
OpenDatabase& operator=(const OpenDatabase &) = delete;
|
||||||
~OpenDatabase();
|
~OpenDatabase();
|
||||||
|
|
||||||
|
PgsqlDatabaseCatalogue* getCatalogue();
|
||||||
|
TypeSelectionItemModel* getTypeSelectionModel();
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
@ -28,6 +31,8 @@ private:
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
PgsqlDatabaseCatalogue *m_catalogue;
|
PgsqlDatabaseCatalogue *m_catalogue;
|
||||||
|
|
||||||
|
TypeSelectionItemModel *m_typeSelectionModel = nullptr;
|
||||||
|
|
||||||
OpenDatabase(const ConnectionConfig& cfg, QObject *parent = 0);
|
OpenDatabase(const ConnectionConfig& cfg, QObject *parent = 0);
|
||||||
bool Init();
|
bool Init();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "paramlistmodel.h"
|
#include "ParamListModel.h"
|
||||||
|
|
||||||
ParamListModel::ParamListModel(QObject *parent)
|
ParamListModel::ParamListModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
#include "paramtypedelegate.h"
|
#include "ParamTypeDelegate.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include "TypeSelectionItemModel.h"
|
#include "TypeSelectionItemModel.h"
|
||||||
|
|
||||||
ParamTypeDelegate::ParamTypeDelegate()
|
ParamTypeDelegate::ParamTypeDelegate()
|
||||||
: m_typeSelectionModel(new TypeSelectionItemModel)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ParamTypeDelegate::~ParamTypeDelegate()
|
ParamTypeDelegate::~ParamTypeDelegate()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model)
|
||||||
{
|
{
|
||||||
delete m_typeSelectionModel;
|
m_typeSelectionModel = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
||||||
|
|
@ -18,12 +20,16 @@ QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
||||||
|
|
||||||
{
|
{
|
||||||
QWidget *w = nullptr;
|
QWidget *w = nullptr;
|
||||||
// if (index.data().canConvert<StarRating>()) {
|
|
||||||
QComboBox *cmbbx = new QComboBox(parent);
|
QComboBox *cmbbx = new QComboBox(parent);
|
||||||
cmbbx->setModel(m_typeSelectionModel);
|
cmbbx->setModel(m_typeSelectionModel);
|
||||||
w = cmbbx;
|
w = cmbbx;
|
||||||
// } else {
|
|
||||||
// w = QStyledItemDelegate::createEditor(parent, option, index);
|
// ...
|
||||||
// }
|
// m_ComboBox->setView(m_ColumnView);
|
||||||
|
// m_ComboBox->view()->setCornerWidget(new QSizeGrip(m_ColumnView));
|
||||||
|
// m_ComboBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
|
// ...
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
|
void setTypeSelectionModel(TypeSelectionItemModel* model);
|
||||||
private:
|
private:
|
||||||
TypeSelectionItemModel* m_typeSelectionModel = nullptr;
|
TypeSelectionItemModel* m_typeSelectionModel = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
18
pglab.pro
18
pglab.pro
|
|
@ -13,7 +13,7 @@ TEMPLATE = app
|
||||||
|
|
||||||
INCLUDEPATH += C:\prog\include
|
INCLUDEPATH += C:\prog\include
|
||||||
DEFINES += WIN32_LEAN_AND_MEAN NOMINMAX
|
DEFINES += WIN32_LEAN_AND_MEAN NOMINMAX
|
||||||
LIBS += c:\prog\lib\libpq.lib User32.lib ws2_32.lib
|
LIBS += c:\prog\lib\libpq.lib c:\prog\lib\fmt.lib User32.lib ws2_32.lib
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
|
|
@ -45,11 +45,11 @@ SOURCES += main.cpp\
|
||||||
pgnamespace.cpp \
|
pgnamespace.cpp \
|
||||||
pgclass.cpp \
|
pgclass.cpp \
|
||||||
backupdialog.cpp \
|
backupdialog.cpp \
|
||||||
paramlistmodel.cpp \
|
|
||||||
paramtypedelegate.cpp \
|
|
||||||
typeselectionitemmodel.cpp \
|
typeselectionitemmodel.cpp \
|
||||||
opendatabase.cpp \
|
MasterController.cpp \
|
||||||
MasterController.cpp
|
ParamTypeDelegate.cpp \
|
||||||
|
OpenDatabase.cpp \
|
||||||
|
ParamListModel.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
sqlparser.h \
|
sqlparser.h \
|
||||||
|
|
@ -80,11 +80,11 @@ HEADERS += mainwindow.h \
|
||||||
pgnamespace.h \
|
pgnamespace.h \
|
||||||
pgclass.h \
|
pgclass.h \
|
||||||
backupdialog.h \
|
backupdialog.h \
|
||||||
paramlistmodel.h \
|
|
||||||
paramtypedelegate.h \
|
|
||||||
typeselectionitemmodel.h \
|
typeselectionitemmodel.h \
|
||||||
opendatabase.h \
|
MasterController.h \
|
||||||
MasterController.h
|
ParamTypeDelegate.h \
|
||||||
|
OpenDatabase.h \
|
||||||
|
ParamListModel.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
databasewindow.ui \
|
databasewindow.ui \
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
PgsqlDatabaseCatalogue::PgsqlDatabaseCatalogue()
|
PgsqlDatabaseCatalogue::PgsqlDatabaseCatalogue()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PgsqlDatabaseCatalogue::~PgsqlDatabaseCatalogue()
|
PgsqlDatabaseCatalogue::~PgsqlDatabaseCatalogue()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
const PgTypeContainer* getTypes() const { return m_types; }
|
const PgTypeContainer* getTypes() const { return m_types; }
|
||||||
private:
|
private:
|
||||||
PgTypeContainer *m_types;
|
PgTypeContainer *m_types = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGSQLDATABASECATALOGUE_H
|
#endif // PGSQLDATABASECATALOGUE_H
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ const PgType& PgTypeContainer::getTypeByName(const QString &name) const
|
||||||
return m_invalidType;
|
return m_invalidType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PgType& PgTypeContainer::getTypeByIdx(int idx) const
|
||||||
|
{
|
||||||
|
return m_types.at(idx);
|
||||||
|
}
|
||||||
|
|
||||||
std::string PgTypeContainer::getLoadQuery()
|
std::string PgTypeContainer::getLoadQuery()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ public:
|
||||||
t_Types::const_iterator end() const { return m_types.end(); }
|
t_Types::const_iterator end() const { return m_types.end(); }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
int count() const { return (int)m_types.size(); }
|
||||||
std::string getLoadQuery();
|
std::string getLoadQuery();
|
||||||
void load(const Pgsql::Result &res);
|
void load(const Pgsql::Result &res);
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ public:
|
||||||
*/
|
*/
|
||||||
const PgType& getTypeByOid(Oid oid) const;
|
const PgType& getTypeByOid(Oid oid) const;
|
||||||
const PgType& getTypeByName(const QString &name) const;
|
const PgType& getTypeByName(const QString &name) const;
|
||||||
|
const PgType& getTypeByIdx(int idx) const;
|
||||||
private:
|
private:
|
||||||
PgType m_invalidType; ///< default constructed object for when a non existent type is being retrieved.
|
PgType m_invalidType; ///< default constructed object for when a non existent type is being retrieved.
|
||||||
t_Types m_types; // Keep sorted by Oid
|
t_Types m_types; // Keep sorted by Oid
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include "explaintreemodelitem.h"
|
#include "explaintreemodelitem.h"
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "OpenDatabase.h"
|
||||||
#include "pgtypecontainer.h"
|
#include "pgtypecontainer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
@ -40,6 +41,9 @@ QueryTab::QueryTab(MainWindow *win, QWidget *parent) :
|
||||||
ui->queryEdit->setFont(font);
|
ui->queryEdit->setFont(font);
|
||||||
highlighter.reset(new SqlHighlighter(ui->queryEdit->document()));
|
highlighter.reset(new SqlHighlighter(ui->queryEdit->document()));
|
||||||
|
|
||||||
|
OpenDatabase* open_database = m_win->getDatabase();
|
||||||
|
m_typeDelegate.setTypeSelectionModel(open_database->getTypeSelectionModel());
|
||||||
|
|
||||||
ui->paramTableView->setModel(&m_paramList);
|
ui->paramTableView->setModel(&m_paramList);
|
||||||
ui->paramTableView->setItemDelegateForColumn(1, &m_typeDelegate);
|
ui->paramTableView->setItemDelegateForColumn(1, &m_typeDelegate);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
#define QUERYTAB_H
|
#define QUERYTAB_H
|
||||||
|
|
||||||
#include "asyncdbconnection.h"
|
#include "asyncdbconnection.h"
|
||||||
#include "paramlistmodel.h"
|
#include "ParamListModel.h"
|
||||||
#include "paramtypedelegate.h"
|
#include "ParamTypeDelegate.h"
|
||||||
#include "queryresultmodel.h"
|
#include "queryresultmodel.h"
|
||||||
#include "queryexplainmodel.h"
|
#include "queryexplainmodel.h"
|
||||||
#include "stopwatch.h"
|
#include "stopwatch.h"
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,6 @@
|
||||||
<file>icons/16x16/document_red.png</file>
|
<file>icons/16x16/document_red.png</file>
|
||||||
<file>icons/16x16/document_yellow.png</file>
|
<file>icons/16x16/document_yellow.png</file>
|
||||||
<file>icons/backups.png</file>
|
<file>icons/backups.png</file>
|
||||||
|
<file>icons/page_white_copy.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "typeselectionitemmodel.h"
|
#include "typeselectionitemmodel.h"
|
||||||
|
#include "PgTypeContainer.h"
|
||||||
|
|
||||||
TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent)
|
TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
|
|
@ -7,7 +8,7 @@ TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent)
|
||||||
|
|
||||||
int TypeSelectionItemModel::rowCount(const QModelIndex &parent) const
|
int TypeSelectionItemModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
int result = 10;
|
int result = m_types->count();
|
||||||
// if (!parent.isValid()) {
|
// if (!parent.isValid()) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
@ -32,21 +33,32 @@ QVariant TypeSelectionItemModel::data(const QModelIndex &index, int role) const
|
||||||
int column = index.column();
|
int column = index.column();
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
if (column == 0) {
|
if (column == 0) {
|
||||||
switch (row) {
|
const PgType &tp = m_types->getTypeByIdx(row);
|
||||||
case 0: result = "integer"; break;
|
result = tp.typname;
|
||||||
case 1: result = "numeric"; break;
|
|
||||||
case 2: result = "timestamp"; break;
|
|
||||||
case 3: result = "timestamptz"; break;
|
|
||||||
case 4: result = "float"; break;
|
|
||||||
case 5: result = "double"; break;
|
|
||||||
case 6: result = "date"; break;
|
|
||||||
case 7: result = "varchar"; break;
|
|
||||||
case 8: result = "varchar"; break;
|
|
||||||
case 9: result = "varchar"; break;
|
|
||||||
|
|
||||||
}
|
// switch (row) {
|
||||||
|
// case 0: result = "integer"; break;
|
||||||
|
// case 1: result = "numeric"; break;
|
||||||
|
// case 2: result = "timestamp"; break;
|
||||||
|
// case 3: result = "timestamptz"; break;
|
||||||
|
// case 4: result = "float"; break;
|
||||||
|
// case 5: result = "double"; break;
|
||||||
|
// case 6: result = "date"; break;
|
||||||
|
// case 7: result = "varchar"; break;
|
||||||
|
// case 8: result = "varchar"; break;
|
||||||
|
// case 9: result = "varchar"; break;
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TypeSelectionItemModel::setTypeList(const PgTypeContainer* types)
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_types = types;
|
||||||
|
//emit dataChanged(this->createIndex(0, 0), this->createIndex(types->count(), 0), QVector<int>() << Qt::DisplayRole);
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
class PgTypeContainer;
|
||||||
|
|
||||||
class TypeSelectionItemModel : public QAbstractListModel
|
class TypeSelectionItemModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -10,12 +12,14 @@ class TypeSelectionItemModel : public QAbstractListModel
|
||||||
public:
|
public:
|
||||||
explicit TypeSelectionItemModel(QObject *parent = 0);
|
explicit TypeSelectionItemModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
void setTypeList(const PgTypeContainer* types);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const PgTypeContainer* m_types;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TYPESELECTIONITEMMODEL_H
|
#endif // TYPESELECTIONITEMMODEL_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue