From 4b915ab77f1c46143362ccca8a1622c46977e49f Mon Sep 17 00:00:00 2001 From: cfdev Date: Tue, 30 Apr 2013 10:25:05 +0000 Subject: [PATCH] Add an diagramselection widget git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2132 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/ui/diagramselection.cpp | 111 ++++++++++++++++++++++++++++++++ sources/ui/diagramselection.h | 51 +++++++++++++++ sources/ui/diagramselection.ui | 42 ++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 sources/ui/diagramselection.cpp create mode 100644 sources/ui/diagramselection.h create mode 100644 sources/ui/diagramselection.ui diff --git a/sources/ui/diagramselection.cpp b/sources/ui/diagramselection.cpp new file mode 100644 index 000000000..30e76fd70 --- /dev/null +++ b/sources/ui/diagramselection.cpp @@ -0,0 +1,111 @@ +/* + Copyright 2006-2013 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 . +*/ +#include "diagramselection.h" +#include "ui_diagramselection.h" + +diagramselection::diagramselection(QETProject *prj, QWidget *parent) : + QWidget(parent), + ui(new Ui::diagramselection) +{ + ui -> setupUi(this); + prj_ = prj; + // list all diagrams presents in project + list_diagram_ = prj_ -> diagrams(); + + ui -> label_prj -> setText( tr("Projet : ") + prj_ -> title() ); + load_TableDiagram(); +} + +diagramselection::~diagramselection() { + delete ui; +} + +/** + * @brief load all Diagrams of project in table + */ +void diagramselection::load_TableDiagram() { + // Clear all items + ui -> tableDiagram -> clear(); + for (int i=ui -> tableDiagram -> rowCount()-1; i >= 0; --i) { + ui -> tableDiagram->removeRow(i); + } + for (int i=ui -> tableDiagram -> columnCount()-1; i>=0; --i) { + ui -> tableDiagram->removeColumn(i); + } + + // Set the setting of table + ui -> tableDiagram -> setColumnCount(2); + ui -> tableDiagram -> setSelectionBehavior (QAbstractItemView::SelectRows); + ui -> tableDiagram -> setSelectionMode (QAbstractItemView::SingleSelection); + ui -> tableDiagram -> setEditTriggers (QAbstractItemView::NoEditTriggers); + QStringList titles; + titles.clear(); + titles << tr("Nom") << tr("S\351lection"); + ui-> tableDiagram -> setHorizontalHeaderLabels( titles ); + + // List Diagrams + for(int i=0,j=0; i setData(Qt::DisplayRole, list_diagram_.at(i) -> title() ); + item_State -> setData(Qt::CheckStateRole, Qt::Checked); + + ui -> tableDiagram -> setRowCount(j+1); + ui -> tableDiagram -> setItem(j, 0, item_Name); + ui -> tableDiagram -> setItem(j, 1, item_State); + } + ui -> tableDiagram -> resizeColumnsToContents(); +} + +/** + * @brief get list of Diagrams is selected + * @return this list of Diagrams + */ +QList diagramselection::list_of_DiagramSelected() { + QList listDiag; + for(int i=0; i tableDiagram -> rowCount();i++){ + if(ui -> tableDiagram -> item(i, 1)->checkState()){ + listDiag.push_back( list_diagram_[i] ); + } + } + + return listDiag; +} + +/** + * @brief contextMenuRequested + * @param pos + */ +void diagramselection::on_tableDiagram_customContextMenuRequested(const QPoint &pos){ + QMenu menu(this); + QAction *desl = menu.addAction( tr("D\351s\351lectionner tout") ); + QAction *sel = menu.addAction(QIcon(":/ico/16x16/dialog-ok.png"), tr("S\351lectionner tout") ); + + // Exec Menu + QAction *ret = menu.exec(ui -> tableDiagram -> viewport() -> mapToGlobal(pos)); + if (ret == desl) { + for(int i=0; i tableDiagram -> rowCount();i++) + ui -> tableDiagram -> item(i, 1)->setCheckState(Qt::Unchecked); + } + else{ + for(int i=0; i tableDiagram -> rowCount();i++) + ui -> tableDiagram -> item(i, 1)->setCheckState(Qt::Checked); + } +} + diff --git a/sources/ui/diagramselection.h b/sources/ui/diagramselection.h new file mode 100644 index 000000000..ffb49c8ea --- /dev/null +++ b/sources/ui/diagramselection.h @@ -0,0 +1,51 @@ +/* + Copyright 2006-2013 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 . +*/ +#ifndef DIAGRAMSELECTION_H +#define DIAGRAMSELECTION_H + +#include + +#include "diagram.h" +#include "qetproject.h" + +namespace Ui { + class diagramselection; +} + +class diagramselection : public QWidget +{ + Q_OBJECT + + public: + explicit diagramselection(QETProject *prj, QWidget *parent = 0); + ~diagramselection(); + + QList list_of_DiagramSelected(); + + private slots: + void on_tableDiagram_customContextMenuRequested(const QPoint &pos); + + private: + Ui::diagramselection *ui; + QETProject *prj_; + QList list_diagram_; + + void load_TableDiagram(); +}; + +#endif // DIAGRAMSELECTION_H diff --git a/sources/ui/diagramselection.ui b/sources/ui/diagramselection.ui new file mode 100644 index 000000000..0a1e6459a --- /dev/null +++ b/sources/ui/diagramselection.ui @@ -0,0 +1,42 @@ + + + diagramselection + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + TextLabel + + + + + + + Qt::CustomContextMenu + + + QFrame::StyledPanel + + + + + + + + + +