Commit a2c668e2 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

not necessary to use private class here

parent d2067b67
Pipeline #87736 passed with stage
in 53 minutes and 46 seconds
......@@ -13,26 +13,7 @@
#include <QItemSelectionModel>
class QuicktextManagerPrivate
{
public:
QuicktextManagerPrivate(QuicktextManager *qq, QWidget *parentWidget)
: q(qq)
, mParent(parentWidget)
{
}
Q_REQUIRED_RESULT QModelIndex currentGroupIndex() const;
void save();
QuicktextManager *const q;
MailCommon::SnippetsModel *mModel = nullptr;
QItemSelectionModel *mSelectionModel = nullptr;
QWidget *const mParent;
};
QModelIndex QuicktextManagerPrivate::currentGroupIndex() const
QModelIndex QuicktextManager::currentGroupIndex() const
{
if (mSelectionModel->selectedIndexes().isEmpty()) {
return {};
......@@ -46,75 +27,66 @@ QModelIndex QuicktextManagerPrivate::currentGroupIndex() const
}
}
void QuicktextManagerPrivate::save()
void QuicktextManager::save()
{
MailCommon::SnippetsModel::instance()->save();
}
QuicktextManager::QuicktextManager(QObject *parent, QWidget *parentWidget)
: QObject(parent)
, d(new QuicktextManagerPrivate(this, parentWidget))
, mParent(parentWidget)
{
d->mModel = MailCommon::SnippetsModel::instance();
d->mSelectionModel = new QItemSelectionModel(d->mModel);
mModel = MailCommon::SnippetsModel::instance();
mSelectionModel = new QItemSelectionModel(mModel);
}
QuicktextManager::~QuicktextManager()
{
d->save();
save();
}
QAbstractItemModel *QuicktextManager::model() const
{
return d->mModel;
return mModel;
}
QItemSelectionModel *QuicktextManager::selectionModel() const
{
return d->mSelectionModel;
return mSelectionModel;
}
bool QuicktextManager::snippetGroupSelected() const
{
if (d->mSelectionModel->selectedIndexes().isEmpty()) {
if (mSelectionModel->selectedIndexes().isEmpty()) {
return false;
}
return d->mSelectionModel->selectedIndexes().first().data(MailCommon::SnippetsModel::IsGroupRole).toBool();
return mSelectionModel->selectedIndexes().first().data(MailCommon::SnippetsModel::IsGroupRole).toBool();
}
QString QuicktextManager::selectedName() const
{
if (d->mSelectionModel->selectedIndexes().isEmpty()) {
if (mSelectionModel->selectedIndexes().isEmpty()) {
return QString();
}
return d->mSelectionModel->selectedIndexes().first().data(MailCommon::SnippetsModel::NameRole).toString();
}
void QuicktextManager::save()
{
d->save();
return mSelectionModel->selectedIndexes().first().data(MailCommon::SnippetsModel::NameRole).toString();
}
QModelIndex QuicktextManager::currentGroupIndex() const
{
return d->currentGroupIndex();
}
void QuicktextManager::importQuickText()
{
const QString filename = QFileDialog::getOpenFileName(d->mParent, i18n("Import QuickText"));
const QString filename = QFileDialog::getOpenFileName(mParent, i18n("Import QuickText"));
if (!filename.isEmpty()) {
d->mModel->load(filename);
mModel->load(filename);
}
}
void QuicktextManager::exportQuickText()
{
const QString filename = QFileDialog::getSaveFileName(d->mParent, i18n("Export QuickText"));
const QString filename = QFileDialog::getSaveFileName(mParent, i18n("Export QuickText"));
if (!filename.isEmpty()) {
d->mModel->save(filename);
mModel->save(filename);
}
}
......
......@@ -13,7 +13,10 @@
class QAbstractItemModel;
class QItemSelectionModel;
class QuicktextManagerPrivate;
namespace MailCommon
{
class SnippetsModel;
}
class QuicktextManager : public QObject
{
Q_OBJECT
......@@ -62,8 +65,8 @@ Q_SIGNALS:
void insertPlainText(const QString &snippetText);
private:
//@cond PRIVATE
std::unique_ptr<QuicktextManagerPrivate> const d;
//@endcond
MailCommon::SnippetsModel *mModel = nullptr;
QItemSelectionModel *mSelectionModel = nullptr;
QWidget *const mParent;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment