mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Fixed input in the DivePlanner table
Based on Glance's idea on rewritting the Delegates, but we don't need to redo the wheel as Qt already gives us the correct Delegate, we just need to set some boundaries on it before returning. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									3dbc5bfeaa
								
							
						
					
					
						commit
						af9d62bac3
					
				
					 3 changed files with 55 additions and 1 deletions
				
			
		|  | @ -289,6 +289,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg | ||||||
| 	QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); | 	QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); | ||||||
| 	connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan())); | 	connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan())); | ||||||
| 
 | 
 | ||||||
|  | 	// This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
 | ||||||
|  | 	ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, INT_MAX, this)); | ||||||
|  | 	ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, this)); | ||||||
|  | 	ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, INT_MAX, this)); | ||||||
|  | 	ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0.2, 2, this)); | ||||||
|  | 
 | ||||||
| 	/* set defaults. */ | 	/* set defaults. */ | ||||||
| 	ui.ATMPressure->setValue(1013); | 	ui.ATMPressure->setValue(1013); | ||||||
| 	ui.atmHeight->setValue(0); | 	ui.atmHeight->setValue(0); | ||||||
|  | @ -510,7 +516,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const | ||||||
| 		case CCSETPOINT: | 		case CCSETPOINT: | ||||||
| 			return (double)p.po2 / 1000; | 			return (double)p.po2 / 1000; | ||||||
| 		case DEPTH: | 		case DEPTH: | ||||||
| 			return rint(get_depth_units(p.depth, NULL, NULL)); | 			return (int) rint(get_depth_units(p.depth, NULL, NULL)); | ||||||
| 		case RUNTIME: | 		case RUNTIME: | ||||||
| 			return p.time / 60; | 			return p.time / 60; | ||||||
| 		case DURATION: | 		case DURATION: | ||||||
|  |  | ||||||
|  | @ -364,3 +364,31 @@ void ProfilePrintDelegate::paint(QPainter *painter, const QStyleOptionViewItem & | ||||||
| 	} | 	} | ||||||
| 	QStyledItemDelegate::paint(painter, option, index); | 	QStyledItemDelegate::paint(painter, option, index); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | SpinBoxDelegate::SpinBoxDelegate(int min, int max, QObject *parent): | ||||||
|  | 	QStyledItemDelegate(parent), | ||||||
|  | 	min(min), | ||||||
|  | 	max(max) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||||||
|  | { | ||||||
|  | 	QSpinBox *w = qobject_cast<QSpinBox*>(QStyledItemDelegate::createEditor(parent, option, index)); | ||||||
|  | 	w->setRange(min,max); | ||||||
|  | 	return w; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | DoubleSpinBoxDelegate::DoubleSpinBoxDelegate(qreal min, qreal max, QObject *parent): | ||||||
|  | 	QStyledItemDelegate(parent), | ||||||
|  | 	min(min), | ||||||
|  | 	max(max) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||||||
|  | { | ||||||
|  | 	QDoubleSpinBox *w = qobject_cast<QDoubleSpinBox*>(QStyledItemDelegate::createEditor(parent, option, index)); | ||||||
|  | 	w->setRange(min,max); | ||||||
|  | 	return w; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -88,4 +88,24 @@ public: | ||||||
| 	void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; | 	void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | class SpinBoxDelegate : public QStyledItemDelegate { | ||||||
|  | 	Q_OBJECT | ||||||
|  | public: | ||||||
|  | 	SpinBoxDelegate(int min, int max, QObject *parent = 0); | ||||||
|  | 	virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||||||
|  | private: | ||||||
|  | 	int min; | ||||||
|  | 	int max; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | class DoubleSpinBoxDelegate : public QStyledItemDelegate { | ||||||
|  | 	Q_OBJECT | ||||||
|  | public: | ||||||
|  | 	DoubleSpinBoxDelegate(qreal min, qreal max, QObject *parent = 0); | ||||||
|  | 	virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||||||
|  | private: | ||||||
|  | 	int min; | ||||||
|  | 	int max; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| #endif // MODELDELEGATES_H
 | #endif // MODELDELEGATES_H
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue