mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
		
			
				
	
	
		
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| #include "qt-models/divecomputerextradatamodel.h"
 | |
| #include "core/divecomputer.h"
 | |
| #include "core/extradata.h"
 | |
| #include "core/metrics.h"
 | |
| 
 | |
| ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent)
 | |
| {
 | |
| 	//enum Column {KEY, VALUE};
 | |
| 	setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
 | |
| }
 | |
| 
 | |
| void ExtraDataModel::clear()
 | |
| {
 | |
| 	beginResetModel();
 | |
| 	items.clear();
 | |
| 	endResetModel();
 | |
| }
 | |
| 
 | |
| QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
 | |
| {
 | |
| 	if (!index.isValid() || index.row() > (int)items.size())
 | |
| 		return QVariant();
 | |
| 	const Item &item = items[index.row()];
 | |
| 
 | |
| 	switch (role) {
 | |
| 	case Qt::FontRole:
 | |
| 		return defaultModelFont();
 | |
| 	case Qt::TextAlignmentRole:
 | |
| 		return static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter);
 | |
| 	case Qt::DisplayRole:
 | |
| 		switch (index.column()) {
 | |
| 		case KEY:
 | |
| 			return item.key;
 | |
| 		case VALUE:
 | |
| 			return item.value;
 | |
| 		}
 | |
| 		return QVariant();
 | |
| 	}
 | |
| 	return QVariant();
 | |
| }
 | |
| 
 | |
| int ExtraDataModel::rowCount(const QModelIndex&) const
 | |
| {
 | |
| 	return (int)items.size();
 | |
| }
 | |
| 
 | |
| void ExtraDataModel::updateDiveComputer(const struct divecomputer *dc)
 | |
| {
 | |
| 	beginResetModel();
 | |
| 	struct extra_data *ed = dc ? dc->extra_data : nullptr;
 | |
| 	items.clear();
 | |
| 	while (ed) {
 | |
| 		items.push_back({ ed->key, ed->value });
 | |
| 		ed = ed->next;
 | |
| 	}
 | |
| 	endResetModel();
 | |
| }
 |