File indexing completed on 2024-04-28 15:13:25

0001 /***************************************************************************
0002     File                 : ProjectExplorer.cpp
0003     Project              : LabPlot
0004     Description          : A tree view for displaying and editing an AspectTreeModel.
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2007-2008 by Tilman Benkert (thzs@gmx.net)
0007     Copyright            : (C) 2011-2016 Alexander Semke (alexander.semke@web.de)
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 #ifndef PROJECT_EXPLORER_H
0029 #define PROJECT_EXPLORER_H
0030 
0031 #include <QWidget>
0032 
0033 class AbstractAspect;
0034 class AspectTreeModel;
0035 class Project;
0036 class XmlStreamReader;
0037 
0038 class QFrame;
0039 class QLabel;
0040 class QLineEdit;
0041 class QModelIndex;
0042 class QToolButton;
0043 class QSignalMapper;
0044 class QTreeView;
0045 class QXmlStreamWriter;
0046 class QItemSelection;
0047 class QMenu;
0048 
0049 class ProjectExplorer : public QWidget {
0050     Q_OBJECT
0051 
0052 public:
0053     explicit ProjectExplorer(QWidget* parent = nullptr);
0054     ~ProjectExplorer() override;
0055 
0056     void setCurrentAspect(const AbstractAspect*);
0057     void setModel(AspectTreeModel*);
0058     void setProject(Project*);
0059     QModelIndex currentIndex() const;
0060     void updateSelectedAspects();
0061     void search();
0062 
0063 private:
0064     void createActions();
0065     void contextMenuEvent(QContextMenuEvent*) override;
0066     bool eventFilter(QObject*, QEvent*) override;
0067     void keyPressEvent(QKeyEvent*) override;
0068     void collapseParents(const QModelIndex&, const QList<QModelIndex>& expanded);
0069     bool filter(const QModelIndex&, const QString&);
0070     int m_columnToHide{0};
0071     QTreeView* m_treeView;
0072     Project* m_project{nullptr};
0073     QPoint m_dragStartPos;
0074     bool m_dragStarted{false};
0075     bool m_changeSelectionFromView{false};
0076 
0077     QAction* caseSensitiveAction;
0078     QAction* matchCompleteWordAction;
0079     QAction* expandTreeAction;
0080     QAction* expandSelectedTreeAction;
0081     QAction* collapseTreeAction;
0082     QAction* collapseSelectedTreeAction;
0083     QAction* deleteSelectedTreeAction;
0084     QAction* toggleFilterAction;
0085     QAction* showAllColumnsAction;
0086     QList<QAction*> list_showColumnActions;
0087     QSignalMapper* showColumnsSignalMapper;
0088 
0089     QFrame* m_frameFilter;
0090     QLineEdit* m_leFilter;
0091     QToolButton* bFilterOptions;
0092 
0093 private slots:
0094     void projectLoaded();
0095     void aspectAdded(const AbstractAspect*);
0096     void toggleColumn(int);
0097     void showAllColumns();
0098     void filterTextChanged(const QString&);
0099     void toggleFilterCaseSensitivity();
0100     void toggleFilterMatchCompleteWord();
0101     void toggleFilterWidgets();
0102     void toggleFilterOptionsMenu(bool);
0103     void resizeHeader();
0104     void expandSelected();
0105     void collapseSelected();
0106     void deleteSelected();
0107 
0108     void navigateTo(const QString& path);
0109     void currentChanged(const QModelIndex& current, const QModelIndex& previous);
0110     void selectIndex(const QModelIndex&);
0111     void deselectIndex(const QModelIndex&);
0112     void selectionChanged(const QItemSelection&, const QItemSelection&);
0113 
0114     void save(QXmlStreamWriter*) const;
0115     bool load(XmlStreamReader*);
0116 
0117 signals:
0118     void currentAspectChanged(AbstractAspect*);
0119     void activateView(AbstractAspect*);
0120     void selectedAspectsChanged(QList<AbstractAspect*>&);
0121     void hiddenAspectSelected(const AbstractAspect*);
0122 };
0123 
0124 #endif // ifndef PROJECT_EXPLORER_H