File indexing completed on 2024-05-12 05:21:41
0001 /* 0002 * Copyright (C) 2007 by Mathias Soeken <msoeken@tzi.de> 0003 * Copyright (C) 2019 Alexander Potashev <aspotashev@gmail.com> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License along 0016 * with this program; if not, write to the 0017 * Free Software Foundation, Inc. 0018 * 51 Franklin Street, Fifth Floor 0019 * Boston, MA 02110-1301 USA. 0020 * 0021 */ 0022 0023 #ifndef TREEVIEWHEADERCONTEXTMENU_H 0024 #define TREEVIEWHEADERCONTEXTMENU_H 0025 0026 #include <QHash> 0027 #include <QMenu> 0028 #include <QObject> 0029 #include <QPoint> 0030 #include <QVector> 0031 0032 QT_BEGIN_NAMESPACE 0033 class QAction; 0034 class QTreeView; 0035 QT_END_NAMESPACE 0036 0037 /** 0038 * ContextMenu for QTreeView::header() to toggle the 0039 * visible state of the columns. 0040 * 0041 * It is possible to exclude columns from inserting in the 0042 * menu either by the @p excludedColumns parameter in the constructor. 0043 * 0044 * @author Mathias Soeken <msoeken@tzi.de> 0045 */ 0046 class TreeViewHeaderContextMenu : public QObject 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 TreeViewHeaderContextMenu(QObject *parent, QTreeView *widget, QVector<int> &&excludedColumns); 0052 ~TreeViewHeaderContextMenu() override; 0053 0054 private Q_SLOTS: 0055 void slotCustomContextMenuRequested(const QPoint &); 0056 0057 protected Q_SLOTS: 0058 void updateActions(); 0059 void slotTriggered(QAction *); 0060 void slotAboutToShow(); 0061 0062 Q_SIGNALS: 0063 void columnToggled(int); 0064 0065 private: 0066 void updateAction(QAction *action, int column); 0067 0068 QTreeView *m_widget; 0069 QVector<QAction *> m_actions; 0070 QMenu *m_contextMenu; 0071 QHash<QAction *, int> m_actionColumnMapping; 0072 QVector<int> m_excludedColumns; 0073 }; 0074 0075 #endif