Moving things from the application specific DatabaseWindow to generic LMainWindow (Leon framework)
To achieve flexibility the getDatabase call on the context which was application specific to has been replaced with a type based object registry.
This commit is contained in:
parent
4a78330153
commit
fd603a7434
5 changed files with 137 additions and 99 deletions
|
|
@ -47,10 +47,10 @@ namespace DatabaseWindow_details {
|
|||
m_window->setTabIcon(content, iconname);
|
||||
}
|
||||
|
||||
std::shared_ptr<OpenDatabase> getDatabase() override
|
||||
{
|
||||
return m_window->getDatabase();
|
||||
}
|
||||
// std::shared_ptr<OpenDatabase> getDatabase() override
|
||||
// {
|
||||
// return m_window->getDatabase();
|
||||
// }
|
||||
|
||||
void showStatusMessage(const QString &msg) override
|
||||
{
|
||||
|
|
@ -72,9 +72,30 @@ using namespace DatabaseWindow_details;
|
|||
LMainWindow::LMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
m_tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
|
||||
m_tabWidget->setDocumentMode(true);
|
||||
|
||||
setCentralWidget(m_tabWidget);
|
||||
|
||||
// menu
|
||||
auto menuBar = new QMenuBar(this);
|
||||
setMenuBar(menuBar);
|
||||
|
||||
// tooolbar
|
||||
m_mainToolBar = new QToolBar(this);
|
||||
addToolBar(Qt::TopToolBarArea, m_mainToolBar);
|
||||
|
||||
// statusbar
|
||||
auto statusBar = new QStatusBar(this);
|
||||
setStatusBar(statusBar);
|
||||
|
||||
m_fileMenu = new QMenu("File T", this);
|
||||
|
||||
createActions();
|
||||
m_mainToolBar->addAction(m_closeAction);
|
||||
|
||||
// QMetaObject::connectSlotsByName(this);
|
||||
}
|
||||
|
||||
void LMainWindow::initModuleMenus()
|
||||
|
|
@ -95,6 +116,19 @@ void LMainWindow::addModuleMenuActions()
|
|||
}
|
||||
}
|
||||
|
||||
void LMainWindow::createActions()
|
||||
{
|
||||
{
|
||||
auto action = m_closeAction = new QAction(this);
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
action->setIcon(icon);
|
||||
connect(m_closeAction, &QAction::triggered, this, &DatabaseWindow::actionClose_triggered);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LMainWindow::addMenuAction(const MenuAction &ma)
|
||||
{
|
||||
qDebug() << "add action " << ma.text();
|
||||
|
|
@ -109,69 +143,56 @@ void LMainWindow::addMenuAction(const MenuAction &ma)
|
|||
|
||||
// auto ac = new QAction(this);
|
||||
// ac->
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LMainWindow::actionClose_triggered()
|
||||
{
|
||||
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
void LMainWindow::addPage(PluginContentWidget* page, QString caption)
|
||||
{
|
||||
m_tabWidget->addTab(page, caption);
|
||||
m_tabWidget->setCurrentWidget(page);
|
||||
}
|
||||
|
||||
void LMainWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
m_tabWidget->setTabText(index, caption);
|
||||
m_tabWidget->setTabToolTip(index, hint);
|
||||
}
|
||||
|
||||
void LMainWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
auto n = ":/icons/16x16/" + iconname;
|
||||
m_tabWidget->setTabIcon(index, QIcon(n));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||
: LMainWindow(parent)
|
||||
// , ui(new Ui::DatabaseWindow)
|
||||
|
||||
, m_masterController(master)
|
||||
{
|
||||
// ui->setupUi(this);
|
||||
// ui->tabWidget->setDocumentMode(true);
|
||||
|
||||
// auto centralWidget = new QWidget(this);
|
||||
// auto verticalLayout_3 = new QVBoxLayout(centralWidget);
|
||||
// verticalLayout_3->setSpacing(4);
|
||||
// verticalLayout_3->setContentsMargins(4, 4, 4, 4);
|
||||
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
m_tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
|
||||
m_tabWidget->setDocumentMode(true);
|
||||
// verticalLayout_3->addWidget(m_tabWidget);
|
||||
|
||||
setCentralWidget(m_tabWidget);
|
||||
|
||||
createActions();
|
||||
|
||||
auto menuBar = new QMenuBar(this);
|
||||
setMenuBar(menuBar);
|
||||
|
||||
m_mainToolBar = new QToolBar(this);
|
||||
m_mainToolBar->addAction(m_closeAction);
|
||||
addToolBar(Qt::TopToolBarArea, m_mainToolBar);
|
||||
|
||||
auto statusBar = new QStatusBar(this);
|
||||
setStatusBar(statusBar);
|
||||
|
||||
m_context = new DatabaseWindowContentContext(this);
|
||||
|
||||
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
||||
this, &DatabaseWindow::catalogLoaded);
|
||||
|
||||
initModuleMenus();
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
}
|
||||
|
||||
DatabaseWindow::~DatabaseWindow()
|
||||
{
|
||||
delete m_context;
|
||||
// delete ui;
|
||||
}
|
||||
|
||||
void DatabaseWindow::createActions()
|
||||
{
|
||||
{
|
||||
auto action = m_closeAction = new QAction(this);
|
||||
QIcon icon;
|
||||
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
action->setIcon(icon);
|
||||
connect(m_closeAction, &QAction::triggered, this, &DatabaseWindow::actionClose_triggered);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QueryTab* DatabaseWindow::newSqlPage()
|
||||
{
|
||||
|
|
@ -226,6 +247,7 @@ void DatabaseWindow::catalogLoaded()
|
|||
try {
|
||||
//SCOPE_EXIT { loadFuture = {}; };
|
||||
m_database = loadWatcher.future().result();
|
||||
m_context->registerObject(m_database);
|
||||
|
||||
auto tt = new TablesPage(m_context, this);
|
||||
tt->setCatalog(m_database->catalog());
|
||||
|
|
@ -308,11 +330,6 @@ void DatabaseWindow::on_actionExport_data_triggered()
|
|||
}
|
||||
}
|
||||
|
||||
void DatabaseWindow::actionClose_triggered()
|
||||
{
|
||||
on_tabWidget_tabCloseRequested(m_tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionAbout_triggered()
|
||||
{
|
||||
QMessageBox::about(this, "pgLab 0.1", tr(
|
||||
|
|
@ -468,15 +485,6 @@ void DatabaseWindow::removeToolBarButtonsForPage(PluginContentWidget *page)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void DatabaseWindow::addPage(PluginContentWidget* page, QString caption)
|
||||
{
|
||||
m_tabWidget->addTab(page, caption);
|
||||
m_tabWidget->setCurrentWidget(page);
|
||||
|
||||
//addToolBarButtonsForPage(page);
|
||||
}
|
||||
|
||||
void DatabaseWindow::removePage(PluginContentWidget *)
|
||||
{
|
||||
|
||||
|
|
@ -509,17 +517,3 @@ void DatabaseWindow::on_actionGenerate_code_triggered()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
m_tabWidget->setTabText(index, caption);
|
||||
m_tabWidget->setTabToolTip(index, hint);
|
||||
}
|
||||
|
||||
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
||||
{
|
||||
auto index = m_tabWidget->indexOf(widget);
|
||||
auto n = ":/icons/16x16/" + iconname;
|
||||
m_tabWidget->setTabIcon(index, QIcon(n));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue