File indexing completed on 2024-04-28 05:08:23

0001 /***************************************************************************
0002     Copyright (C) 2001-2020 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_GROUPVIEW_H
0026 #define TELLICO_GROUPVIEW_H
0027 
0028 #include "gui/treeview.h"
0029 #include "observer.h"
0030 
0031 namespace Tellico {
0032   namespace Data {
0033     class EntryGroup;
0034   }
0035   class Filter;
0036   class GroupIterator;
0037   class EntryGroupModel;
0038 
0039 /**
0040  * The GroupView shows the entries grouped, as well as the saved filters.
0041  *
0042  * There is one root item for each collection in the document. The entries are grouped
0043  * by the field defined by each collection. A @ref QDict is used to keep track of the
0044  * group items.
0045  *
0046  * @see Tellico::Data::Collection
0047  *
0048  * @author Robby Stephenson
0049  */
0050 class GroupView : public GUI::TreeView, public Observer {
0051 Q_OBJECT
0052 
0053 public:
0054   /**
0055    * The constructor sets up the single column, and initializes the popup menu.
0056    *
0057    * @param parent A pointer to the parent widget
0058    */
0059   GroupView(QWidget* parent);
0060 
0061   EntryGroupModel* sourceModel() const;
0062 
0063   /**
0064    * Returns the name of the field by which the entries are grouped
0065    *
0066    * @return The field name
0067    */
0068   const QString& groupBy() const { return m_groupBy; }
0069   /**
0070    * Sets the name of the field by which the entries are grouped
0071    *
0072    * @param groupFieldName The field name
0073    */
0074   void setGroupField(const QString& groupFieldName);
0075   QString entrySortField() const;
0076   void setEntrySortField(const QString& groupSortName);
0077   /**
0078    * Adds a collection, along with all all the groups for the collection in
0079    * the groupFieldribute. This method gets called as well when the groupFieldribute
0080    * is changed, since it essentially repopulates the listview.
0081    *
0082    * @param coll A pointer to the collection being added
0083    */
0084   void addCollection(Data::CollPtr coll);
0085   /**
0086    * Removes a root collection item, and all of its children.
0087    *
0088    * @param coll A pointer to the collection
0089    */
0090   void removeCollection(Data::CollPtr coll);
0091   /**
0092    * Refresh all the items for the collection.
0093    */
0094   void populateCollection();
0095   /**
0096    * Selects the first item which refers to a certain entry.
0097    *
0098    * @param entry A pointer to the entry
0099    */
0100   void setEntrySelected(Data::EntryPtr entry);
0101 
0102   virtual void modifyField(Data::CollPtr coll, Data::FieldPtr oldField, Data::FieldPtr newField) Q_DECL_OVERRIDE;
0103 
0104 public Q_SLOTS:
0105   /**
0106    * Resets the list view, clearing and deleting all items.
0107    */
0108   void slotReset();
0109   /**
0110    * Adds or removes listview items when groups are modified.
0111    *
0112    * @param coll A pointer to the collection of the gorup
0113    * @param groups A vector of pointers to the modified groups
0114    */
0115   void slotModifyGroups(Tellico::Data::CollPtr coll, QList<Tellico::Data::EntryGroup*> groups);
0116 
0117 private:
0118   void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE;
0119   /**
0120    * Inserts a listviewitem for a given group
0121    *
0122    * @param group The group to be added
0123    */
0124   void addGroup(Data::EntryGroup* group);
0125 
0126   QString groupTitle();
0127   void updateHeader(Data::FieldPtr field=Data::FieldPtr());
0128 
0129 private Q_SLOTS:
0130   /**
0131    * Handles changing the icon when an item is expanded, depended on whether it refers
0132    * to a collection, a group, or an entry.
0133    */
0134   void slotExpanded(const QModelIndex& index);
0135   /**
0136    * Handles changing the icon when an item is collapsed, depended on whether it refers
0137    * to a collection, a group, or an entry.
0138    */
0139   void slotCollapsed(const QModelIndex& index);
0140   /**
0141    * Filter by group
0142    */
0143   void slotFilterGroup();
0144   void slotDoubleClicked(const QModelIndex& index);
0145   void slotSortingChanged(int column, Qt::SortOrder order);
0146   void slotSortMenuActivated(QAction* action);
0147 
0148 Q_SIGNALS:
0149   /**
0150    * Signals a desire to filter the view.
0151    *
0152    * @param filter A pointer to the filter
0153    */
0154   void signalUpdateFilter(Tellico::FilterPtr filter);
0155 
0156 private:
0157   friend class GroupIterator;
0158 
0159   bool m_notSortedYet;
0160   Data::CollPtr m_coll;
0161   QString m_groupBy;
0162   QString m_entrySortField;
0163 
0164   QString m_groupOpenIconName;
0165   QString m_groupClosedIconName;
0166 };
0167 
0168 } // end namespace
0169 #endif