Warning, file /plasma/latte-dock/app/settings/viewsdialog/viewsmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 /*
0003  * SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0004  *
0005  * This file is part of Latte-Dock
0006  *
0007  * SPDX-License-Identifier: GPL-2.0-or-later
0008  *
0009  */
0010 
0011 #ifndef VIEWSMODEL_H
0012 #define VIEWSMODEL_H
0013 
0014 // local
0015 #include "../../lattecorona.h"
0016 #include "../../data/genericbasictable.h"
0017 #include "../../data/screendata.h"
0018 #include "../../data/viewdata.h"
0019 #include "../../data/viewstable.h"
0020 #include "../../layout/centrallayout.h"
0021 
0022 // Qt
0023 #include <QAbstractTableModel>
0024 #include <QModelIndex>
0025 
0026 namespace Latte {
0027 namespace Settings {
0028 namespace Model {
0029 
0030 class Views : public QAbstractTableModel
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     enum Columns
0036     {
0037         IDCOLUMN = 0,
0038         NAMECOLUMN,
0039         SCREENCOLUMN,
0040         EDGECOLUMN,
0041         ALIGNMENTCOLUMN,
0042         SUBCONTAINMENTSCOLUMN,
0043         LASTCOLUMN
0044     };
0045 
0046     enum Roles
0047     {
0048         IDROLE = Qt::UserRole + 1,
0049         NAMEROLE,
0050         ISACTIVEROLE,
0051         ISCHANGEDROLE,
0052         HASCHANGEDVIEWROLE,
0053         CHOICESROLE,
0054         SCREENROLE,
0055         VIEWROLE,
0056         ISMOVEORIGINROLE,
0057         ERRORSROLE,
0058         WARNINGSROLE,
0059         SORTINGROLE
0060     };
0061 
0062     enum SortingPriority
0063     {
0064         NORMALPRIORITY = 10,
0065         MEDIUMPRIORITY = 100,
0066         HIGHPRIORITY = 1000,
0067         HIGHESTPRIORITY = 10000
0068     };
0069 
0070     explicit Views(QObject *parent, Latte::Corona *corona);
0071     ~Views();
0072 
0073     bool hasChangedData() const;
0074     bool containsCurrentName(const QString &name) const;
0075 
0076     //! all original data will become also current
0077     void resetData();
0078 
0079     void appendTemporaryView(const Latte::Data::View &view);
0080     void removeView(const QString &id);
0081 
0082     int rowCount() const;
0083     static int columnCount();
0084     int rowCount(const QModelIndex &parent) const override;
0085     int columnCount(const QModelIndex &parent) const override;
0086 
0087     QVariant data(const QModelIndex &index, int role) const override;
0088     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0089     Qt::ItemFlags flags(const QModelIndex &index) const override;
0090     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0091     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0092 
0093     int rowForId(const QString &id) const;
0094 
0095     QString viewForSubContainment(const QString &sid);
0096 
0097     const Latte::Data::View &at(const int &row);
0098     const Latte::Data::View currentData(const QString &id);
0099     const Latte::Data::View originalData(const QString &id);
0100 
0101     const Latte::Data::ViewsTable &currentViewsData();
0102     const Latte::Data::ViewsTable &originalViewsData();
0103 
0104     void setOriginalData(Latte::Data::ViewsTable &data);
0105     void setOriginalView(QString currentViewId, Latte::Data::View &view);
0106     void updateCurrentView(QString currentViewId, Latte::Data::View &view);
0107     void clearErrorsAndWarnings();
0108 
0109     void updateActiveStatesBasedOn(const CentralLayout *layout);
0110 
0111     Latte::Data::ViewsTable alteredViews() const;
0112     Latte::Data::ViewsTable newViews() const;
0113 
0114 signals:
0115     void rowsInserted();
0116     void rowsRemoved();
0117 
0118 private slots:
0119     void clear();
0120 
0121     void initEdges();
0122     void initAlignments();
0123     void populateScreens();
0124 
0125 private:
0126     Data::ViewsTable edgesChoices(const Data::View &view) const;
0127     Data::ViewsTable horizontalAlignmentChoices(const Data::View &view) const;
0128     Data::ViewsTable verticalAlignmentChoices(const Data::View &view) const;
0129 
0130     bool isVertical(const Plasma::Types::Location &location) const;
0131 
0132     int sortingFactorForState(const Data::View &view) const;
0133     int sortingFactorForScreen(const Data::View &view) const;
0134     int sortingFactorForEdge(const Data::View &view) const;
0135     int sortingFactorForAlignment(const Data::View &view) const;
0136     int sortingFactorForSubContainments(const Data::View &view) const;
0137 
0138     //! based on priority a sortable text is returned
0139     QString sortableText(const int &priority, const QString &text) const;
0140 
0141     Latte::Data::Screen screenData(const QString &viewId) const;
0142 
0143 private:
0144     Latte::Data::ViewsTable m_viewsTable;
0145     Latte::Data::ViewsTable o_viewsTable;
0146 
0147     Latte::Corona *m_corona{nullptr};
0148 
0149     Data::ViewsTable s_edges;
0150     Data::ViewsTable s_horizontalAlignments;
0151     Data::ViewsTable s_verticalAlignments;
0152     Latte::Data::ScreensTable s_screens;
0153 };
0154 
0155 }
0156 }
0157 }
0158 
0159 #endif