Tab with list of sequences and create sql for selected sequence.
This commit is contained in:
parent
769307c821
commit
437736a023
19 changed files with 507 additions and 63 deletions
|
|
@ -43,11 +43,9 @@ FunctionsPage::FunctionsPage(QWidget *parent)
|
|||
auto item_delegate = new PgLabItemDelegate(this);
|
||||
m_functionTable->setItemDelegate(item_delegate);
|
||||
|
||||
|
||||
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&FunctionsPage::functionTable_currentRowChanged);
|
||||
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +80,6 @@ void FunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t,
|
|||
|
||||
void FunctionsPage::selectedProcChanged(const std::optional<PgProc> &proc)
|
||||
{
|
||||
|
||||
updateSqlTab(proc);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "ui_MainWindow.h"
|
||||
#include "TablesPage.h"
|
||||
#include "FunctionsPage.h"
|
||||
#include "SequencesPage.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
#include <QFileDialog>
|
||||
|
|
@ -112,6 +113,10 @@ void MainWindow::catalogLoaded()
|
|||
functions_page->setCatalog(m_database->catalog());
|
||||
ui->tabWidget->addTab(functions_page, "Functions");
|
||||
|
||||
auto sequences_page = new SequencesPage(this);
|
||||
sequences_page->setCatalog(m_database->catalog());
|
||||
ui->tabWidget->addTab(sequences_page, "Sequences");
|
||||
|
||||
newSqlPage();
|
||||
newCreateTablePage();
|
||||
} catch (std::runtime_error &ex) {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
void newCrudPage(const PgClass &table);
|
||||
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
||||
|
||||
private:
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ public:
|
|||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
PgProc proc(int row) const;
|
||||
|
||||
|
|
|
|||
82
pglab/SequenceModel.cpp
Normal file
82
pglab/SequenceModel.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#include "SequenceModel.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "catalog/PgSequenceContainer.h"
|
||||
|
||||
SequenceModel::SequenceModel(QObject * parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{}
|
||||
|
||||
QVariant SequenceModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case NameCol: return tr("Name");
|
||||
case SchemaCol: return tr("Schema");
|
||||
case OwnerCol: return tr("Owner");
|
||||
case LastCol: return tr("Last");
|
||||
case StartCol: return tr("Start");
|
||||
case MinCol: return tr("Min");
|
||||
case MaxCol: return tr("Max");
|
||||
case IncrementCol: return tr("Inc");
|
||||
case CacheCol: return tr("Cached");
|
||||
case CycledCol: return tr("Cycled");
|
||||
case CalledCol: return tr("Called");
|
||||
case AclCol: return tr("ACL");
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void SequenceModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
m_catalog = cat;
|
||||
m_sequences = cat->sequences();
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
PgSequence SequenceModel::sequence(int row) const
|
||||
{
|
||||
return m_sequences->getByIdx(row);
|
||||
}
|
||||
|
||||
int SequenceModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_sequences ? static_cast<int>(m_sequences->count()) : 0;
|
||||
}
|
||||
|
||||
int SequenceModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return colCount;
|
||||
}
|
||||
|
||||
QVariant SequenceModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_sequences)
|
||||
return {};
|
||||
|
||||
int row = index.row();
|
||||
auto && seq = m_sequences->getByIdx(row);
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (index.column()) {
|
||||
case NameCol: return seq.objectName();
|
||||
case SchemaCol: return seq.nsName();
|
||||
case OwnerCol: return seq.ownerName();
|
||||
case LastCol: return seq.last;
|
||||
case StartCol: return seq.start;
|
||||
case MinCol: return seq.min;
|
||||
case MaxCol: return seq.max;
|
||||
case IncrementCol: return seq.increment;
|
||||
case CacheCol: return seq.cache;
|
||||
case CycledCol: return seq.cycled;
|
||||
case CalledCol: return seq.called;
|
||||
case AclCol: return seq.aclString();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
48
pglab/SequenceModel.h
Normal file
48
pglab/SequenceModel.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef SEQUENCEMODEL_H
|
||||
#define SEQUENCEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
//#include "catalog/PgClass.h"
|
||||
#include "catalog/PgSequence.h"
|
||||
#include <memory>
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
class PgSequenceContainer;
|
||||
|
||||
class SequenceModel: public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
enum e_Columns : int {
|
||||
NameCol,
|
||||
SchemaCol,
|
||||
OwnerCol,
|
||||
LastCol,
|
||||
StartCol,
|
||||
MinCol,
|
||||
MaxCol,
|
||||
IncrementCol,
|
||||
CacheCol,
|
||||
CycledCol,
|
||||
CalledCol,
|
||||
AclCol,
|
||||
|
||||
colCount
|
||||
};
|
||||
|
||||
SequenceModel(QObject * parent = nullptr);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
PgSequence sequence(int row) const;
|
||||
private:
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::shared_ptr<const PgSequenceContainer> m_sequences;
|
||||
};
|
||||
|
||||
#endif // SEQUENCEMODEL_H
|
||||
81
pglab/SequencesPage.cpp
Normal file
81
pglab/SequencesPage.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "SequencesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "SequenceModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QTableView>
|
||||
|
||||
SequencesPage::SequencesPage(QWidget *parent)
|
||||
{
|
||||
m_sequenceTable = new QTableView(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
|
||||
// build widget tree
|
||||
// add top level widgets to splitter
|
||||
addWidget(m_sequenceTable);
|
||||
addWidget(m_definitionView);
|
||||
|
||||
SetTableViewDefault(m_sequenceTable);
|
||||
|
||||
m_model = new SequenceModel(this);
|
||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
m_sequenceTable->setModel(m_sortFilterProxy);
|
||||
m_sequenceTable->setSortingEnabled(true);
|
||||
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
auto item_delegate = new PgLabItemDelegate(this);
|
||||
m_sequenceTable->setItemDelegate(item_delegate);
|
||||
|
||||
connect(m_sequenceTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&SequencesPage::sequenceTable_currentRowChanged);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void SequencesPage::retranslateUi()
|
||||
{
|
||||
// auto set_tabtext = [this] (QWidget *widget, QString translation) {
|
||||
// m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation);
|
||||
// };
|
||||
|
||||
// set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr));
|
||||
}
|
||||
|
||||
void SequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
}
|
||||
|
||||
void SequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
if (current.isValid()) {
|
||||
auto source_index = m_sortFilterProxy->mapToSource(current);
|
||||
auto proc = m_model->sequence(source_index.row());
|
||||
|
||||
selectedSequenceChanged(proc);
|
||||
}
|
||||
else
|
||||
selectedSequenceChanged({});
|
||||
}
|
||||
}
|
||||
|
||||
void SequencesPage::selectedSequenceChanged(const std::optional<PgSequence> &seq)
|
||||
{
|
||||
updateSqlTab(seq);
|
||||
}
|
||||
|
||||
void SequencesPage::updateSqlTab(const std::optional<PgSequence> &seq)
|
||||
{
|
||||
if (!seq.has_value()) {
|
||||
m_definitionView->clear();
|
||||
return;
|
||||
}
|
||||
QString create_sql = seq->createSql();
|
||||
|
||||
m_definitionView->setPlainText(create_sql);
|
||||
}
|
||||
40
pglab/SequencesPage.h
Normal file
40
pglab/SequencesPage.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef SEQUENCESPAGES_H
|
||||
#define SEQUENCESPAGES_H
|
||||
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
class QTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class SequenceModel;
|
||||
class CustomFilterSortModel;
|
||||
//class QTabWidget;
|
||||
class SqlCodePreview;
|
||||
class PgSequence;
|
||||
|
||||
|
||||
class SequencesPage : public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequencesPage(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
public slots:
|
||||
|
||||
void sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
private:
|
||||
QTableView *m_sequenceTable = nullptr;
|
||||
//QTabWidget *m_detailTabs = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
SequenceModel *m_model = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi();
|
||||
void selectedSequenceChanged(const std::optional<PgSequence> &seq);
|
||||
void updateSqlTab(const std::optional<PgSequence> &seq);
|
||||
};
|
||||
|
||||
#endif // SEQUENCESPAGES_H
|
||||
|
|
@ -81,7 +81,9 @@ PropertyProxyModel.cpp \
|
|||
FunctionsPage.cpp \
|
||||
ColumnPage.cpp \
|
||||
EditTableWidget.cpp \
|
||||
EditColumnTableModel.cpp
|
||||
EditColumnTableModel.cpp \
|
||||
SequenceModel.cpp \
|
||||
SequencesPage.cpp
|
||||
|
||||
HEADERS += \
|
||||
QueryResultModel.h \
|
||||
|
|
@ -140,7 +142,9 @@ CustomDataRole.h \
|
|||
FunctionsPage.h \
|
||||
ColumnPage.h \
|
||||
EditTableWidget.h \
|
||||
EditColumnTableModel.h
|
||||
EditColumnTableModel.h \
|
||||
SequenceModel.h \
|
||||
SequencesPage.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
ConnectionManagerWindow.ui \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue