File: diagrampropertiesdialog.cpp

package info (click to toggle)
qelectrotech 1%3A0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 144,968 kB
  • sloc: cpp: 93,465; xml: 711; sh: 546; perl: 316; makefile: 6
file content (160 lines) | stat: -rw-r--r-- 5,744 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
	Copyright 2006-2023 The QElectroTech Team
	This file is part of QElectroTech.

	QElectroTech is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	QElectroTech is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "diagrampropertiesdialog.h"

#include "../diagram.h"
#include "../diagramcommands.h"
#include "../undocommand/changetitleblockcommand.h"
#include "borderpropertieswidget.h"
#include "conductorpropertieswidget.h"
#include "projectpropertiesdialog.h"
#include "titleblockpropertieswidget.h"

/**
	@brief DiagramPropertiesDialog::DiagramPropertiesDialog
	Default constructor
	@param diagram : diagram to edit properties
	@param parent : parent widget
*/
DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *parent) :
	QDialog (parent),
	m_diagram (diagram)
{
	bool diagram_is_read_only = diagram -> isReadOnly();

	// Get some properties of edited diagram
	TitleBlockProperties titleblock = diagram -> border_and_titleblock.exportTitleBlock();
	BorderProperties     border     = diagram -> border_and_titleblock.exportBorder();
	ConductorProperties  conductors = diagram -> defaultConductorProperties;

	setWindowModality(Qt::WindowModal);
#ifdef Q_OS_MACOS
	setWindowFlags(Qt::Sheet);
#endif

	setWindowTitle(tr("Propriétés du folio", "window title"));

	//Border widget
	BorderPropertiesWidget *border_infos = new BorderPropertiesWidget(border, this);
	border_infos -> setReadOnly(diagram_is_read_only);

	//Title block widget
	TitleBlockPropertiesWidget  *titleblock_infos;

	if (QETProject *parent_project = diagram -> project())
		titleblock_infos  = new TitleBlockPropertiesWidget(parent_project -> embeddedTitleBlockTemplatesCollection(), titleblock, false, diagram->project(),  this);
	else
		titleblock_infos = new TitleBlockPropertiesWidget(titleblock, false, diagram->project(), this);

	titleblock_infos -> setReadOnly(diagram_is_read_only);
	connect(titleblock_infos,SIGNAL(openAutoNumFolioEditor(QString)),this,SLOT(editAutoFolioNum()));
	//titleblock_infos->setMinimumSize(590,480); //Minimum Size needed for correct display

		//Conductor widget
	m_cpw = new ConductorPropertiesWidget(conductors, this);
	m_cpw -> setReadOnly(diagram_is_read_only);

	QComboBox *autonum_combobox = m_cpw->autonumComboBox();
	autonum_combobox->addItems(diagram->project()->conductorAutoNum().keys());
	autonum_combobox->setCurrentIndex(autonum_combobox->findText(diagram->conductorsAutonumName()));

	connect(m_cpw->editAutonumPushButton(), &QPushButton::clicked, this, &DiagramPropertiesDialog::editAutonum);

		// Buttons
	QDialogButtonBox boutons(diagram_is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
	connect(&boutons, SIGNAL(accepted()), this, SLOT(accept()));
	connect(&boutons, SIGNAL(rejected()), this, SLOT(reject()));

	QGridLayout *glayout = new QGridLayout;
	glayout->addWidget(border_infos,0,0);
	glayout->addWidget(titleblock_infos, 1, 0);
	glayout->addWidget(m_cpw, 0, 1, 0, 1);

	QVBoxLayout vlayout(this);
	vlayout.addLayout(glayout);
	vlayout.addWidget(&boutons);

	// if dialog is accepted
	if (this -> exec() == QDialog::Accepted && !diagram_is_read_only)
	{
		TitleBlockProperties new_titleblock = titleblock_infos  -> properties();
		BorderProperties     new_border     = border_infos -> properties();
		ConductorProperties  new_conductors = m_cpw -> properties();

		// Title block have change
		if (new_titleblock != titleblock) {
			diagram -> undoStack().push(new ChangeTitleBlockCommand(diagram, titleblock, new_titleblock));
		}

		// Border have change
		if (new_border != border) {
			diagram -> undoStack().push(new ChangeBorderCommand(diagram, border, new_border));
		}

		// Conducteur have change
		if (new_conductors != conductors) {
#if TODO_LIST
#pragma message("@TODO implement an undo command to allow the user to undo/redo this action")
#endif
			/// TODO implement an undo command to allow the user to undo/redo this action
			diagram -> defaultConductorProperties = new_conductors;
		}

			// Conductor autonum name
		if (autonum_combobox->currentText() != diagram->conductorsAutonumName())
		{
			diagram->setConductorsAutonumName (autonum_combobox->currentText());
			diagram->project()->conductorAutoNumChanged();
		}
	}
}

/**
	@brief DiagramPropertiesDialog::diagramPropertiesDialog
	Static method to get a DiagramPropertiesDialog.
	@param diagram : diagram to edit properties
	@param parent : parent widget
*/
void DiagramPropertiesDialog::diagramPropertiesDialog(Diagram *diagram, QWidget *parent) {
	DiagramPropertiesDialog dialog(diagram, parent);
}

/**
	@brief DiagramPropertiesDialog::editAutonum
	Open conductor autonum editor
*/
void DiagramPropertiesDialog::editAutonum()
{
	ProjectPropertiesDialog ppd (m_diagram->project(), this);
	ppd.setCurrentPage(ProjectPropertiesDialog::Autonum);
	ppd.exec();
	m_cpw->autonumComboBox()->clear();
	m_cpw->autonumComboBox()->addItems(m_diagram->project()->conductorAutoNum().keys());
}

/**
	@brief DiagramPropertiesDialog::editAutonum
	Open folio autonum editor
*/
void DiagramPropertiesDialog::editAutoFolioNum ()
{
	ProjectPropertiesDialog ppd (m_diagram->project(), this);
	ppd.setCurrentPage(ProjectPropertiesDialog::Autonum);
	ppd.changeToFolio();
	ppd.exec();
}