QElectroTech  0.70
diagramselection.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "diagramselection.h"
19 #include "ui_diagramselection.h"
20 
22  QWidget(parent),
23  ui(new Ui::diagramselection),
24  prj_ (prj),
25  list_diagram_ (prj -> diagrams())
26 {
27  ui -> setupUi(this);
28 
29  QString project_title = prj_ -> title();
30  if (project_title.isEmpty()) project_title = tr("Projet sans titre");
31 
32  ui -> label_prj -> setText( tr("Projet : ") + project_title );
34 }
35 
37  delete ui;
38 }
39 
44  // Clear all items
45  ui -> tableDiagram -> clear();
46  for (int i=ui -> tableDiagram -> rowCount()-1; i >= 0; --i) {
47  ui -> tableDiagram->removeRow(i);
48  }
49  for (int i=ui -> tableDiagram -> columnCount()-1; i>=0; --i) {
50  ui -> tableDiagram->removeColumn(i);
51  }
52 
53  // Set the setting of table
54  ui -> tableDiagram -> setColumnCount(2);
55  ui -> tableDiagram -> setSelectionBehavior (QAbstractItemView::SelectRows);
56  ui -> tableDiagram -> setSelectionMode (QAbstractItemView::SingleSelection);
57  ui -> tableDiagram -> setEditTriggers (QAbstractItemView::NoEditTriggers);
58  QStringList titles;
59  titles.clear();
60  titles << tr("Sélection") << tr("Nom");
61  ui-> tableDiagram -> setHorizontalHeaderLabels( titles );
62 
63  // List Diagrams
64  for(int i=0,j=0; i<list_diagram_.count(); i++,j++){
65  QTableWidgetItem *item_Name = new QTableWidgetItem();
66  QTableWidgetItem *item_State = new QTableWidgetItem();
67 
68  QString diagram_title = list_diagram_.at(i) -> title();
69  if (diagram_title.isEmpty()) diagram_title = tr("Folio sans titre");
70 
71  item_Name -> setData(Qt::DisplayRole, diagram_title);
72  item_State -> setData(Qt::CheckStateRole, Qt::Checked);
73 
74  ui -> tableDiagram -> setRowCount(j+1);
75  ui -> tableDiagram -> setItem(j, 0, item_State);
76  ui -> tableDiagram -> setItem(j, 1, item_Name);
77 
78  }
79  ui -> tableDiagram -> horizontalHeader() -> setStretchLastSection(true);
80 }
81 
87  QList<Diagram *> listDiag;
88  for(int i=0; i<ui -> tableDiagram -> rowCount();i++){
89  if(ui -> tableDiagram -> item(i, 0)->checkState()){
90  listDiag.push_back( list_diagram_[i] );
91  }
92  }
93  return listDiag;
94 }
95 
101  QMenu menu(this);
102  QAction *desl = menu.addAction( tr("Désélectionner tout") );
103  menu.addAction(QIcon(":/ico/16x16/dialog-ok.png"), tr("Sélectionner tout") );
104 
105  // Exec Menu
106  QAction *ret = menu.exec(ui -> tableDiagram -> viewport() -> mapToGlobal(pos));
107  if (ret == desl) {
108  for(int i=0; i<ui -> tableDiagram -> rowCount();i++)
109  ui -> tableDiagram -> item(i, 0)->setCheckState(Qt::Unchecked);
110  }
111  else{
112  for(int i=0; i<ui -> tableDiagram -> rowCount();i++)
113  ui -> tableDiagram -> item(i, 0)->setCheckState(Qt::Checked);
114  }
115 }
116 
~diagramselection() override
Ui::diagramselection * ui
QList< Diagram * > list_of_DiagramSelected()
get list of Diagrams is selected
void load_TableDiagram()
load all Diagrams of project in table
QIcon tr
Definition: qeticons.cpp:204
QList< Diagram * > list_diagram_
diagramselection(QETProject *prj, QWidget *parent=nullptr)
QETProject * prj_
void on_tableDiagram_customContextMenuRequested(const QPoint &pos)
contextMenuRequested