mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Merge branch 'microFixes' of https://github.com/tcanabrava/subsurface
This commit is contained in:
		
						commit
						ace8b4f2ea
					
				
					 2 changed files with 38 additions and 3 deletions
				
			
		| 
						 | 
					@ -10,8 +10,10 @@
 | 
				
			||||||
#include <QApplication>
 | 
					#include <QApplication>
 | 
				
			||||||
#include <QHeaderView>
 | 
					#include <QHeaderView>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
 | 
					#include <QSettings>
 | 
				
			||||||
#include <QKeyEvent>
 | 
					#include <QKeyEvent>
 | 
				
			||||||
#include <QSortFilterProxyModel>
 | 
					#include <QSortFilterProxyModel>
 | 
				
			||||||
 | 
					#include <QAction>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false)
 | 
					DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false)
 | 
				
			||||||
| 
						 | 
					@ -20,6 +22,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
 | 
				
			||||||
	setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
 | 
						setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
 | 
				
			||||||
	QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
 | 
						QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
 | 
				
			||||||
	setModel(model);
 | 
						setModel(model);
 | 
				
			||||||
 | 
						header()->setContextMenuPolicy(Qt::ActionsContextMenu);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveListView::reload()
 | 
					void DiveListView::reload()
 | 
				
			||||||
| 
						 | 
					@ -37,11 +40,41 @@ void DiveListView::reload()
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			setCurrentIndex(firstDiveOrTrip);
 | 
								setCurrentIndex(firstDiveOrTrip);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// Populate the context menu of the headers that will show
 | 
				
			||||||
 | 
						// the menu to show / hide columns.
 | 
				
			||||||
 | 
						if (!header()->actions().size()){
 | 
				
			||||||
 | 
							QAction *visibleAction = new QAction("Visible:", header());
 | 
				
			||||||
 | 
							header()->addAction(visibleAction);
 | 
				
			||||||
 | 
							QSettings s;
 | 
				
			||||||
 | 
							s.beginGroup("DiveListColumnState");
 | 
				
			||||||
 | 
							for(int i = 0; i < model()->columnCount(); i++){
 | 
				
			||||||
 | 
								QString title = QString("show %1").arg( model()->headerData( i, Qt::Horizontal).toString());
 | 
				
			||||||
 | 
								QAction *a = new QAction(title, header());
 | 
				
			||||||
 | 
								a->setCheckable(true);
 | 
				
			||||||
 | 
								a->setChecked( s.value(title, true).toBool());
 | 
				
			||||||
 | 
								a->setProperty("index", i);
 | 
				
			||||||
 | 
								connect(a, SIGNAL(triggered(bool)), this, SLOT(hideColumnByIndex()));
 | 
				
			||||||
 | 
								header()->addAction(a);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							s.endGroup();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveListView::setModel(QAbstractItemModel* model)
 | 
					void DiveListView::hideColumnByIndex()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QTreeView::setModel(model);
 | 
						QAction *action = qobject_cast<QAction*>(sender());
 | 
				
			||||||
 | 
						if (!action)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QSettings s;
 | 
				
			||||||
 | 
						s.beginGroup("DiveListColumnState");
 | 
				
			||||||
 | 
						s.setValue(action->text(), action->isChecked());
 | 
				
			||||||
 | 
						s.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (action->isChecked())
 | 
				
			||||||
 | 
							showColumn(action->property("index").toInt());
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							hideColumn(action->property("index").toInt());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
 | 
					void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,6 @@ public:
 | 
				
			||||||
	DiveListView(QWidget *parent = 0);
 | 
						DiveListView(QWidget *parent = 0);
 | 
				
			||||||
	void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
 | 
						void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
 | 
				
			||||||
	void currentChanged(const QModelIndex& current, const QModelIndex& previous);
 | 
						void currentChanged(const QModelIndex& current, const QModelIndex& previous);
 | 
				
			||||||
	void setModel(QAbstractItemModel* model);
 | 
					 | 
				
			||||||
	void mousePressEvent(QMouseEvent* event);
 | 
						void mousePressEvent(QMouseEvent* event);
 | 
				
			||||||
	void mouseReleaseEvent(QMouseEvent* event);
 | 
						void mouseReleaseEvent(QMouseEvent* event);
 | 
				
			||||||
	void keyPressEvent(QKeyEvent* event);
 | 
						void keyPressEvent(QKeyEvent* event);
 | 
				
			||||||
| 
						 | 
					@ -31,6 +30,9 @@ public:
 | 
				
			||||||
	void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
 | 
						void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
 | 
				
			||||||
	void reload();
 | 
						void reload();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public slots:
 | 
				
			||||||
 | 
						void hideColumnByIndex();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_SIGNALS:
 | 
					Q_SIGNALS:
 | 
				
			||||||
	void currentDiveChanged(int divenr);
 | 
						void currentDiveChanged(int divenr);
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue