Files
DbLogAnalyzer/wizard/tablespage.cpp

79 lines
1.8 KiB
C++
Raw Permalink Normal View History

2019-04-01 10:43:36 +02:00
#include "tablespage.h"
2019-04-07 18:20:01 +02:00
#include "ui_tablespage.h"
2019-04-01 10:43:36 +02:00
#include "importwizard.h"
#include "threads/tablecreatorthread.h"
TablesPage::TablesPage(QWidget *parent) :
2019-04-07 18:20:01 +02:00
QWizardPage(parent),
m_ui(std::make_unique<Ui::TablesPage>()),
m_model(this)
2019-04-01 10:43:36 +02:00
{
2019-04-07 18:20:01 +02:00
m_ui->setupUi(this);
2019-04-01 10:43:36 +02:00
2019-04-07 18:20:01 +02:00
m_ui->listView->setModel(&m_model);
2019-04-01 10:43:36 +02:00
}
TablesPage::~TablesPage() = default;
int TablesPage::nextId() const
{
return int(ImportWizard::Pages::ImportType);
}
void TablesPage::initializePage()
{
auto importWizard = qobject_cast<ImportWizard*>(wizard());
Q_ASSERT(importWizard);
Q_ASSERT(importWizard->database().isOpen());
2019-04-07 18:20:01 +02:00
QVector<ProgressModel::Item> items;
items.reserve(TableCreatorThread::tables().size());
for (const QString &tableName : TableCreatorThread::tables())
items.append({ tr("Create table %0").arg(tableName), ProgressModel::Item::Status::None });
items.first().status = ProgressModel::Item::Status::Loading;
m_model.setItems(items);
2019-04-01 10:43:36 +02:00
m_thread = std::make_unique<TableCreatorThread>(importWizard->database(), this);
connect(m_thread.get(), &TableCreatorThread::someSignal, this, &TablesPage::someSlot);
m_thread->start();
}
void TablesPage::cleanupPage()
{
2019-04-07 18:20:01 +02:00
stopThread();
m_model.clearItems();
2019-04-01 10:43:36 +02:00
}
bool TablesPage::isComplete() const
{
return m_thread == nullptr;
}
void TablesPage::someSlot(int index)
{
2019-04-07 18:20:01 +02:00
Q_ASSERT(index < m_model.rowCount({}));
2019-04-01 10:43:36 +02:00
2019-04-07 18:20:01 +02:00
m_model.setStatus(index, ProgressModel::Item::Status::Succeeded);
if (index < m_model.rowCount({}) - 1)
m_model.setStatus(index + 1, ProgressModel::Item::Status::Loading);
2019-04-01 10:43:36 +02:00
else
{
2019-04-07 18:20:01 +02:00
stopThread();
2019-04-01 10:43:36 +02:00
emit completeChanged();
}
}
2019-04-07 18:20:01 +02:00
void TablesPage::stopThread()
{
if (m_thread)
{
m_thread->requestInterruption();
m_thread->wait();
m_thread = nullptr;
}
}