File: FlowsheetViewer.h

package info (click to toggle)
dyssol 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,184 kB
  • sloc: cpp: 53,870; sh: 85; python: 59; makefile: 11
file content (91 lines) | stat: -rw-r--r-- 3,132 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (c) 2021, Dyssol Development Team.
 * Copyright (c) 2023, DyssolTEC GmbH.
 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#pragma once

#include "ui_FlowsheetViewer.h"
#include "GraphvizHandler.h"
#include "QtDialog.h"

class QSettings;
class CFlowsheet;
class QLabel;
class QScrollArea;

/*
 * Uses graphviz library to render flowsheet as a picture and shows it.
 */
class CFlowsheetViewer
	: public QDialog
	, public CDyssolBaseWidget
{
	Q_OBJECT

	Ui::CFlowsheetViewer ui{};

	const double MIN_SCALE       = 0.2;	// Minimum scale factor for showing image.
	const double MAX_SCALE       = 4.0;	// Maximum scale factor for showing image.
	const double DEFAULT_SCALE   = 1.0;	// Default scale factor for showing image.
	const double ZOOM_IN_FACTOR  = 1.1;	// Scaling factor for each zoom in step.
	const double ZOOM_OUT_FACTOR = 0.9;	// Scaling factor for each zoom out step.

	const CFlowsheet* m_flowsheet{};		// Pointer to flowsheet.
	QString m_imageFullName;				// Path and name to store temporary images.

	CGraphvizHandler m_graphBuilder{ m_flowsheet };	// Image builder.
	QImage m_image;									// Current image.
	double m_scaleFactor{ DEFAULT_SCALE };			// Current image scale factor relative to original size.
	QPoint m_lastMousePos;							// Last mouse position needed to track mouse movements.

public:
	CFlowsheetViewer(const CFlowsheet* _flowsheet, QWidget* _parent = nullptr);
	~CFlowsheetViewer() override;

	CFlowsheetViewer(const CFlowsheetViewer& _other)                = delete;
	CFlowsheetViewer(CFlowsheetViewer&& _other) noexcept            = delete;
	CFlowsheetViewer& operator=(const CFlowsheetViewer& _other)     = delete;
	CFlowsheetViewer& operator=(CFlowsheetViewer&& _other) noexcept = delete;

	void SetPointers(CFlowsheet* _flowsheet, CModelsManager* _modelsManager, QSettings* _settings) override;

	// Connects signals and slots.
	void InitializeConnections() const;

	// Changes visibility of this dialog.
	void setVisible(bool _visible) override;

	// Completely updates view using data from flowsheet.
	void Update();

private:
	// Creates main menu of the dialog.
	void CreateMenu();
	// Reaction on action Save As.
	void SaveAs();
	// Reaction on action Fit To Window.
	void FitToWindow();
	// Resize image according to given factor.
	void ScaleImage(double _factor);
	// Shows image with current scaling factor.
	void ShowImage() const;
	// Updates cursor view depending on the state of scroll bars.
	void UpdateCursor();
	// Checks if the shown image can be moved.
	[[nodiscard]] bool IsImageMovable() const;
	// Changes rendering style.
	void StyleChanged();

	// Load view settings.
	void LoadSettings();
	// Save view settings.
	void SaveSettings() const;

	void mouseMoveEvent(QMouseEvent* _event) override;
	void mousePressEvent(QMouseEvent* _event) override;
	void mouseReleaseEvent(QMouseEvent* _event) override;
	void wheelEvent(QWheelEvent* _event) override;
	void resizeEvent(QResizeEvent* _event) override;
	void changeEvent(QEvent* _event) override;
	bool eventFilter(QObject* _object, QEvent* _event) override;
};