Old element panel : Remove the management of the elements collection. Now the element panel only manage the title block and folio.

Remove the management of custom and common elements collection in the class qetapp. 


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4529 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-05-27 12:44:24 +00:00
parent 1ec0538e71
commit ef555c5424
11 changed files with 15 additions and 1307 deletions

View File

@@ -19,14 +19,8 @@
#include "qetapp.h"
#include "qetproject.h"
#include "diagram.h"
#include "elementscategory.h"
#include "elementscollectioncache.h"
#include "factory/elementfactory.h"
#include "fileelementscollection.h"
#include "fileelementdefinition.h"
#include "qeticons.h"
#include "templatescollection.h"
#include "element.h"
/*
Lorsque le flag ENABLE_PANEL_DND_CHECKS est defini, le panel d'elements
@@ -38,26 +32,12 @@
*/
#define ENABLE_PANEL_DND_CHECKS
/*
Largeur maximale, en pixels, de la pixmap accrochee au pointeur de la
souris
*/
#define QET_MAX_DND_PIXMAP_WIDTH 500
/*
Hauteur maximale, en pixels, de la pixmap accrochee au pointeur de la
souris
*/
#define QET_MAX_DND_PIXMAP_HEIGHT 375
/**
Constructeur
@param parent Le QWidget parent du panel d'appareils
*/
ElementsPanel::ElementsPanel(QWidget *parent) :
GenericPanel(parent),
common_collection_item_(0),
custom_collection_item_(0),
first_reload_(true)
{
// selection unique
@@ -89,8 +69,6 @@ ElementsPanel::ElementsPanel(QWidget *parent) :
//Emit a signal instead au manage is own context menu
setContextMenuPolicy(Qt::CustomContextMenu);
setElementsCache(QETApp::collectionCache());
}
/**
@@ -99,41 +77,6 @@ ElementsPanel::ElementsPanel(QWidget *parent) :
ElementsPanel::~ElementsPanel() {
}
/**
@param qtwi Un QTreeWidgetItem
@return true si qtwi represente un element, false sinon
*/
bool ElementsPanel::itemIsWritable(QTreeWidgetItem *qtwi) const {
if (ElementsCollectionItem *qtwi_item = collectionItemForItem(qtwi)) {
return(qtwi_item -> isWritable());
}
return(false);
}
/**
@return true si l'item selectionne est accessible en ecriture, false sinon
*/
bool ElementsPanel::selectedItemIsWritable() const {
if (ElementsCollectionItem *selected_item = selectedItem()) {
return(selected_item -> isWritable());
}
return(false);
}
/**
@return la collection, la categorie ou l'element selectionne(e)
*/
ElementsCollectionItem *ElementsPanel::selectedItem() const {
ElementsLocation selected_location(selectedElementLocation());
if (!selected_location.isNull()) {
return(QETApp::collectionItem(selected_location));
}
return(0);
}
/**
Gere l'entree d'un drag'n drop. L'evenement est accepte si les donnees
fournies contiennent un type MIME representant une categorie ou un element
@@ -148,71 +91,12 @@ void ElementsPanel::dragEnterEvent(QDragEnterEvent *e) {
}
}
/**
Gere le mouvement lors d'un drag'n drop
*/
void ElementsPanel::dragMoveEvent(QDragMoveEvent *e)
{
// scrolle lorsque le curseur est pres des bords
int limit = 40;
QScrollBar *scroll_bar = verticalScrollBar();
if (e -> pos().y() < limit) {
scroll_bar -> setValue(scroll_bar -> value() - 1);
} else if (e -> pos().y() > height() - limit) {
scroll_bar -> setValue(scroll_bar -> value() + 1);
}
QTreeWidget::dragMoveEvent(e);
// recupere la categorie cible pour le deplacement / la copie
ElementsCategory *target_category = categoryForPos(e -> pos());
if (!target_category) {
e -> ignore();
return;
}
// recupere la source (categorie ou element) pour le deplacement / la copie
ElementsLocation dropped_location = ElementsLocation(e -> mimeData() -> text());
ElementsCollectionItem *source_item = QETApp::collectionItem(dropped_location, false);
if (!source_item) {
e -> ignore();
return;
}
#ifdef ENABLE_PANEL_DND_CHECKS
// ne prend pas en consideration le drop d'un item sur lui-meme ou une categorie imbriquee
if (
source_item -> location() == target_category -> location() ||\
target_category -> isChildOf(source_item)
) {
e -> ignore();
return;
}
// s'assure que la categorie cible est accessible en ecriture
if (!target_category -> isWritable()) {
e -> ignore();
return;
}
#endif
e -> accept();
/// @todo mettre en valeur le lieu de depot
}
/**
Gere le debut des drag'n drop
@param supportedActions Les actions supportees
*/
void ElementsPanel::startDrag(Qt::DropActions supportedActions) {
Q_UNUSED(supportedActions);
// recupere l'emplacement selectionne
ElementsLocation element_location = selectedElementLocation();
if (!element_location.isNull()) {
startElementDrag(element_location);
return;
}
TitleBlockTemplateLocation tbt_location = selectedTemplateLocation();
if (tbt_location.isValid()) {
@@ -221,63 +105,6 @@ void ElementsPanel::startDrag(Qt::DropActions supportedActions) {
}
}
/**
Handle the dragging of an element.
@param location Location of the dragged element
*/
void ElementsPanel::startElementDrag(const ElementsLocation &location) {
// recupere la selection
ElementsCollectionItem *selected_item = QETApp::collectionItem(location);
if (!selected_item) return;
// objet QDrag pour realiser le drag'n drop
QDrag *drag = new QDrag(this);
// donnees qui seront transmises par le drag'n drop
QString location_string(location.toString());
QMimeData *mimeData = new QMimeData();
mimeData -> setText(location_string);
if (selected_item -> isCategory() || selected_item -> isCollection()) {
mimeData -> setData("application/x-qet-category-uri", location_string.toLatin1());
drag -> setPixmap(QET::Icons::Folder.pixmap(22, 22));
} else if (selected_item -> isElement()) {
mimeData -> setData("application/x-qet-element-uri", location_string.toLatin1());
// element temporaire pour fournir un apercu
int elmt_creation_state;
Element *temp_elmt = ElementFactory::Instance() -> createElement(location, 0, &elmt_creation_state);
if (elmt_creation_state) {
delete temp_elmt;
return;
}
// accrochage d'une pixmap representant l'appareil au pointeur
QPixmap elmt_pixmap(temp_elmt -> pixmap());
QPoint elmt_hotspot(temp_elmt -> hotspot());
// ajuste la pixmap si celle-ci est trop grande
QPoint elmt_pixmap_size(elmt_pixmap.width(), elmt_pixmap.height());
if (elmt_pixmap.width() > QET_MAX_DND_PIXMAP_WIDTH || elmt_pixmap.height() > QET_MAX_DND_PIXMAP_HEIGHT) {
elmt_pixmap = elmt_pixmap.scaled(QET_MAX_DND_PIXMAP_WIDTH, QET_MAX_DND_PIXMAP_HEIGHT, Qt::KeepAspectRatio);
elmt_hotspot = QPoint(
elmt_hotspot.x() * elmt_pixmap.width() / elmt_pixmap_size.x(),
elmt_hotspot.y() * elmt_pixmap.height() / elmt_pixmap_size.y()
);
}
drag -> setPixmap(elmt_pixmap);
drag -> setHotSpot(elmt_hotspot);
// suppression de l'appareil temporaire
delete temp_elmt;
}
// realisation du drag'n drop
drag -> setMimeData(mimeData);
drag -> start(Qt::MoveAction | Qt::CopyAction);
}
/**
Handle the dragging of a title block template
@param location Location of the dragged template.
@@ -333,21 +160,6 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project) {
return(qtwi_project);
}
/**
Methode privee permettant d'ajouter une collection d'elements au panel d'elements
@param qtwi_parent QTreeWidgetItem parent sous lequel sera insere la collection d'elements
@param collection Collection a inserer dans le panel d'elements - si
collection vaut 0, cette methode retourne 0.
@param coll_name Nom a utiliser pour la collection
@param icon Icone a utiliser pour l'affichage de la collection
@return Le QTreeWidgetItem insere le plus haut
*/
QTreeWidgetItem *ElementsPanel::addCollection(ElementsCollection *collection) {
PanelOptions options = GenericPanel::AddAllChild;
options |= GenericPanel::DisplayElementsPreview;
return(addElementsCollection(collection, invisibleRootItem(), options));
}
QTreeWidgetItem *ElementsPanel::updateTemplatesCollectionItem(QTreeWidgetItem *tbt_collection_qtwi, TitleBlockTemplatesCollection *tbt_collection, PanelOptions options, bool freshly_created) {
QTreeWidgetItem *tbtc_qtwi = GenericPanel::updateTemplatesCollectionItem(tbt_collection_qtwi, tbt_collection, options, freshly_created);
if (tbt_collection && tbt_collection -> parentProject()) {
@@ -369,43 +181,6 @@ QTreeWidgetItem *ElementsPanel::updateTemplateItem(QTreeWidgetItem *tb_template_
return(item);
}
QTreeWidgetItem *ElementsPanel::updateElementsCategoryItem(QTreeWidgetItem *category_qtwi, ElementsCategory *category, PanelOptions options, bool freshly_created) {
QTreeWidgetItem *item = GenericPanel::updateElementsCategoryItem(category_qtwi, category, options, freshly_created);
item -> setStatusTip(
0,
tr(
"Double-cliquez pour réduire ou développer cette catégorie d'éléments",
"Status tip displayed by elements category"
)
);
emit(loadingProgressed(++ loading_progress_, -1));
return(item);
}
QTreeWidgetItem *ElementsPanel::updateElementsCollectionItem(QTreeWidgetItem *collection_qtwi, ElementsCollection *collection, PanelOptions options, bool freshly_created) {
QTreeWidgetItem *c_qtwi = GenericPanel::updateElementsCollectionItem(collection_qtwi, collection, options, freshly_created);
if (collection && collection -> project()) {
c_qtwi -> setText(0, tr("Collection embarquée"));
c_qtwi -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer cette collection d'éléments embarquée", "Status tip"));
}
return(c_qtwi);
}
QTreeWidgetItem *ElementsPanel::updateElementItem(QTreeWidgetItem *element_qtwi, ElementDefinition *element, PanelOptions options, bool freshly_created) {
QTreeWidgetItem *item = GenericPanel::updateElementItem(element_qtwi, element, options, freshly_created);
QString status_tip = tr(
"Glissez-déposez cet élément « %1 » sur un folio pour l'y insérer, double-cliquez dessus pour l'éditer",
"Status tip displayed in the status bar when selecting an element"
);
item -> setStatusTip(0, status_tip.arg(item -> text(0)));
item -> setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
emit(loadingProgressed(++ loading_progress_, -1));
return(item);
}
/**
@return true if \a item matches the current filter, false otherwise
*/
@@ -434,50 +209,18 @@ bool ElementsPanel::matchesFilter(const QTreeWidgetItem *item, QString filter) c
return(item_matches);
}
/**
Reloads the following collections:
* common collection
* custom collection
* collection of every project displayed in this panel
*/
void ElementsPanel::reloadCollections() {
QETApp::commonElementsCollection() -> reload();
QETApp::customElementsCollection() -> reload();
}
/**
@return the count of categories and elements within the following collections:
* common collection
* custom collection
* collection of every project displayed in this panel
*/
int ElementsPanel::elementsCollectionItemsCount() {
int items_count = 0;
items_count += QETApp::commonElementsCollection() -> count();
items_count += QETApp::customElementsCollection() -> count();
return(items_count);
}
/**
* @brief ElementsPanel::reload
* Reload the elements tree
* @param reload_collections true for read all collections since their sources (files, projects ...)
*/
void ElementsPanel::reload(bool reload_collections) {
if (reload_collections) {
emit(readingAboutToBegin());
reloadCollections();
emit(readingFinished());
}
Q_UNUSED(reload_collections);
QIcon system_icon(":/ico/16x16/qet.png");
QIcon user_icon(":/ico/16x16/go-home.png");
// estimates the number of categories and elements to load
int items_count = elementsCollectionItemsCount();
emit(loadingProgressed(loading_progress_ = 0, items_count));
// load the common title block templates collection
TitleBlockTemplatesCollection *common_tbt_collection = QETApp::commonTitleBlockTemplatesCollection();
common_tbt_collection_item_ = addTemplatesCollection(common_tbt_collection, invisibleRootItem());
@@ -486,16 +229,6 @@ void ElementsPanel::reload(bool reload_collections) {
common_tbt_collection_item_ -> setWhatsThis(0, tr("Ceci est la collection de cartouches fournie avec QElectroTech. Installée en tant que composant système, vous ne pouvez normalement pas la personnaliser.", "\"What's this\" tip"));
if (first_reload_) common_tbt_collection_item_ -> setExpanded(true);
// load the common elements collection
if (QETApp::commonElementsCollection() -> rootCategory()) {
// first check local
QETApp::commonElementsCollection()->cache()->setLocale(QETApp::langFromSetting());
common_collection_item_ = addCollection(QETApp::commonElementsCollection());
common_collection_item_ -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer la collection d'éléments QElectroTech", "Status tip"));
common_collection_item_ -> setWhatsThis(0, tr("Ceci est la collection d'éléments fournie avec QElectroTech. Installée en tant que composant système, vous ne pouvez normalement pas la personnaliser.", "\"What's this\" tip"));
if (first_reload_) common_collection_item_ -> setExpanded(true);
}
// load the custom title block templates collection
TitleBlockTemplatesCollection *custom_tbt_collection = QETApp::customTitleBlockTemplatesCollection();
custom_tbt_collection_item_ = addTemplatesCollection(custom_tbt_collection, invisibleRootItem());
@@ -504,16 +237,6 @@ void ElementsPanel::reload(bool reload_collections) {
custom_tbt_collection_item_ -> setWhatsThis(0, tr("Ceci est votre collection personnelle de cartouches -- utilisez-la pour créer, stocker et éditer vos propres cartouches.", "\"What's this\" tip"));
if (first_reload_) custom_tbt_collection_item_ -> setExpanded(true);
// load the custom elements collection
if (QETApp::customElementsCollection() -> rootCategory()) {
// first check local
QETApp::customElementsCollection()->cache()->setLocale(QETApp::langFromSetting());
custom_collection_item_ = addCollection(QETApp::customElementsCollection());
custom_collection_item_ -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer votre collection personnelle d'éléments", "Status tip"));
custom_collection_item_ -> setWhatsThis(0, tr("Ceci est votre collection personnelle d'éléments -- utilisez-la pour créer, stocker et éditer vos propres éléments.", "\"What's this\" tip"));
if (first_reload_) custom_collection_item_ -> setExpanded(true);
}
// add projects
foreach(QETProject *project, projects_to_display_.values()) {
addProject(project);
@@ -521,8 +244,6 @@ void ElementsPanel::reload(bool reload_collections) {
// the first time, expand the first level of collections
if (first_reload_) first_reload_ = false;
emit(loadingFinished());
}
/**
@@ -531,8 +252,6 @@ void ElementsPanel::reload(bool reload_collections) {
est emis.
Si un double-clic sur un schema est effectue, le signal requestForDiagram
est emis.
Si un double-clic sur une collection, une categorie ou un element est
effectue, le signal requestForCollectionItem est emis.
@param qtwi
*/
void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) {
@@ -543,64 +262,12 @@ void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) {
} else if (qtwi_type == QET::Diagram) {
Diagram *diagram = valueForItem<Diagram *>(qtwi);
emit(requestForDiagram(diagram));
} else if (qtwi_type & QET::ElementsCollectionItem) {
ElementsLocation element = valueForItem<ElementsLocation>(qtwi);
emit(requestForCollectionItem(element));
} else if (qtwi_type == QET::TitleBlockTemplate) {
TitleBlockTemplateLocation tbt = valueForItem<TitleBlockTemplateLocation>(qtwi);
emit(requestForTitleBlockTemplate(tbt));
}
}
/**
@param qtwi Un QTreeWidgetItem
@return L'ElementsCollectionItem represente par qtwi, ou 0 si qtwi ne
represente pas un ElementsCollectionItem
*/
ElementsCollectionItem *ElementsPanel::collectionItemForItem(QTreeWidgetItem *qtwi) const {
if (qtwi && qtwi -> type() & QET::ElementsCollectionItem) {
ElementsLocation item_location = elementLocationForItem(qtwi);
return(QETApp::collectionItem(item_location));
}
return(0);
}
/**
Cette methode permet d'acceder a la categorie correspondant a un item donne.
Si cet item represente une collection, c'est sa categorie racine qui est renvoyee.
Si cet item represente une categorie, c'est cette categorie qui est renvoyee.
Si cet item represente un element, c'est sa categorie parente qui est renvoyee.
@param qtwi un QTreeWidgetItem
@return la categorie correspondant au QTreeWidgetItem qtwi, ou 0 s'il n'y a
aucune categorie correspondante.
*/
ElementsCategory *ElementsPanel::categoryForItem(QTreeWidgetItem *qtwi) {
if (!qtwi) return(0);
// Recupere le CollectionItem associe a cet item
ElementsCollectionItem *collection_item = collectionItemForItem(qtwi);
if (!collection_item) return(0);
// recupere la categorie cible pour le deplacement
return(collection_item -> toCategory());
}
/**
@param pos Position dans l'arborescence
@return La categorie situee sous la position pos, ou 0 s'il n'y a aucune
categorie correspondante.
@see categoryForItem
*/
ElementsCategory *ElementsPanel::categoryForPos(const QPoint &pos) {
// Accede a l'item sous la position
QTreeWidgetItem *pos_qtwi = itemAt(pos);
if (!pos_qtwi) {
return(0);
}
return(categoryForItem(pos_qtwi));
}
/**
@param qtwi a QTreeWidgetItem
@return the directory path of the object represented by \a qtwi
@@ -626,23 +293,15 @@ QString ElementsPanel::dirPathForItem(QTreeWidgetItem *item) {
QString ElementsPanel::filePathForItem(QTreeWidgetItem *item) {
if (!item) return(QString());
ElementsCollectionItem *collection_item = collectionItemForItem(item);
if (collection_item) {
if (collection_item -> hasFilePath()) {
return(collection_item -> filePath());
}
TitleBlockTemplateLocation tbt_location = templateLocationForItem(item);
TitleBlockTemplatesCollection *tbt_collection = tbt_location.parentCollection();
if (tbt_collection && tbt_collection -> hasFilePath()) {
return(tbt_collection -> filePath());
}
else {
TitleBlockTemplateLocation tbt_location = templateLocationForItem(item);
TitleBlockTemplatesCollection *tbt_collection = tbt_location.parentCollection();
if (tbt_collection && tbt_collection -> hasFilePath()) {
return(tbt_collection -> filePath());
}
else {
QETProject *project = projectForItem(item);
if (project) {
return(project -> filePath());
}
QETProject *project = projectForItem(item);
if (project) {
return(project -> filePath());
}
}
return(QString());
@@ -710,23 +369,6 @@ void ElementsPanel::projectWasClosed(QETProject *project) {
emit(panelContentChanged());
}
/**
Affiche un element etant donne son emplacement
@param location Emplacement de l'element a afficher
*/
bool ElementsPanel::scrollToElement(const ElementsLocation &location) {
// recherche l'element dans le panel
QTreeWidgetItem *item = itemForElementsLocation(location);
if (!item) return(false);
// s'assure que l'item ne soit pas filtre
item -> setHidden(false);
setCurrentItem(item);
ensureHierarchyIsVisible(QList<QTreeWidgetItem *>() << item);
scrollToItem(item);
return(true);
}
/**
Build filter list for multiple filter
*/
@@ -788,13 +430,3 @@ void ElementsPanel::ensureHierarchyIsVisible(const QList<QTreeWidgetItem *> &ite
if (parent_qtwi -> isHidden()) parent_qtwi -> setHidden(false);
}
}
/**
Scroll to the currently selected item.
*/
void ElementsPanel::scrollToSelectedItem() {
QList<QTreeWidgetItem *> selected_items = selectedItems();
if (selected_items.count()) {
scrollToItem(selected_items.first(), QAbstractItemView::PositionAtCenter);
}
}