summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
commit7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch)
treea35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp b/SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp
new file mode 100644
index 0000000..9df3f81
--- /dev/null
+++ b/SQLiteStudio3/coreSQLiteStudio/ddlhistorymodel.cpp
@@ -0,0 +1,76 @@
+#include "ddlhistorymodel.h"
+#include "querymodel.h"
+#include <QSet>
+#include <QDebug>
+
+DdlHistoryModel::DdlHistoryModel(Db* db, QObject *parent) :
+ QSortFilterProxyModel(parent)
+{
+ static const QString query =
+ "SELECT dbname,"
+ " file,"
+ " date(timestamp, 'unixepoch') AS date,"
+ " count(*)"
+ " FROM ddl_history"
+ " GROUP BY dbname, file, date"
+ " ORDER BY date DESC";
+
+ internalModel = new QueryModel(db, this);
+ setSourceModel(internalModel);
+ connect(internalModel, SIGNAL(refreshed()), this, SIGNAL(refreshed()));
+
+ setFilterKeyColumn(0);
+ setDynamicSortFilter(true);
+
+ internalModel->setQuery(query);
+}
+
+QVariant DdlHistoryModel::data(const QModelIndex& index, int role) const
+{
+ if (role == Qt::TextAlignmentRole && (index.column() == 2 || index.column() == 3))
+ return (int)(Qt::AlignRight|Qt::AlignVCenter);
+
+ return QSortFilterProxyModel::data(index, role);
+}
+
+void DdlHistoryModel::refresh()
+{
+ internalModel->refresh();
+
+}
+
+void DdlHistoryModel::setDbNameForFilter(const QString& value)
+{
+ setFilterWildcard("*"+value+"*");
+}
+
+QStringList DdlHistoryModel::getDbNames() const
+{
+ QSet<QString> dbNames;
+ for (int row = 0; row < rowCount(); row++)
+ dbNames << data(index(row, 0)).toString();
+
+ QStringList nameList = dbNames.toList();
+ qSort(nameList);
+ return nameList;
+}
+
+QVariant DdlHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
+ {
+ switch (section)
+ {
+ case 0:
+ return tr("Database name", "ddl history header");
+ case 1:
+ return tr("Database file", "ddl history header");
+ case 2:
+ return tr("Date of execution", "ddl history header");
+ case 3:
+ return tr("Changes", "ddl history header");
+ }
+ return QVariant();
+ }
+ return QSortFilterProxyModel::headerData(section, orientation, role);
+}