mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Made the TableViews share a bit of code, code cleanup.
Made the tableviews share a bit of code, and code cleanup. The tableviews for Cylinders, Weigth and Dive Planner Points now shares the CSS and I also implemented the save / load methods for the dive planner points, so the functionality is mostly done on the vieualization side. - since we are now using three tables maybe it's a better idea to create one class SubSurfaceTable that knows how to handle saving / loading of the columns... TODO for the future. ;) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
		
							parent
							
								
									cfd17116eb
								
							
						
					
					
						commit
						bb59202812
					
				
					 5 changed files with 57 additions and 62 deletions
				
			
		|  | @ -1,8 +1,10 @@ | ||||||
| #include "diveplanner.h" | #include "diveplanner.h" | ||||||
| #include "graphicsview-common.h" | #include "graphicsview-common.h" | ||||||
|  | #include "models.h" | ||||||
| 
 | 
 | ||||||
| #include "../dive.h" | #include "../dive.h" | ||||||
| #include "../divelist.h" | #include "../divelist.h" | ||||||
|  | 
 | ||||||
| #include <cmath> | #include <cmath> | ||||||
| #include <QMouseEvent> | #include <QMouseEvent> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
|  | @ -16,7 +18,7 @@ | ||||||
| #include <QListView> | #include <QListView> | ||||||
| #include <QDesktopWidget> | #include <QDesktopWidget> | ||||||
| #include <QModelIndex> | #include <QModelIndex> | ||||||
| 
 | #include <QSettings> | ||||||
| #include "ui_diveplanner.h" | #include "ui_diveplanner.h" | ||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| 
 | 
 | ||||||
|  | @ -833,8 +835,46 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge | ||||||
| 	connect(ui->lowGF, SIGNAL(textChanged(QString)), this, SLOT(gflowChanged(QString))); | 	connect(ui->lowGF, SIGNAL(textChanged(QString)), this, SLOT(gflowChanged(QString))); | ||||||
| 	connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString))); | 	connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString))); | ||||||
| 	connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool))); | 	connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool))); | ||||||
|  | 
 | ||||||
|  | 	QFile cssFile(":table-css"); | ||||||
|  | 	cssFile.open(QIODevice::ReadOnly); | ||||||
|  | 	QTextStream reader(&cssFile); | ||||||
|  | 	QString css = reader.readAll(); | ||||||
|  | 
 | ||||||
|  | 	ui->tablePoints->setStyleSheet(css); | ||||||
|  | 	QFontMetrics metrics(defaultModelFont()); | ||||||
|  | 
 | ||||||
|  | 	ui->tablePoints->horizontalHeader()->setResizeMode(DivePlannerPointsModel::REMOVE, QHeaderView::Fixed); | ||||||
|  | 	ui->tablePoints->verticalHeader()->setDefaultSectionSize( metrics.height() +8 ); | ||||||
|  | 	initialUiSetup(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DivePlannerWidget::hideEvent(QHideEvent* event) | ||||||
|  | { | ||||||
|  | 	QSettings s; | ||||||
|  | 	s.beginGroup("DivePlanner"); | ||||||
|  | 	s.beginGroup("PointTables"); | ||||||
|  | 	for (int i = 0; i < CylindersModel::COLUMNS; i++) { | ||||||
|  | 		s.setValue(QString("colwidth%1").arg(i), ui->tablePoints->columnWidth(i)); | ||||||
|  | 	} | ||||||
|  | 	s.endGroup(); | ||||||
|  | 	s.sync(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void DivePlannerWidget::initialUiSetup() | ||||||
|  | { | ||||||
|  | 	QSettings s; | ||||||
|  | 	s.beginGroup("DivePlanner"); | ||||||
|  | 	s.beginGroup("PointTables"); | ||||||
|  | 	for (int i = 0; i < CylindersModel::COLUMNS; i++) { | ||||||
|  | 		QVariant width = s.value(QString("colwidth%1").arg(i)); | ||||||
|  | 		if (width.isValid()) | ||||||
|  | 			ui->tablePoints->setColumnWidth(i, width.toInt()); | ||||||
|  | 		else | ||||||
|  | 			ui->tablePoints->resizeColumnToContents(i); | ||||||
|  | 	} | ||||||
|  | 	s.endGroup(); | ||||||
|  | } | ||||||
| void DivePlannerWidget::startTimeChanged(const QTime& time) | void DivePlannerWidget::startTimeChanged(const QTime& time) | ||||||
| { | { | ||||||
| 	plannerModel->setStartTime(time); | 	plannerModel->setStartTime(time); | ||||||
|  |  | ||||||
|  | @ -183,6 +183,7 @@ private: | ||||||
| 
 | 
 | ||||||
| class DivePlannerWidget : public QWidget { | class DivePlannerWidget : public QWidget { | ||||||
| 	Q_OBJECT | 	Q_OBJECT | ||||||
|  |     void initialUiSetup(); | ||||||
| public: | public: | ||||||
|     explicit DivePlannerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); |     explicit DivePlannerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); | ||||||
| 
 | 
 | ||||||
|  | @ -194,7 +195,8 @@ public slots: | ||||||
| 	void gflowChanged(const QString& gflow); | 	void gflowChanged(const QString& gflow); | ||||||
| 	void gfhighChanged(const QString& gfhigh); | 	void gfhighChanged(const QString& gfhigh); | ||||||
| 	void lastStopChanged(bool checked); | 	void lastStopChanged(bool checked); | ||||||
| 
 | protected: | ||||||
|  |     virtual void hideEvent(QHideEvent* ); | ||||||
| private: | private: | ||||||
| 	Ui::DivePlanner *ui; | 	Ui::DivePlanner *ui; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -18,6 +18,8 @@ | ||||||
| #include <QCompleter> | #include <QCompleter> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
| #include <QSet> | #include <QSet> | ||||||
|  | #include <QTextStream> | ||||||
|  | #include <QFile> | ||||||
| #include <QSettings> | #include <QSettings> | ||||||
| 
 | 
 | ||||||
| MainTab::MainTab(QWidget *parent) : QTabWidget(parent), | MainTab::MainTab(QWidget *parent) : QTabWidget(parent), | ||||||
|  | @ -85,7 +87,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), | ||||||
| 	connect(ui->weights, SIGNAL(clicked(QModelIndex)), this, SLOT(editWeigthWidget(QModelIndex))); | 	connect(ui->weights, SIGNAL(clicked(QModelIndex)), this, SLOT(editWeigthWidget(QModelIndex))); | ||||||
| 
 | 
 | ||||||
| 	QFontMetrics metrics(defaultModelFont()); | 	QFontMetrics metrics(defaultModelFont()); | ||||||
| 	QFontMetrics metrics2(font()); |  | ||||||
| 
 | 
 | ||||||
| 	ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed); | 	ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed); | ||||||
| 	ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 ); | 	ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 ); | ||||||
|  | @ -106,6 +107,13 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), | ||||||
| 	ui->location->setCompleter(completers.location); | 	ui->location->setCompleter(completers.location); | ||||||
| 	ui->suit->setCompleter(completers.suit); | 	ui->suit->setCompleter(completers.suit); | ||||||
| 
 | 
 | ||||||
