2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2012-01-01 22:51:51 +00:00
|
|
|
Copyright 2006-2012 Xavier Guerrin
|
2007-12-01 10:47:15 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
2007-04-04 02:13:14 +00:00
|
|
|
#include "elementscategorieslist.h"
|
2007-09-21 13:22:18 +00:00
|
|
|
#include "qetapp.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "customelement.h"
|
|
|
|
#include "elementscollection.h"
|
2007-04-05 01:13:14 +00:00
|
|
|
#include "elementscategory.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementdefinition.h"
|
2009-05-01 14:41:33 +00:00
|
|
|
#include "qeticons.h"
|
2007-04-04 02:13:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2009-04-03 19:30:25 +00:00
|
|
|
@param display_elements true pour afficher les elements, false sinon
|
|
|
|
@param selectables Types selectionnables
|
|
|
|
@see QET::ItemType
|
2007-04-04 02:13:14 +00:00
|
|
|
@param parent QWidget parent de ce widget
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementsCategoriesList::ElementsCategoriesList(bool display_elements, uint selectables, QWidget *parent) :
|
2012-02-06 21:21:43 +00:00
|
|
|
GenericPanel(parent),
|
2009-04-03 19:30:25 +00:00
|
|
|
display_elements_(display_elements),
|
|
|
|
selectables_(selectables),
|
|
|
|
first_load(true)
|
|
|
|
{
|
2007-04-04 02:13:14 +00:00
|
|
|
// selection unique
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
setColumnCount(1);
|
|
|
|
|
|
|
|
// charge les categories
|
2012-02-06 21:21:43 +00:00
|
|
|
setElementsCache(QETApp::collectionCache());
|
2007-04-04 02:13:14 +00:00
|
|
|
reload();
|
2009-04-03 19:30:25 +00:00
|
|
|
|
2012-02-06 21:21:43 +00:00
|
|
|
connect(
|
|
|
|
this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
|
|
|
this, SLOT(selectionChanged(QTreeWidgetItem *, QTreeWidgetItem *))
|
|
|
|
);
|
2007-04-04 02:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructeur
|
|
|
|
*/
|
|
|
|
ElementsCategoriesList::~ElementsCategoriesList() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Recharge l'arbre des categories
|
|
|
|
*/
|
|
|
|
void ElementsCategoriesList::reload() {
|
2012-02-06 21:21:43 +00:00
|
|
|
GenericPanel::PanelOptions options = display_elements_ ? GenericPanel::AddAllChildElements : GenericPanel::AddChildElementsContainers;
|
|
|
|
options |= GenericPanel::DisplayElementsPreview;
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
foreach(ElementsCollection *collection, QETApp::availableCollections()) {
|
|
|
|
if (collection == QETApp::commonElementsCollection()) continue;
|
|
|
|
if (collection == QETApp::customElementsCollection()) continue;
|
2012-02-06 21:21:43 +00:00
|
|
|
addElementsCollection(collection, invisibleRootItem(), options, tr("Collection projet")) -> setExpanded(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
2007-04-04 02:13:14 +00:00
|
|
|
|
2007-12-18 21:19:41 +00:00
|
|
|
// chargement des elements de la collection commune si droits d'ecriture
|
2009-04-03 19:30:25 +00:00
|
|
|
if (QETApp::commonElementsCollection() -> isWritable()) {
|
2012-02-06 21:21:43 +00:00
|
|
|
addElementsCollection(
|
|
|
|
QETApp::commonElementsCollection(),
|
|
|
|
invisibleRootItem(),
|
|
|
|
options,
|
|
|
|
tr("Collection QET"),
|
|
|
|
QIcon(":/ico/16x16/qet.png")
|
|
|
|
) -> setExpanded(true);
|
2007-12-18 21:19:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 02:13:14 +00:00
|
|
|
// chargement des elements de la collection utilisateur
|
2012-02-06 21:21:43 +00:00
|
|
|
addElementsCollection(
|
|
|
|
QETApp::customElementsCollection(),
|
|
|
|
invisibleRootItem(),
|
|
|
|
options,
|
|
|
|
tr("Collection utilisateur"),
|
|
|
|
QIcon(":/ico/16x16/go-home.png")
|
|
|
|
) -> setExpanded(true);
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
if (first_load) first_load = false;
|
2007-04-04 02:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-06 21:21:43 +00:00
|
|
|
Create a QTreeWidgetItem
|
|
|
|
@param type Item type (e.g QET::Diagram, QET::Project, ...)
|
|
|
|
@param parent Parent for the created item
|
|
|
|
@param label Label for the created item
|
|
|
|
@param icon Icon for the created item
|
|
|
|
@return the create QTreeWidgetItem
|
2007-04-04 02:13:14 +00:00
|
|
|
*/
|
2012-02-06 21:21:43 +00:00
|
|
|
QTreeWidgetItem *ElementsCategoriesList::makeItem(QET::ItemType type, QTreeWidgetItem *parent, const QString &label, const QIcon &icon) {
|
|
|
|
QTreeWidgetItem *item = GenericPanel::makeItem(type, parent, label, icon);
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsEnabled;
|
|
|
|
if (selectables_ & item -> type()) flags |= Qt::ItemIsSelectable;
|
|
|
|
item -> setFlags(flags);
|
|
|
|
return(item);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return l'emplacement correspondant au QTreeWidgetItem selectionne
|
|
|
|
*/
|
|
|
|
ElementsLocation ElementsCategoriesList::selectedLocation() const {
|
2012-02-06 21:21:43 +00:00
|
|
|
QTreeWidgetItem *current_qtwi = currentItem();
|
|
|
|
if (!current_qtwi) return(ElementsLocation());
|
|
|
|
return(valueForItem<ElementsLocation>(current_qtwi));
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Selectionne un element dans la liste a partir de son emplacement
|
|
|
|
@see ElementsLocation
|
|
|
|
@param location Emplacement a selectionner
|
|
|
|
@return true si la selection a pu etre effectuee, false sinon
|
|
|
|
*/
|
|
|
|
bool ElementsCategoriesList::selectLocation(const ElementsLocation &location) {
|
2012-02-06 21:21:43 +00:00
|
|
|
QTreeWidgetItem *qtwi = itemForElementsLocation(location);
|
|
|
|
if (qtwi) setCurrentItem(qtwi);
|
|
|
|
return(qtwi);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Recupere le chemin virtuel de l'element selectionne et emet le signal
|
|
|
|
virtualPathChanged.
|
|
|
|
@param current QTreeWidgetItem selectionne
|
|
|
|
@param previous QTreeWidgetItem precedemment selectionne
|
|
|
|
*/
|
2009-11-22 16:12:22 +00:00
|
|
|
void ElementsCategoriesList::selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) {
|
|
|
|
Q_UNUSED(previous);
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementsLocation emited_location;
|
|
|
|
if (current) {
|
2012-02-06 21:21:43 +00:00
|
|
|
emited_location = valueForItem<ElementsLocation>(current);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
emit(locationChanged(emited_location));
|
2007-04-04 02:13:14 +00:00
|
|
|
}
|