aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/sqlhistorymodel.cpp
blob: 201dc8b56e00687ebde1a66d73aaca4e59797c11 (plain) (blame)
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
#include "sqlhistorymodel.h"
#include "common/global.h"
#include "db/db.h"

SqlHistoryModel::SqlHistoryModel(Db* db, QObject *parent) :
    QueryModel(db, parent)
{
    static_char* query = "SELECT dbname, datetime(date, 'unixepoch'), (time_spent / 1000.0)||'s', rows, sql "
                         "FROM sqleditor_history ORDER BY date DESC";

    setQuery(query);
}

QVariant SqlHistoryModel::data(const QModelIndex& index, int role) const
{
    if (role == Qt::TextAlignmentRole && (index.column() == 2 || index.column() == 3))
        return (int)(Qt::AlignRight|Qt::AlignVCenter);

    return QueryModel::data(index, role);
}

QVariant SqlHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
        return QueryModel::headerData(section, orientation, role);

    switch (section)
    {
        case 0:
            return tr("Database", "sql history header");
        case 1:
            return tr("Execution date", "sql history header");
        case 2:
            return tr("Time spent", "sql history header");
        case 3:
            return tr("Rows affected", "sql history header");
        case 4:
            return tr("SQL", "sql history header");
    }

    return QueryModel::headerData(section, orientation, role);
}