Moved many components into shared libraries of DbSoftware

This commit is contained in:
feedc0de committed 2019-04-20 11:39:37 +02:00
1 parent 2d50405fa4
commit a20580ebeb
17 files changed
+91 -1090

No files matched your search

-182
View File
@@ -1,182 +0,0 @@
#include "checklistmodel.h"
ChecklistModel::ChecklistModel(QObject *parent) :
QAbstractListModel(parent)
{
}
ChecklistModel::ChecklistModel(const QStringList &items, QObject *parent) :
QAbstractListModel(parent)
{
for (const auto &item : items)
m_items.append({ item, item, true });
}
ChecklistModel::ChecklistModel(const QList<ChecklistItem> &items, QObject *parent) :
QAbstractListModel(parent),
m_items(items)
{
}
const QList<ChecklistModel::ChecklistItem> &ChecklistModel::items() const
{
return m_items;
}
void ChecklistModel::setItems(const QList<ChecklistItem> &items)
{
emit beginResetModel();
m_items = items;
emit endResetModel();
}
void ChecklistModel::setItems(const QStringList &items)
{
emit beginResetModel();
m_items.clear();
for (const auto &item : items)
m_items.append({ item, item, true });
emit endResetModel();
}
QStringList ChecklistModel::itemTexts() const
{
QStringList items;
for (const auto &item : m_items)
items.append(item.displayText);
return items;
}
QVariantList ChecklistModel::itemDatas() const
{
QVariantList items;
for (const auto &item : m_items)
items.append(item.data);
return items;
}
QList<ChecklistModel::ChecklistItem> ChecklistModel::enabledItems() const
{
QList<ChecklistModel::ChecklistItem> items;
for (const auto &item : m_items)
if (item.checked)
items.append(item);
return items;
}
QList<ChecklistModel::ChecklistItem> ChecklistModel::disabledItems() const
{
QList<ChecklistModel::ChecklistItem> items;
for (const auto &item : m_items)
if (!item.checked)
items.append(item);
return items;
}
QStringList ChecklistModel::enabledTexts() const
{
QStringList items;
for (const auto &item : m_items)
if (item.checked)
items.append(item.displayText);
return items;
}
QStringList ChecklistModel::disabledTexts() const
{
QStringList items;
for (const auto &item : m_items)
if (!item.checked)
items.append(item.displayText);
return items;
}
QVariantList ChecklistModel::enabledItemDatas() const
{
QVariantList items;
for (const auto &item : m_items)
if (item.checked)
items.append(item.data);
return items;
}
QVariantList ChecklistModel::disabledItemDatas() const
{
QVariantList items;
for (const auto &item : m_items)
if (!item.checked)
items.append(item.data);
return items;
}
int ChecklistModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_items.count();
}
QVariant ChecklistModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_items.size())
return {};
const auto &item = m_items.at(index.row());
switch (role)
{
case Qt::DisplayRole: return item.displayText;
case Qt::EditRole: return item.data;
case Qt::CheckStateRole: return item.checked ? Qt::Checked : Qt::Unchecked;
}
return QVariant();
}
bool ChecklistModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.row() < 0 || index.row() >= m_items.size())
return false;
auto &item = m_items[index.row()];
switch (role)
{
case Qt::CheckStateRole:
item.checked = value.toBool();
emit dataChanged(index, index, { Qt::CheckStateRole });
return true;
}
return false;
}
Qt::ItemFlags ChecklistModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return QAbstractListModel::flags(index);
return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
}
-42
View File
@@ -1,42 +0,0 @@
#pragma once
#include <QAbstractListModel>
#include <QList>
class Q_CORE_EXPORT ChecklistModel : public QAbstractListModel
{
Q_OBJECT
public:
struct ChecklistItem
{
QString displayText;
QVariant data;
bool checked;
};
explicit ChecklistModel(QObject *parent = nullptr);
explicit ChecklistModel(const QStringList &items, QObject *parent = nullptr);
explicit ChecklistModel(const QList<ChecklistItem> &strings, QObject *parent = nullptr);
const QList<ChecklistItem> &items() const;
void setItems(const QList<ChecklistItem> &items);
void setItems(const QStringList &items);
QStringList itemTexts() const;
QVariantList itemDatas() const;
QList<ChecklistItem> enabledItems() const;
QList<ChecklistItem> disabledItems() const;
QStringList enabledTexts() const;
QStringList disabledTexts() const;
QVariantList enabledItemDatas() const;
QVariantList disabledItemDatas() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
private:
QList<ChecklistItem> m_items;
};
-148
View File
@@ -1,148 +0,0 @@
#include "progressmodel.h"
#include <QImage>
#include <algorithm>
ProgressModel::ProgressModel(QObject *parent) :
QAbstractListModel(parent)
{
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
}
ProgressModel::ProgressModel(const QStringList &items, QObject *parent) :
QAbstractListModel(parent)
{
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
m_items.reserve(items.count());
for (const auto &item : items)
m_items.append({ item, Item::Status::None });
}
ProgressModel::ProgressModel(const QVector<ProgressModel::Item> &items, QObject *parent) :
QAbstractListModel(parent),
m_items(items)
{
connect(&m_movieLoading, &QMovie::frameChanged, this, &ProgressModel::frameChanged);
if (anyLoading())
m_movieLoading.start();
}
const QVector<ProgressModel::Item> &ProgressModel::items() const
{
return m_items;
}
void ProgressModel::setItems(const QStringList &items)
{
emit beginResetModel();
m_items.clear();
m_items.reserve(items.count());
for (const auto &item : items)
m_items.append({ item, Item::Status::None });
emit endResetModel();
m_movieLoading.stop();
}
void ProgressModel::setItems(const QVector<ProgressModel::Item> &items)
{
emit beginResetModel();
m_items = items;
emit endResetModel();
updateMovieStatus();
}
void ProgressModel::setText(int row, const QString &text)
{
m_items[row].text = text;
const auto index = createIndex(row, 0);
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
}
void ProgressModel::setStatus(int row, ProgressModel::Item::Status status)
{
m_items[row].status = status;
const auto index = createIndex(row, 0);
emit dataChanged(index, index, { Qt::DecorationRole });
if (status == Item::Status::Loading)
m_movieLoading.start();
else
updateMovieStatus();
}
void ProgressModel::clearItems()
{
emit beginResetModel();
m_items.clear();
emit endResetModel();
m_movieLoading.stop();
}
int ProgressModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_items.count();
}
QVariant ProgressModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_items.size())
return {};
const auto &item = m_items.at(index.row());
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
return item.text;
case Qt::DecorationRole:
switch (item.status)
{
case Item::Status::None:
return m_pixmapEmpty;
case Item::Status::Loading:
return m_movieLoading.currentPixmap();
case Item::Status::Succeeded:
return m_pixmapSucceeded;
case Item::Status::Failed:
return m_pixmapFailed;
}
}
return {};
}
void ProgressModel::frameChanged()
{
for (auto iter = m_items.constBegin(); iter != m_items.constEnd(); iter++)
{
if (iter->status == Item::Status::Loading)
{
const auto index = createIndex(std::distance(m_items.constBegin(), iter), 0);
emit dataChanged(index, index, { Qt::DecorationRole });
}
}
}
bool ProgressModel::anyLoading() const
{
return std::any_of(m_items.constBegin(), m_items.constEnd(), [](const auto &item){ return item.status == Item::Status::Loading; });
}
void ProgressModel::updateMovieStatus()
{
if (anyLoading())
m_movieLoading.start();
else
m_movieLoading.stop();
}
-59
View File
@@ -1,59 +0,0 @@
#pragma once
#include <QAbstractListModel>
#include <QPixmap>
#include <QMovie>
class ProgressModel : public QAbstractListModel
{
Q_OBJECT
public:
struct Item
{
enum class Status
{
None,
Loading,
Succeeded,
Failed
};
QString text;
Status status;
};
explicit ProgressModel(QObject *parent = nullptr);
ProgressModel(const QStringList &items, QObject *parent = nullptr);
ProgressModel(const QVector<Item> &items, QObject *parent = nullptr);
const QVector<Item> &items() const;
void setItems(const QStringList &items);
void setItems(const QVector<Item> &items);
void setText(int row, const QString &text);
void setStatus(int row, Item::Status status);
void clearItems();
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
private slots:
void frameChanged();
private:
bool anyLoading() const;
void updateMovieStatus();
QVector<Item> m_items;
const QPixmap m_pixmapSucceeded { ":/loganalyzer/icons/succeeded.png" };
const QPixmap m_pixmapFailed { ":/loganalyzer/icons/failed.png" };
const QPixmap m_pixmapEmpty { [this](){
QPixmap pixmap(m_pixmapSucceeded.size());
pixmap.fill();
return pixmap;
}() };
QMovie m_movieLoading { ":/loganalyzer/icons/loading.gif" };
};