summaryrefslogtreecommitdiff
path: root/rockwork/screenshotmodel.cpp
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2016-02-11 23:55:16 +0100
committerAndrew Branson <andrew.branson@cern.ch>2016-02-11 23:55:16 +0100
commit29aaea2d80a9eb1715b6cddfac2d2aacf76358bd (patch)
tree012795b6bec16c72f38d33cff46324c9a0225868 /rockwork/screenshotmodel.cpp
launchpad ~mzanetti/rockwork/trunk r87
Diffstat (limited to 'rockwork/screenshotmodel.cpp')
-rw-r--r--rockwork/screenshotmodel.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/rockwork/screenshotmodel.cpp b/rockwork/screenshotmodel.cpp
new file mode 100644
index 0000000..e943aa6
--- /dev/null
+++ b/rockwork/screenshotmodel.cpp
@@ -0,0 +1,71 @@
+#include "screenshotmodel.h"
+
+#include <QDebug>
+
+ScreenshotModel::ScreenshotModel(QObject *parent):
+ QAbstractListModel(parent)
+{
+}
+
+int ScreenshotModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)
+ return m_files.count();
+}
+
+QVariant ScreenshotModel::data(const QModelIndex &index, int role) const
+{
+ switch (role) {
+ case RoleFileName:
+ return m_files.at(index.row());
+ }
+ return QVariant();
+}
+
+QHash<int, QByteArray> ScreenshotModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles.insert(RoleFileName, "filename");
+ return roles;
+}
+
+QString ScreenshotModel::get(int index) const
+{
+ if (index >= 0 && index < m_files.count()) {
+ return m_files.at(index);
+ }
+ return QString();
+}
+
+QString ScreenshotModel::latestScreenshot() const
+{
+ return get(0);
+}
+
+void ScreenshotModel::clear()
+{
+ beginResetModel();
+ m_files.clear();
+ endResetModel();
+}
+
+void ScreenshotModel::insert(const QString &filename)
+{
+ qDebug() << "should insert filename" << filename;
+ if (!m_files.contains(filename)) {
+ beginInsertRows(QModelIndex(), 0, 0);
+ m_files.prepend(filename);
+ endInsertRows();
+ emit latestScreenshotChanged();
+ }
+}
+
+void ScreenshotModel::remove(const QString &filename)
+{
+ if (m_files.contains(filename)) {
+ int idx = m_files.indexOf(filename);
+ beginRemoveRows(QModelIndex(), idx, idx);
+ m_files.removeOne(filename);
+ endRemoveRows();
+ }
+}