|  | 	QFile cssFile(":table-css"); | ||||||
|  | 	cssFile.open(QIODevice::ReadOnly); | ||||||
|  | 	QTextStream reader(&cssFile); | ||||||
|  | 	QString css = reader.readAll(); | ||||||
|  | 
 | ||||||
|  | 	ui->cylinders->setStyleSheet(css); | ||||||
|  | 	ui->weights->setStyleSheet(css); | ||||||
| 	initialUiSetup(); | 	initialUiSetup(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ | ||||||
|    <string>TabWidget</string> |    <string>TabWidget</string> | ||||||
|   </property> |   </property> | ||||||
|   <property name="currentIndex"> |   <property name="currentIndex"> | ||||||
|    <number>0</number> |    <number>1</number> | ||||||
|   </property> |   </property> | ||||||
|   <widget class="QWidget" name="notesTab"> |   <widget class="QWidget" name="notesTab"> | ||||||
|    <attribute name="title"> |    <attribute name="title"> | ||||||
|  | @ -159,35 +159,7 @@ | ||||||
|         <item> |         <item> | ||||||
|          <widget class="QTableView" name="cylinders"> |          <widget class="QTableView" name="cylinders"> | ||||||
|           <property name="styleSheet"> |           <property name="styleSheet"> | ||||||
|            <string notr="true"> QTableView { |            <string notr="true"/> | ||||||
|      show-decoration-selected: 1; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item { |  | ||||||
|      border: 1px solid #d9d9d9; |  | ||||||
|      border-top-color: transparent; |  | ||||||
|      border-bottom-color: transparent; |  | ||||||
|      padding: 2px; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:hover { |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); |  | ||||||
|      border: 1px solid #bfcde4; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected { |  | ||||||
|      border: 1px solid #567dbc; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected:active{ |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc); |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected:!active { |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
| </string> |  | ||||||
|           </property> |           </property> | ||||||
|           <property name="alternatingRowColors"> |           <property name="alternatingRowColors"> | ||||||
|            <bool>true</bool> |            <bool>true</bool> | ||||||
|  | @ -210,35 +182,7 @@ | ||||||
|         <item> |         <item> | ||||||
|          <widget class="QTableView" name="weights"> |          <widget class="QTableView" name="weights"> | ||||||
|           <property name="styleSheet"> |           <property name="styleSheet"> | ||||||
|            <string notr="true"> QTableView { |            <string notr="true"/> | ||||||
|      show-decoration-selected: 1; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item { |  | ||||||
|      border: 1px solid #d9d9d9; |  | ||||||
|      border-top-color: transparent; |  | ||||||
|      border-bottom-color: transparent; |  | ||||||
|      padding: 2px; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:hover { |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); |  | ||||||
|      border: 1px solid #bfcde4; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected { |  | ||||||
|      border: 1px solid #567dbc; |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected:active{ |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc); |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
|  QTableView::item:selected:!active { |  | ||||||
|      background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); |  | ||||||
|  } |  | ||||||
| 
 |  | ||||||
| </string> |  | ||||||
|           </property> |           </property> | ||||||
|           <property name="showGrid"> |           <property name="showGrid"> | ||||||
|            <bool>false</bool> |            <bool>false</bool> | ||||||
|  |  | ||||||
|  | @ -10,5 +10,6 @@ | ||||||
| 	<file alias="minimum">icons/minimum.svg</file> | 	<file alias="minimum">icons/minimum.svg</file> | ||||||
| 	<file alias="maximum">icons/maximum.svg</file> | 	<file alias="maximum">icons/maximum.svg</file> | ||||||
| 	<file alias="average">icons/average.svg</file> | 	<file alias="average">icons/average.svg</file> | ||||||
|  | 	<file alias="table-css">qt-ui/css/tableviews.css</file> | ||||||
|  </qresource> |  </qresource> | ||||||
|  </RCC> |  </RCC> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue