1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#include "ddlhistorywindow.h"
#include "ui_ddlhistorywindow.h"
#include "services/config.h"
#include "ddlhistorymodel.h"
#include "common/unused.h"
#include "iconmanager.h"
#include <QDate>
#include <QLineEdit>
#include <QMessageBox>
#include <QStringListModel>
DdlHistoryWindow::DdlHistoryWindow(QWidget *parent) :
MdiChild(parent),
ui(new Ui::DdlHistoryWindow)
{
init();
}
DdlHistoryWindow::~DdlHistoryWindow()
{
delete ui;
}
void DdlHistoryWindow::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void DdlHistoryWindow::init()
{
ui->setupUi(this);
dataModel = CFG->getDdlHistoryModel();
dbListModel = new QStringListModel(this);
QStringList dbList = dataModel->getDbNames();
dbList.prepend("");
dbListModel->setStringList(dbList);
ui->comboBox->setModel(dbListModel);
ui->comboBox->setCurrentIndex(-1);
connect(ui->comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(applyFilter(QString)));
connect(dataModel, SIGNAL(refreshed()), this, SLOT(refreshDbList()));
ui->tableView->setModel(dataModel);
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
connect(ui->tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(activated(QModelIndex,QModelIndex)));
connect(ui->clearButton, SIGNAL(clicked(bool)), this, SLOT(clearHistory()));
}
void DdlHistoryWindow::activated(const QModelIndex& current, const QModelIndex& previous)
{
UNUSED(previous);
int row = current.row();
QString dbName = dataModel->data(dataModel->index(row, 0)).toString();
QString dbFile = dataModel->data(dataModel->index(row, 1)).toString();
QString dateString = dataModel->data(dataModel->index(row, 2)).toString();
QDate date = QDate::fromString(dateString, "yyyy-MM-dd");
static const QString templ = tr("-- Queries executed on database %1 (%2)\n"
"-- Date and time of execution: %3\n"
"%4");
QStringList contentEntries;
QList<Config::DdlHistoryEntryPtr> entries = CFG->getDdlHistoryFor(dbName, dbFile, date);
for (Config::DdlHistoryEntryPtr& entry : entries)
contentEntries << templ.arg(entry->dbName, entry->dbFile, entry->timestamp.toString("yyyy-MM-dd HH:mm:ss"), entry->queries);
ui->ddlEdit->setPlainText(contentEntries.join("\n\n"));
}
void DdlHistoryWindow::applyFilter(const QString& filterValue)
{
dataModel->setDbNameForFilter(filterValue);
}
void DdlHistoryWindow::refreshDbList()
{
QStringList dbList = dataModel->getDbNames();
dbList.prepend("");
dbListModel->setStringList(dbList);
}
void DdlHistoryWindow::clearHistory()
{
QMessageBox::StandardButton result = QMessageBox::question(this, tr("Clear history"), tr("Are you sure you want to erase entire DDL history?"));
if (result != QMessageBox::Yes)
return;
CFG->clearDdlHistory();
dataModel->refresh();
ui->ddlEdit->setPlainText("");
}
bool DdlHistoryWindow::restoreSessionNextTime()
{
return false;
}
QVariant DdlHistoryWindow::saveSession()
{
return QVariant();
}
bool DdlHistoryWindow::restoreSession(const QVariant& sessionValue)
{
UNUSED(sessionValue);
return true;
}
Icon* DdlHistoryWindow::getIconNameForMdiWindow()
{
return ICONS.DDL_HISTORY;
}
QString DdlHistoryWindow::getTitleForMdiWindow()
{
return tr("DDL history");
}
void DdlHistoryWindow::createActions()
{
}
void DdlHistoryWindow::setupDefShortcuts()
{
}
QToolBar* DdlHistoryWindow::getToolBar(int toolbar) const
{
UNUSED(toolbar);
return nullptr;
}
bool DdlHistoryWindow::isUncommitted() const
{
return false;
}
QString DdlHistoryWindow::getQuitUncommittedConfirmMessage() const
{
return QString();
}
|