Replace the class folioReportProperties by the class linkSingleElementWidget.

The new class does the same thing but is more flexible, this class is used by report and slave element
to find element to be linked and/or unlink an already linked element.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2921 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-03-12 09:32:56 +00:00
parent cbbd9354cf
commit b74c5804be
15 changed files with 585 additions and 332 deletions

View File

@@ -0,0 +1,116 @@
/*
Copyright 2006-2014 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 "elementselectorwidget.h"
#include "ui_elementselectorwidget.h"
#include "diagramposition.h"
#include "qeticons.h"
/**
* @brief ElementSelectorWidget::ElementSelectorWidget
* Default constructor
* @param elmt_list
* List of element to be displayed by the selector
* @param parent
* Parent widget
*/
ElementSelectorWidget::ElementSelectorWidget(QList <Element *> elmt_list, QWidget *parent) :
QWidget(parent),
ui(new Ui::ElementSelectorWidget),
elements_list(elmt_list),
selected_element(0),
showed_element(0)
{
ui->setupUi(this);
buildInterface();
}
/**
* @brief ElementSelectorWidget::~ElementSelectorWidget
* Default destructor
*/
ElementSelectorWidget::~ElementSelectorWidget()
{
if (showed_element) showed_element->setHighlighted(false);
delete ui;
}
/**
* @brief ElementSelectorWidget::showElement
* Show the element given by parametre
* @param elmt
*/
void ElementSelectorWidget::showElement(Element *elmt) {
if (showed_element) showed_element->setHighlighted(false);
elmt->diagram()->showMe();
elmt->setHighlighted(true);
showed_element = elmt;
}
/**
* @brief ElementSelectorWidget::buildInterface
* Build interface of this widget (fill all available element)
*/
void ElementSelectorWidget::buildInterface() {
//Setup the signal mapper
int map_id = 0; //this int is used to map the signal
sm_ = new QSignalMapper(this);
connect(sm_, SIGNAL(mapped(int)), this, SLOT(setSelectedElement(int)));
sm_show_ = new QSignalMapper(this);
connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showElementFromList(int)));
//Build the list
foreach (Element *elmt, elements_list) {
//label for the button
QString button_text;
QString title = elmt->diagram()->title();
if (title.isEmpty()) title = tr("Sans titre");
button_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
.arg(title)
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
//add the button himself
QHBoxLayout *hl = new QHBoxLayout();
QRadioButton *rb = new QRadioButton(button_text , this);
QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", this);
pb->setToolTip(tr("Voir l'\351l\351ment"));
hl->addWidget(rb);
hl->addStretch();
hl->addWidget(pb);
ui->scroll_layout_->addLayout(hl);
//map the radio button signal
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
sm_ -> setMapping(rb, map_id);
//map the push button show diagram
connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map()));
sm_show_->setMapping(pb, map_id);
map_id++; //increase the map_id for next button.
}
ui->scroll_layout_->addStretch();
}
/**
* @brief ElementSelectorWidget::showElementFromList
* Show the element at the position i in @elements_list
* @param i
*/
void ElementSelectorWidget::showElementFromList(const int i) {
if (elements_list.size() >= i)
showElement(elements_list.at(i));
}