File indexing completed on 2022-10-04 15:12:31

0001 /***************************************************************************
0002 *   Copyright 2007 Niko Sams <niko.sams@gmail.com>                        *
0003 *                                                                         *
0004 *   This program is free software; you can redistribute it and/or modify  *
0005 *   it under the terms of the GNU General Public License as published by  *
0006 *   the Free Software Foundation; either version 2 of the License, or     *
0007 *   (at your option) any later version.                                   *
0008 *                                                                         *
0009 ***************************************************************************/
0010 
0011 #ifndef UPLOADPROJECTMODEL_H
0012 #define UPLOADPROJECTMODEL_H
0013 
0014 #include <QSortFilterProxyModel>
0015 
0016 #include <ksharedconfig.h>
0017 #include <kconfiggroup.h>
0018 
0019 namespace KDevelop {
0020     class IProject;
0021     class ProjectModel;
0022     class ProjectBaseItem;
0023 }
0024 class QUrl;
0025 
0026 /**
0027  * ProxyModel that adds checkboxes for upload status to the ProjectModel.
0028  *
0029  * Reads out the modified time of files and compares it with the last upload time
0030  * to automatically select changed items.
0031  */
0032 class UploadProjectModel : public QSortFilterProxyModel
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     UploadProjectModel( KDevelop::IProject* project, QObject *parent = nullptr );
0038     ~UploadProjectModel() override;
0039 
0040     QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const override;
0041     bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) override;
0042     Qt::ItemFlags flags ( const QModelIndex & index ) const override;
0043 
0044     bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const override;
0045 
0046     /**
0047      * Sets the profile KConfigGroup where the uploadtimes are stored.
0048      * called when user changes the active upload-profile.
0049      */
0050     void setProfileConfigGroup(const KConfigGroup& group);
0051     /**
0052      * Returns the KConfigGroup with the current upload-profile.
0053      */
0054     KConfigGroup profileConfigGroup() const;
0055 
0056     /**
0057      * Convenience function that returns the casted project-model.
0058      */
0059     KDevelop::ProjectModel* projectModel() const;
0060 
0061     /**
0062      * Convenience function that returns a casted project-item for an index.
0063      */
0064     KDevelop::ProjectBaseItem* item(const QModelIndex& index) const;
0065 
0066     /**
0067      * Helper-function to iterate recursive through the project-tree.
0068      * @param current the current index, start with QModelIndex()
0069      * @param root set to valid QModelIndex if a different root should be used
0070      * @return the next model-index in the iteration
0071      */
0072     QModelIndex nextRecursionIndex(const QModelIndex& current, const QModelIndex& root = QModelIndex()) const;
0073 
0074     void setRootItem(KDevelop::ProjectBaseItem* item);
0075 
0076     /**
0077      * Returns the name of the current Upload Profile (which is set through setProfileConfigGroup)
0078      */
0079     QString currentProfileName();
0080 
0081     /**
0082      * Returns the url of the current Upload Profile (which is set through setProfileConfigGroup)
0083      */
0084     QUrl currentProfileUrl();
0085     
0086     /**
0087      * Returns the local url of the current Upload Profile (which is set through setProfileConfigGroup)
0088      */
0089     QUrl currentProfileLocalUrl();
0090 
0091 public Q_SLOTS:
0092     /**
0093      * Checks all items
0094      */
0095     void checkAll();
0096 
0097     /**
0098      * Checks all modified items
0099      */
0100     void checkModified();
0101 
0102     /**
0103      * Inverts the checkStatus of all items
0104      */
0105     void checkInvert();
0106 
0107 private:
0108     KDevelop::IProject* m_project; ///< current project
0109     KConfigGroup m_profileConfigGroup; ///< KConfigGroup for active upload-profile
0110     QMap<QModelIndex, Qt::CheckState> m_checkStates; ///< holds the user-modified states of the checkboxes
0111     KDevelop::ProjectBaseItem* m_rootItem; ///< rootItem, tree is only displayed from here
0112 };
0113 
0114 
0115 #endif
0116 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on