Refactoring: added the class GenericPanel, which provides most functions for ElementsPanel, ElementsCategoriesList, and any future panel-like widget.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1490 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-02-06 21:21:43 +00:00
parent 4adbba85df
commit 7ca84724ae
16 changed files with 1558 additions and 1150 deletions

View File

@@ -69,6 +69,10 @@ Diagram::Diagram(QObject *parent) :
&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)),
this, SLOT(setTitleBlockTemplate(const QString &))
);
connect(
&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)),
this, SLOT(titleChanged(const QString &))
);
}
/**
@@ -711,6 +715,10 @@ void Diagram::removeIndependentTextItem(IndependentTextItem *iti) {
);
}
void Diagram::titleChanged(const QString &title) {
emit(diagramTitleChanged(this, title));
}
/**
Gere le fait qu'un texte du schema ait ete modifie
@param text_item Texte modifie

View File

@@ -171,6 +171,7 @@ class Diagram : public QGraphicsScene {
QGIManager &qgiManager();
public slots:
void titleChanged(const QString &);
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
void titleBlockTemplateChanged(const QString &);
void titleBlockTemplateRemoved(const QString &, const QString & = QString());
@@ -185,7 +186,9 @@ class Diagram : public QGraphicsScene {
void written();
void readOnlyChanged(bool);
void usedTitleBlockTemplateChanged(const QString &);
void diagramTitleChanged(Diagram *, const QString &);
};
Q_DECLARE_METATYPE(Diagram *)
/**
Permet d'ajouter ou enlever le "poseur de conducteur", c'est-a-dire la

View File

@@ -51,9 +51,9 @@ ElementDialog::ElementDialog(uint mode, QWidget *parentWidget, QObject *parent)
int selectables = 0;
switch(mode_) {
case OpenElement: selectables = QET::Element; break;
case SaveElement: selectables = QET::All; break;
case OpenCategory: selectables = QET::Category | QET::Collection; break;
case SaveCategory: selectables = QET::Category | QET::Collection; break;
case SaveElement: selectables = QET::ElementsCollectionItem; break;
case OpenCategory: selectables = QET::ElementsContainer; break;
case SaveCategory: selectables = QET::ElementsContainer; break;
}
list_ = new ElementsCategoriesList(display_elements, selectables);
connect(list_, SIGNAL(locationChanged(const ElementsLocation &)), this, SLOT(locationChanged(const ElementsLocation &)));

View File

@@ -31,7 +31,7 @@
@param parent QWidget parent de ce widget
*/
ElementsCategoriesList::ElementsCategoriesList(bool display_elements, uint selectables, QWidget *parent) :
QTreeWidget(parent),
GenericPanel(parent),
display_elements_(display_elements),
selectables_(selectables),
first_load(true)
@@ -39,12 +39,15 @@ ElementsCategoriesList::ElementsCategoriesList(bool display_elements, uint selec
// selection unique
setSelectionMode(QAbstractItemView::SingleSelection);
setColumnCount(1);
header() -> hide();
// charge les categories
setElementsCache(QETApp::collectionCache());
reload();
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(selectionChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
connect(
this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(selectionChanged(QTreeWidgetItem *, QTreeWidgetItem *))
);
}
/**
@@ -57,124 +60,61 @@ ElementsCategoriesList::~ElementsCategoriesList() {
Recharge l'arbre des categories
*/
void ElementsCategoriesList::reload() {
// vide l'arbre
clear();
GenericPanel::PanelOptions options = display_elements_ ? GenericPanel::AddAllChildElements : GenericPanel::AddChildElementsContainers;
options |= GenericPanel::DisplayElementsPreview;
foreach(ElementsCollection *collection, QETApp::availableCollections()) {
if (collection == QETApp::commonElementsCollection()) continue;
if (collection == QETApp::customElementsCollection()) continue;
addCollection(invisibleRootItem(), collection, tr("Collection projet"));
addElementsCollection(collection, invisibleRootItem(), options, tr("Collection projet")) -> setExpanded(true);
}
// chargement des elements de la collection commune si droits d'ecriture
if (QETApp::commonElementsCollection() -> isWritable()) {
if (!first_load) QETApp::commonElementsCollection() -> reload();
addCollection(invisibleRootItem(), QETApp::commonElementsCollection(), tr("Collection QET"), QET::Icons::QETLogo);
addElementsCollection(
QETApp::commonElementsCollection(),
invisibleRootItem(),
options,
tr("Collection QET"),
QIcon(":/ico/16x16/qet.png")
) -> setExpanded(true);
}
// chargement des elements de la collection utilisateur
if (!first_load) QETApp::customElementsCollection() -> reload();
addCollection(invisibleRootItem(), QETApp::customElementsCollection(), tr("Collection utilisateur"), QET::Icons::Home);
addElementsCollection(
QETApp::customElementsCollection(),
invisibleRootItem(),
options,
tr("Collection utilisateur"),
QIcon(":/ico/16x16/go-home.png")
) -> setExpanded(true);
if (first_load) first_load = false;
}
/**
Methode privee permettant d'ajouter une collection 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
@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
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
*/
QTreeWidgetItem *ElementsCategoriesList::addCollection(QTreeWidgetItem *qtwi_parent, ElementsCollection *collection, const QString &coll_name, const QIcon &icon) {
QTreeWidgetItem *qtwi_coll = addCategory(qtwi_parent, collection -> rootCategory(), coll_name, icon);
qtwi_coll -> setExpanded(true);
Qt::ItemFlags flags_coll = Qt::ItemIsEnabled;
if (selectables_ & QET::Collection) flags_coll |= Qt::ItemIsSelectable;
qtwi_coll -> setFlags(flags_coll);
return(qtwi_coll);
}
/**
Methode privee permettant d'ajouter une categorie
@param qtwi_parent QTreeWidgetItem parent sous lequel sera insere la categorie
@param category Categorie d'elements a inserer
@param cat_name Parametre facultatif permettant de forcer le nom affiche
S'il n'est pas precise, la methode utilise le nom declare par la categorie.
@param icon Icone a utiliser pour l'affichage de la categorie
Si elle n'est pas precisee, une icone par defaut est utilisee
@return Le QTreeWidgetItem insere le plus haut
*/
QTreeWidgetItem *ElementsCategoriesList::addCategory(QTreeWidgetItem *qtwi_parent, ElementsCategory *category, const QString &cat_name, const QIcon &icon) {
// recupere le nom de la categorie
QString final_name(cat_name.isEmpty() ? category -> name() : cat_name);
QIcon final_icon(icon.isNull() ? QET::Icons::Folder : icon);
// creation du QTreeWidgetItem representant le dossier
QTreeWidgetItem *qtwi_category = new QTreeWidgetItem(qtwi_parent, QStringList(final_name));
qtwi_category -> setIcon(0, final_icon);
locations_.insert(qtwi_category, category -> location());
Qt::ItemFlags flags_category = Qt::ItemIsEnabled;
if (selectables_ & QET::Category) flags_category |= Qt::ItemIsSelectable;
qtwi_category -> setFlags(flags_category);
// ajout des sous-categories
foreach(ElementsCategory *sub_cat, category -> categories()) addCategory(qtwi_category, sub_cat);
if (display_elements_) {
foreach(ElementDefinition *elmt, category -> elements()) addElement(qtwi_category, elmt);
}
return(qtwi_category);
}
/**
Methode privee permettant d'ajouter un element
@param qtwi_parent QTreeWidgetItem parent sous lequel sera insere l'element
@param element Element a inserer
@param elmt_name Parametre facultatif permettant de forcer le nom affiche
S'il n'est pas precise, la methode utilise le nom declare par la categorie.
@param icon Icone a utiliser pour l'affichage de l'element
@return Le QTreeWidgetItem insere
*/
QTreeWidgetItem *ElementsCategoriesList::addElement(QTreeWidgetItem *qtwi_parent, ElementDefinition *element, const QString &elmt_name, const QIcon &icon) {
int state;
CustomElement custom_elmt(element -> xml(), 0, 0, &state);
if (state) {
qDebug() << "ElementsCategoriesList::addElement() : Le chargement du composant" << qPrintable(element -> location().toString()) << "a echoue avec le code d'erreur" << state;
return(0);
}
QString final_name(elmt_name.isEmpty() ? custom_elmt.name() : elmt_name);
QTreeWidgetItem *qtwi = new QTreeWidgetItem(qtwi_parent, QStringList(final_name));
qtwi -> setToolTip(0, custom_elmt.name());
Qt::ItemFlags flags_element = Qt::ItemIsEnabled;
if (selectables_ & QET::Element) flags_element |= Qt::ItemIsSelectable;
qtwi -> setFlags(flags_element);
qtwi -> setIcon(0, icon);
locations_.insert(qtwi, element -> location());
return(qtwi);
}
/**
@return Le nom de la categorie selectionnee
*/
QString ElementsCategoriesList::selectedCategoryName() const {
QTreeWidgetItem *qtwi = currentItem();
if (qtwi) return(qtwi -> data(0, Qt::DisplayRole).toString());
else return(QString());
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);
}
/**
@return l'emplacement correspondant au QTreeWidgetItem selectionne
*/
ElementsLocation ElementsCategoriesList::selectedLocation() const {
if (QTreeWidgetItem *current_qtwi = currentItem()) {
return(locations_[current_qtwi]);
} else {
return(ElementsLocation());
}
QTreeWidgetItem *current_qtwi = currentItem();
if (!current_qtwi) return(ElementsLocation());
return(valueForItem<ElementsLocation>(current_qtwi));
}
/**
@@ -184,11 +124,9 @@ ElementsLocation ElementsCategoriesList::selectedLocation() const {
@return true si la selection a pu etre effectuee, false sinon
*/
bool ElementsCategoriesList::selectLocation(const ElementsLocation &location) {
if (QTreeWidgetItem *qtwi = locations_.key(location)) {
setCurrentItem(qtwi);
return(true);
}
return(false);
QTreeWidgetItem *qtwi = itemForElementsLocation(location);
if (qtwi) setCurrentItem(qtwi);
return(qtwi);
}
/**
@@ -201,7 +139,7 @@ void ElementsCategoriesList::selectionChanged(QTreeWidgetItem *current, QTreeWid
Q_UNUSED(previous);
ElementsLocation emited_location;
if (current) {
emited_location = locations_[current];
emited_location = valueForItem<ElementsLocation>(current);
}
emit(locationChanged(emited_location));
}

View File

@@ -20,6 +20,7 @@
#include <QtGui>
#include "qet.h"
#include "elementslocation.h"
#include "genericpanel.h"
class ElementsCollection;
class ElementsCategory;
class ElementDefinition;
@@ -27,7 +28,7 @@ class ElementDefinition;
Cette classe fournit une liste graphique des categories d'elements de
l'utilisateur.
*/
class ElementsCategoriesList : public QTreeWidget {
class ElementsCategoriesList : public GenericPanel {
Q_OBJECT
// Constructeurs, destructeur
@@ -40,15 +41,12 @@ class ElementsCategoriesList : public QTreeWidget {
// methodes
public:
QString selectedCategoryName() const;
ElementsLocation selectedLocation() const;
bool selectLocation(const ElementsLocation &);
private:
QTreeWidgetItem *addCollection(QTreeWidgetItem *, ElementsCollection *, const QString & = QString(), const QIcon & = QIcon());
QTreeWidgetItem *addCategory (QTreeWidgetItem *, ElementsCategory *, const QString & = QString(), const QIcon & = QIcon());
QTreeWidgetItem *addElement (QTreeWidgetItem *, ElementDefinition *, const QString & = QString(), const QIcon & = QIcon());
QString categoryName(QDir &);
QTreeWidgetItem *makeItem(QET::ItemType, QTreeWidgetItem *, const QString &, const QIcon &);
public slots:
void reload();
@@ -64,6 +62,5 @@ class ElementsCategoriesList : public QTreeWidget {
bool display_elements_;
int selectables_;
bool first_load;
QHash<QTreeWidgetItem *, ElementsLocation> locations_;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@
#ifndef PANELAPPAREILS_H
#define PANELAPPAREILS_H
#include <QtGui>
#include "genericpanel.h"
#include "elementslocation.h"
#include "templatelocation.h"
class QETProject;
@@ -34,7 +35,7 @@ class TitleBlockTemplatesFilesCollection;
graphique) dans lequel l'utilisateur choisit les composants de
son choix et les depose sur le schema par drag'n drop.
*/
class ElementsPanel : public QTreeWidget {
class ElementsPanel : public GenericPanel {
Q_OBJECT
// constructeurs, destructeur
@@ -45,45 +46,17 @@ class ElementsPanel : public QTreeWidget {
private:
ElementsPanel(const ElementsPanel &);
// methodes
// methods
public:
// methodes pour determiner ce que represente un item donne
bool itemIsACollection(QTreeWidgetItem *) const;
bool itemIsACategory(QTreeWidgetItem *) const;
bool itemIsAnElement(QTreeWidgetItem *) const;
bool itemIsAProject(QTreeWidgetItem *) const;
bool itemIsADiagram(QTreeWidgetItem *) const;
bool itemHasLocation(QTreeWidgetItem *) const;
bool itemIsWritable(QTreeWidgetItem *) const;
bool itemIsATitleBlockTemplatesCollection(QTreeWidgetItem *) const;
bool itemIsATitleBlockTemplate(QTreeWidgetItem *) const;
bool selectedItemIsWritable() const;
// methodes pour obtenir ce que represente un item donne
ElementsCollectionItem *collectionItemForItem(QTreeWidgetItem *) const;
QETProject *projectForItem(QTreeWidgetItem *) const;
Diagram *diagramForItem(QTreeWidgetItem *) const;
ElementsLocation locationForItem(QTreeWidgetItem *) const;
ElementsCollectionItem *selectedItem() const;
ElementsCategory *categoryForItem(QTreeWidgetItem *);
ElementsCategory *categoryForPos(const QPoint &);
TitleBlockTemplateLocation locationForTitleBlockTemplate(QTreeWidgetItem *);
QString nameOfTitleBlockTemplate(QTreeWidgetItem *);
// methodes pour determiner ce que represente l'item selectionne
bool selectedItemIsACollection() const;
bool selectedItemIsACategory() const;
bool selectedItemIsAnElement() const;
bool selectedItemIsAProject() const;
bool selectedItemIsADiagram() const;
bool selectedItemHasLocation() const;
bool selectedItemIsWritable() const;
bool selectedItemIsATitleBlockTemplatesDirectory() const;
bool selectedItemIsATitleBlockTemplate() const;
// methodes pour obtenir ce que represente l'item selectionne
ElementsCollectionItem *selectedItem() const;
QETProject *selectedProject() const;
Diagram *selectedDiagram() const;
ElementsLocation selectedLocation() const;
void reloadCollections();
int elementsCollectionItemsCount();
@@ -91,7 +64,7 @@ class ElementsPanel : public QTreeWidget {
signals:
void requestForProject(QETProject *);
void requestForDiagram(Diagram *);
void requestForCollectionItem(ElementsCollectionItem *);
void requestForCollectionItem(const ElementsLocation &);
void requestForMoveElements(ElementsCollectionItem *, ElementsCollectionItem *, QPoint);
void requestForTitleBlockTemplate(const TitleBlockTemplateLocation &);
void readingAboutToBegin();
@@ -101,15 +74,9 @@ class ElementsPanel : public QTreeWidget {
public slots:
void slot_doubleClick(QTreeWidgetItem *, int);
void reload(bool = false);
void filter(const QString &);
void filter(const QString &, QET::Filtering = QET::RegularFilter);
void projectWasOpened(QETProject *);
void projectWasClosed(QETProject *);
void projectInformationsChanged(QETProject *);
void titleBlockTemplatesCollectionChanged(TitleBlockTemplatesCollection*, const QString & = QString());
void diagramWasAdded(QETProject *, Diagram *);
void diagramWasRemoved(QETProject *, Diagram *);
void diagramTitleChanged(QETProject *, Diagram *);
void diagramOrderChanged(QETProject *, int, int);
bool scrollToElement(const ElementsLocation &);
protected:
@@ -119,43 +86,27 @@ class ElementsPanel : public QTreeWidget {
void startDrag(Qt::DropActions);
void startElementDrag(const ElementsLocation &);
void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &);
bool event(QEvent *);
protected slots:
void firstActivation();
private:
QTreeWidgetItem *addProject (QTreeWidgetItem *, QETProject *);
QTreeWidgetItem *addDiagram (QTreeWidgetItem *, Diagram *);
QTreeWidgetItem *addCollection(QTreeWidgetItem *, ElementsCollection *, const QString & = QString(), const QIcon & = QIcon());
QTreeWidgetItem *addCategory (QTreeWidgetItem *, ElementsCategory *, const QString & = QString(), const QIcon & = QIcon());
QTreeWidgetItem *addElement (QTreeWidgetItem *, ElementDefinition *, const QString & = QString());
QTreeWidgetItem *addTitleBlockTemplatesCollection(QTreeWidgetItem *, TitleBlockTemplatesCollection *, const QString & = QString(), const QIcon & = QIcon());
void saveExpandedCategories();
QTreeWidgetItem *findLocation(const ElementsLocation &) const;
QTreeWidgetItem *findLocation(const QString &) const;
void deleteItem(QTreeWidgetItem *);
void updateProjectItemInformations(QETProject *);
void updateDiagramLabel(QTreeWidgetItem *, int);
QString diagramTitleToDisplay(Diagram *) const;
QString titleBlockTemplateNameToDisplay(const QString &) const;
QTreeWidgetItem *addProject (QETProject *);
QTreeWidgetItem *addCollection(ElementsCollection *, const QString & = QString(), const QIcon & = QIcon());
QTreeWidgetItem *updateTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions, bool = false);
QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions, bool = false);
QTreeWidgetItem *updateElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false);
void ensureHierarchyIsVisible(QList<QTreeWidgetItem *>);
void markItemAsUnused(QTreeWidgetItem *);
// attributs
// attributes
private:
QStringList expanded_directories;
QString last_selected_item;
QHash<QTreeWidgetItem *, ElementsLocation> locations_;
QHash<QTreeWidgetItem *, TitleBlockTemplateLocation> title_blocks_;
QSet<QETProject *> projects_to_display_;
QHash<QTreeWidgetItem *, QETProject *> projects_;
QHash<QTreeWidgetItem *, Diagram *> diagrams_;
QHash<QTreeWidgetItem *, TitleBlockTemplatesCollection *> title_blocks_collections_;
QTreeWidgetItem *common_collection_item_;
QTreeWidgetItem *common_tbt_collection_item_;
QTreeWidgetItem *custom_collection_item_;
QTreeWidgetItem *custom_tbt_collection_item_;
int loading_progress_;
bool first_activation_;
bool first_reload_;
ElementsCollectionCache *cache_;
QSet<QETProject *> projects_to_display_; ///< list of projects that have been added to this panel
QTreeWidgetItem *common_collection_item_; ///< pointer to the item representing the common elements collection
QTreeWidgetItem *common_tbt_collection_item_; ///< pointer to the item representing the common templates collection
QTreeWidgetItem *custom_collection_item_; ///< pointer to the item representing the user elements collection
QTreeWidgetItem *custom_tbt_collection_item_; ///< pointer to the item representing the user templates collection
int loading_progress_; ///< used to track the loading progress of elements collections
bool first_reload_; ///< used to distinguish the first time this panel is reloaded
};
#endif

View File

@@ -117,11 +117,11 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
connect(copy_elements_, SIGNAL(triggered()), this, SLOT(copyElements()));
connect(erase_textfield, SIGNAL(triggered()), this, SLOT(clearFilterTextField()));
connect(filter_textfield, SIGNAL(textEdited(const QString &)), elements_panel, SLOT(filter(const QString &)));
connect(filter_textfield, SIGNAL(textEdited(const QString &)), this, SLOT(filterEdited(const QString &)));
connect(elements_panel, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(updateButtons()));
connect(elements_panel, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(handleContextMenu(const QPoint &)));
connect(elements_panel, SIGNAL(requestForCollectionItem(ElementsCollectionItem *)), this, SLOT(handleCollectionRequest(ElementsCollectionItem *)));
connect(elements_panel, SIGNAL(requestForCollectionItem(const ElementsLocation &)), this, SLOT(handleCollectionRequest(const ElementsLocation &)));
connect(
elements_panel,
SIGNAL(requestForMoveElements(ElementsCollectionItem *, ElementsCollectionItem *, QPoint)),
@@ -179,7 +179,7 @@ ElementsPanelWidget::~ElementsPanelWidget() {
void ElementsPanelWidget::clearFilterTextField() {
filter_textfield -> clear();
filter_textfield -> setFocus();
elements_panel -> filter(QString());
filterEdited(QString());
}
/**
@@ -263,9 +263,10 @@ void ElementsPanelWidget::addTitleBlockTemplate() {
QTreeWidgetItem *current_item = elements_panel -> currentItem();
if (!current_item) return;
if (elements_panel -> itemIsATitleBlockTemplatesCollection(current_item)) {
TitleBlockTemplateLocation location = elements_panel -> locationForTitleBlockTemplate(current_item);
QETApp::instance() -> openTitleBlockTemplate(location);
if (current_item -> type() == QET::TitleBlockTemplatesCollection) {
QETApp::instance() -> openTitleBlockTemplate(
elements_panel -> templateLocationForItem(current_item)
);
}
}
@@ -274,8 +275,10 @@ void ElementsPanelWidget::addTitleBlockTemplate() {
*/
void ElementsPanelWidget::editTitleBlockTemplate() {
QTreeWidgetItem *current_item = elements_panel -> currentItem();
if (current_item && elements_panel -> itemIsATitleBlockTemplate(current_item)) {
QETApp::instance() -> openTitleBlockTemplate(elements_panel -> locationForTitleBlockTemplate(current_item));
if (current_item && current_item -> type() == QET::TitleBlockTemplate) {
QETApp::instance() -> openTitleBlockTemplate(
elements_panel -> templateLocationForItem(current_item)
);
}
}
@@ -284,9 +287,9 @@ void ElementsPanelWidget::editTitleBlockTemplate() {
*/
void ElementsPanelWidget::removeTitleBlockTemplate() {
QTreeWidgetItem *current_item = elements_panel -> currentItem();
if (current_item && elements_panel -> itemIsATitleBlockTemplate(current_item)) {
if (current_item && current_item -> type() == QET::TitleBlockTemplate) {
TitleBlockTemplateDeleter(
elements_panel -> locationForTitleBlockTemplate(current_item),
elements_panel -> templateLocationForItem(current_item),
this
).exec();
}
@@ -342,9 +345,12 @@ void ElementsPanelWidget::newCategory() {
Met a jour les boutons afin d'assurer la coherence de l'interface
*/
void ElementsPanelWidget::updateButtons() {
bool collection_selected = elements_panel -> selectedItemIsACollection();
bool category_selected = collection_selected || elements_panel -> selectedItemIsACategory();
bool element_selected = elements_panel -> selectedItemIsAnElement();
QTreeWidgetItem *current_item = elements_panel -> currentItem();
int current_type = elements_panel -> currentItemType();
bool collection_selected = current_type == QET::ElementsCollection;
bool category_selected = current_type & QET::ElementsContainer;
bool element_selected = current_type == QET::Element;
if (collection_selected || category_selected || element_selected) {
bool element_writable = elements_panel -> selectedItemIsWritable();
@@ -355,11 +361,11 @@ void ElementsPanelWidget::updateButtons() {
new_element -> setEnabled(category_selected && element_writable);
edit_element -> setEnabled(element_selected);
delete_element -> setEnabled(element_selected && element_writable);
} else if (elements_panel -> selectedItemIsAProject()) {
} else if (current_type == QET::Project) {
bool is_writable = !(elements_panel -> selectedProject() -> isReadOnly());
prj_add_diagram -> setEnabled(is_writable);
setElementsActionEnabled(false);
} else if (elements_panel -> selectedItemIsADiagram()) {
} else if (current_type == QET::Diagram) {
Diagram *selected_diagram = elements_panel -> selectedDiagram();
QETProject *selected_diagram_project = selected_diagram -> project();
@@ -371,16 +377,15 @@ void ElementsPanelWidget::updateButtons() {
prj_move_diagram_up -> setEnabled(is_writable && diagram_position > 0);
prj_move_diagram_down -> setEnabled(is_writable && diagram_position < project_diagrams_count - 1);
setElementsActionEnabled(false);
} else if (elements_panel -> selectedItemIsATitleBlockTemplatesDirectory()) {
QTreeWidgetItem *item = elements_panel -> currentItem();
TitleBlockTemplateLocation location = elements_panel -> locationForTitleBlockTemplate(item);
} else if (current_type == QET::TitleBlockTemplatesCollection) {
TitleBlockTemplateLocation location = elements_panel -> templateLocationForItem(current_item);
tbt_add -> setEnabled(!location.isReadOnly());
tbt_edit -> setEnabled(false); // would not make sense
tbt_remove -> setEnabled(false); // would not make sense
setElementsActionEnabled(false);
} else if (elements_panel -> selectedItemIsATitleBlockTemplate()) {
} else if (current_type == QET::TitleBlockTemplate) {
QTreeWidgetItem *item = elements_panel -> currentItem();
TitleBlockTemplateLocation location = elements_panel -> locationForTitleBlockTemplate(item);
TitleBlockTemplateLocation location = elements_panel -> templateLocationForItem(item);
tbt_add -> setEnabled(false); // would not make sense
tbt_edit -> setEnabled(true); // the tbt editor has a read-only mode
// deleting a tbt requires its parent collection to be writable
@@ -441,42 +446,40 @@ void ElementsPanelWidget::handleContextMenu(const QPoint &pos) {
updateButtons();
context_menu -> clear();
if (elements_panel -> itemHasLocation(item)) {
// recupere l'emplacement associe a l'item
ElementsCollectionItem *selected_item = elements_panel -> collectionItemForItem(item);
if (selected_item) {
if (selected_item -> isCategory()) {
context_menu -> addAction(new_category);
context_menu -> addAction(edit_category);
context_menu -> addAction(delete_category);
context_menu -> addAction(new_element);
} else if (selected_item -> isElement()) {
context_menu -> addAction(edit_element);
context_menu -> addAction(delete_element);
} else if (selected_item -> isCollection()) {
// categorie racine / collection
context_menu -> addAction(new_category);
context_menu -> addAction(delete_collection);
context_menu -> addAction(new_element);
}
}
} else {
if (elements_panel -> itemIsAProject(item)) {
switch(item -> type()) {
case QET::ElementsCategory:
context_menu -> addAction(new_category);
context_menu -> addAction(edit_category);
context_menu -> addAction(delete_category);
context_menu -> addAction(new_element);
break;
case QET::Element:
context_menu -> addAction(edit_element);
context_menu -> addAction(delete_element);
break;
case QET::ElementsCollection:
context_menu -> addAction(new_category);
context_menu -> addAction(delete_collection);
context_menu -> addAction(new_element);
break;
case QET::Project:
context_menu -> addAction(prj_edit_prop);
context_menu -> addAction(prj_add_diagram);
context_menu -> addAction(prj_close);
} else if (elements_panel -> itemIsADiagram(item)) {
break;
case QET::Diagram:
context_menu -> addAction(prj_prop_diagram);
context_menu -> addAction(prj_del_diagram);
context_menu -> addAction(prj_move_diagram_up);
context_menu -> addAction(prj_move_diagram_down);
} else if (elements_panel -> itemIsATitleBlockTemplatesCollection(item)) {
break;
case QET::TitleBlockTemplatesCollection:
context_menu -> addAction(tbt_add);
} else if (elements_panel -> itemIsATitleBlockTemplate(item)) {
break;
case QET::TitleBlockTemplate:
context_menu -> addAction(tbt_edit);
context_menu -> addAction(tbt_remove);
}
break;
}
// affiche le menu
@@ -489,7 +492,9 @@ void ElementsPanelWidget::handleContextMenu(const QPoint &pos) {
Gere les demandes d'edition de categories ou d'elements
@param item Item de la collection a editer
*/
void ElementsPanelWidget::handleCollectionRequest(ElementsCollectionItem *item) {
void ElementsPanelWidget::handleCollectionRequest(const ElementsLocation &item_location) {
if (item_location.isNull()) return;
ElementsCollectionItem *item = QETApp::collectionItem(item_location);
if (!item) return;
if (item -> isElement()) {
// il s'agit d'un element
@@ -601,6 +606,20 @@ void ElementsPanelWidget::updateProgressBar(int current, int maximum) {
progress_bar_ -> setValue(current);
}
void ElementsPanelWidget::filterEdited(const QString &next_text) {
if (previous_filter_.isEmpty() && next_text.length() == 1) {
// the field is not empty anymore: begin filtering
elements_panel -> filter(next_text, QET::BeginFilter);
} else if (!previous_filter_.isEmpty() && next_text.isEmpty()) {
// the field is now empty again: end of filtering
elements_panel -> filter(QString(), QET::EndFilter);
} else {
// regular filtering
elements_panel -> filter(next_text, QET::RegularFilter);
}
previous_filter_ = next_text;
}
/**
Copie l'item src dans l'item dst
*/
@@ -686,7 +705,10 @@ ElementsCategory *ElementsPanelWidget::writableSelectedCategory() {
if (!selected_qtwi) return(0);
// l'element selectionne doit pouvoir correspondre a une categorie
ElementsCategory *selected_category = elements_panel -> categoryForItem(selected_qtwi);
if (!(selected_qtwi -> type() & QET::ElementsContainer)) return(0);
ElementsLocation category_location = elements_panel -> elementLocationForItem(selected_qtwi);
ElementsCollectionItem *category = QETApp::collectionItem(category_location, false);
ElementsCategory *selected_category = category -> toCategory();
if (!selected_category) return(0);
// la categorie doit etre accessible en ecriture

View File

@@ -88,7 +88,7 @@ class ElementsPanelWidget : public QWidget {
void setElementsActionEnabled(bool);
int launchCategoriesManager();
void handleContextMenu(const QPoint &);
void handleCollectionRequest(ElementsCollectionItem *);
void handleCollectionRequest(const ElementsLocation &);
void handleMoveElementsRequest(ElementsCollectionItem *, ElementsCollectionItem *, const QPoint & = QPoint());
void moveElements();
void moveElements(ElementsCollectionItem *, ElementsCollectionItem *);
@@ -97,11 +97,13 @@ class ElementsPanelWidget : public QWidget {
void collectionsRead();
void collectionsReadFinished();
void updateProgressBar(int, int);
void filterEdited(const QString &);
private:
void launchElementEditor(const ElementsLocation &);
void launchCategoryEditor(const ElementsLocation &);
ElementsCategory *writableSelectedCategory();
QString previous_filter_;
};
/**

1045
sources/genericpanel.cpp Normal file

File diff suppressed because it is too large Load Diff

194
sources/genericpanel.h Normal file
View File

@@ -0,0 +1,194 @@
/*
Copyright 2006-2012 Xavier Guerrin
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/>.
*/
#ifndef GENERIC_PANEL_H
#define GENERIC_PANEL_H
#include "qet.h"
#include <QTreeWidget>
#include "elementslocation.h"
class QTreeWidgetItem;
class QETProject;
class Diagram;
class ElementsCollection;
class ElementsCategory;
class ElementDefinition;
class TitleBlockTemplatesCollection;
class TitleBlockTemplateLocation;
class ElementsCollectionCache;
/**
The generic panel is a QTreeWidget subclass providing extra methods
allowing developers to easily add objects (projects, diagrams, title block
templates, elements, ...) to it; it also ensures the displayed information
remains up to date.
*/
class GenericPanel : public QTreeWidget {
Q_OBJECT
public:
enum PanelOption {
AddChildDiagrams = 1,
AddChildTemplatesCollection = 2,
AddChildTemplates = 4,
AddAllChildTemplates = 6,
AddChildElementsCollections = 8,
AddChildElementsCategories = 16,
AddChildElementsContainers = 24,
AddChildElements = 32,
AddAllChildElements = 56,
AddAllChild = 63,
DisplayElementsPreview = 64,
All = 127
};
Q_DECLARE_FLAGS(PanelOptions, PanelOption)
enum MetaData {
Item = Qt::UserRole + 1,
AliasItem,
Parent
};
// Constructors, destructor
public:
GenericPanel(QWidget * = 0);
virtual ~GenericPanel();
// cache-related methods
public:
virtual ElementsCollectionCache *elementsCache();
virtual bool setElementsCache(ElementsCollectionCache *, ElementsCollectionCache ** = 0);
protected:
virtual ElementsCollectionCache *getElementsCache();
public:
// convenience methods to obtain what an item represents
virtual int currentItemType();
virtual QETProject *projectForItem(QTreeWidgetItem *) const;
virtual Diagram *diagramForItem(QTreeWidgetItem *) const;
virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const;
virtual ElementsLocation elementLocationForItem(QTreeWidgetItem *) const;
// convenience methods to obtain what the selected item represents
virtual QETProject *selectedProject() const;
virtual Diagram *selectedDiagram() const;
virtual TitleBlockTemplateLocation selectedTemplateLocation() const;
virtual ElementsLocation selectedElementLocation() const;
// project-related methods
public:
virtual QTreeWidgetItem *addProject(QETProject *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForProject(QETProject *);
protected:
virtual QTreeWidgetItem *getItemForProject(QETProject *, bool * = 0);
virtual QTreeWidgetItem *updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillProjectItem (QTreeWidgetItem *, QETProject *, PanelOptions = AddAllChild, bool = false);
// diagram-related methods
public:
virtual QTreeWidgetItem *addDiagram(Diagram *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForDiagram(Diagram *);
protected:
virtual QTreeWidgetItem *getItemForDiagram(Diagram *, bool * = 0);
virtual QTreeWidgetItem *updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillDiagramItem (QTreeWidgetItem *, Diagram *, PanelOptions = AddAllChild, bool = false);
// title block templates collections methods
public:
virtual QTreeWidgetItem *addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForTemplatesCollection(TitleBlockTemplatesCollection *);
protected:
virtual QTreeWidgetItem *getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool * = 0);
virtual QTreeWidgetItem *updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillTemplatesCollectionItem (QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions = AddAllChild, bool = false);
// title block templates methods
public:
virtual QTreeWidgetItem *addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForTemplate(const TitleBlockTemplateLocation &);
protected:
virtual QTreeWidgetItem *getItemForTemplate(const TitleBlockTemplateLocation &, bool * = 0);
virtual QTreeWidgetItem *updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false);
// elements collections methods
public:
virtual QTreeWidgetItem *addElementsCollection(ElementsCollection *, QTreeWidgetItem *, PanelOptions = AddAllChild, const QString & = QString(), const QIcon & = QIcon());
virtual QTreeWidgetItem *itemForElementsLocation(const ElementsLocation &);
// elements categories methods
public:
virtual QTreeWidgetItem *addElementsCategory(ElementsCategory *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForElementsCategory(ElementsCategory *);
protected:
virtual QTreeWidgetItem *getItemForElementsCategory(ElementsCategory *, bool * = 0);
virtual QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillElementsCategoryItem (QTreeWidgetItem *, ElementsCategory *, PanelOptions = AddAllChild, bool = false);
// elements methods
public:
virtual QTreeWidgetItem *addElement(ElementDefinition *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild);
virtual QTreeWidgetItem *itemForElement(ElementDefinition *);
protected:
virtual QTreeWidgetItem *getItemForElement(ElementDefinition *, bool * = 0);
virtual QTreeWidgetItem *updateElementItem(QTreeWidgetItem *, ElementDefinition *, PanelOptions = AddAllChild, bool = false);
virtual QTreeWidgetItem *fillElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions = AddAllChild, bool = false);
// slots used to receive change notifications from added objects
protected slots:
void projectInformationsChanged(QETProject *);
void diagramAdded(QETProject *, Diagram *);
void diagramRemoved(QETProject *, Diagram *);
void projectDiagramsOrderChanged(QETProject *, int, int);
void diagramTitleChanged(Diagram *, const QString &);
void templatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &);
void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
// various other methods
protected:
virtual QString defaultText(QET::ItemType);
virtual QIcon defaultIcon(QET::ItemType);
virtual QTreeWidgetItem *makeItem(QET::ItemType, QTreeWidgetItem * = 0, const QString & = QString(), const QIcon & = QIcon());
virtual void deleteItem(QTreeWidgetItem *);
virtual void markItemAsContainer(QTreeWidgetItem *);
virtual void markItemAsUnused(QTreeWidgetItem *);
virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *);
QList<QTreeWidgetItem *> childItems(QTreeWidgetItem *, QET::ItemType, bool = false) const;
template<typename T> void removeObsoleteItems(const QList<T> &, QTreeWidgetItem *, QET::ItemType, bool);
template<typename T> T valueForItem(QTreeWidgetItem *) const;
void unregisterItem(QTreeWidgetItem *);
void clearPanel();
bool event(QEvent *);
signals:
bool firstActivated();
private slots:
void emitFirstActivated();
protected:
ElementsCollectionCache *cache_; ///< Cache used to render elements
private:
bool first_activation_; ///< boolean used to track the first time this widget is activated/shown
QHash<QETProject *, QTreeWidgetItem *> projects_; ///< Allow quick retrieval of the item representing a given project
QHash<Diagram *, QTreeWidgetItem *> diagrams_; ///< Allow quick retrieval of the item representing a given diagram
QHash<TitleBlockTemplateLocation, QTreeWidgetItem *> tb_templates_; ///< Allow quick retrieval of the item representing a title block template
QHash<ElementsLocation, QTreeWidgetItem *> elements_; ///< Allow quick retrieval of the item representing an element
};
#endif

View File

@@ -68,12 +68,27 @@ namespace QET {
collection d'elements.
*/
enum ItemType {
Element = 1, ///< Element
Category = 2, ///< Categorie
Collection = 4, ///< Collection
All = 7 ///< Tous
Element = 1,
ElementsCategory = 2,
ElementsCollection = 4,
ElementsContainer = 6,
ElementsCollectionItem = 7,
TitleBlockTemplate = 8,
TitleBlockTemplatesCollection = 16,
TitleBlockTemplatesCollectionItem = 24,
Diagram = 32,
Project = 64,
All = 127
};
/**
This enum represents the various steps when applying a filter.
*/
enum Filtering {
BeginFilter,
RegularFilter,
EndFilter
};
/**
Cet enum represente les differentes facons de gerer un probleme lors de

View File

@@ -27,6 +27,7 @@
#include "qeticons.h"
#include "qetelementeditor.h"
#include "qetmessagebox.h"
#include "genericpanel.h"
/**
constructeur
@@ -967,20 +968,6 @@ void QETDiagramEditor::activateWidget(QWidget *widget) {
}
}
/**
@param project_view Projet concerne
@param from Index de l'onglet avant le deplacement
@param to Index de l'onglet apres le deplacement
*/
void QETDiagramEditor::diagramOrderChanged(ProjectView *project_view, int from, int to) {
if (!project_view) return;
QETProject *project = project_view -> project();
if (!project) return;
pa -> elementsPanel().diagramOrderChanged(project, from, to);
}
/**
Effectue l'action "couper" sur le schema en cours
*/
@@ -1252,16 +1239,10 @@ void QETDiagramEditor::addProjectView(ProjectView *project_view) {
connect(project_view, SIGNAL(diagramRemoved(DiagramView *)), this, SLOT(diagramWasRemoved(DiagramView *)));
connect(project_view, SIGNAL(diagramRemoved(DiagramView *)), this, SLOT(slot_updateActions()));
if (QETProject *project = project_view -> project()) {
connect(project, SIGNAL(diagramAdded (QETProject *, Diagram*)), &(pa -> elementsPanel()), SLOT(diagramWasAdded (QETProject *, Diagram*)));
connect(project, SIGNAL(diagramRemoved(QETProject *, Diagram*)), &(pa -> elementsPanel()), SLOT(diagramWasRemoved(QETProject *, Diagram*)));
// on met aussi les menus a jour quand un projet passe en lecture seule ou non
connect(project, SIGNAL(readOnlyChanged(QETProject *, bool)), this, SLOT(slot_updateActions()));
}
// gere les changements de l'ordre des schemas dans le projet
connect(project_view, SIGNAL(diagramOrderChanged(ProjectView *, int, int)), this, SLOT(diagramOrderChanged(ProjectView *, int, int)));
// gere les demandes consistant a retrouver un element dans le panel
connect(project_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SLOT(findElementInPanel(const ElementsLocation &)));
@@ -1694,7 +1675,6 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) {
connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions()));
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool)));
connect(dv, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(diagramTitleChanged(DiagramView *)));
}
/**
@@ -1715,18 +1695,6 @@ void QETDiagramEditor::diagramWasRemoved(DiagramView *dv) {
can_update_actions = true;
}
/**
Gere le changement de titre d'un schema dans un projet
@param dv DiagramView concerne
*/
void QETDiagramEditor::diagramTitleChanged(DiagramView *dv) {
if (Diagram *diagram = dv -> diagram()) {
if (QETProject *project = diagram -> project()) {
pa -> elementsPanel().diagramTitleChanged(project, diagram);
}
}
}
/**
@param location Emplacement de l'element a retrouver dans le panel
d'elements.

View File

@@ -129,7 +129,6 @@ class QETDiagramEditor : public QMainWindow {
void activateProject(QETProject *);
void activateProject(ProjectView *);
void activateWidget(QWidget *);
void diagramOrderChanged(ProjectView *, int, int);
void projectWasClosed(ProjectView *);
void editCurrentProjectProperties();
void editProjectProperties(ProjectView *);
@@ -147,7 +146,6 @@ class QETDiagramEditor : public QMainWindow {
void diagramWasAdded(DiagramView *);
void diagramIsAboutToBeRemoved(DiagramView *);
void diagramWasRemoved(DiagramView *);
void diagramTitleChanged(DiagramView *);
void findElementInPanel(const ElementsLocation &);
void editElementInEditor(const ElementsLocation &);

View File

@@ -832,6 +832,7 @@ void QETProject::diagramOrderChanged(int old_index, int new_index) {
diagrams_.move(old_index, new_index);
updateDiagramsFolioData();
emit(projectDiagramsOrderChanged(this, old_index, new_index));
}
/**

View File

@@ -128,6 +128,7 @@ class QETProject : public QObject {
void projectInformationsChanged(QETProject *);
void diagramAdded(QETProject *, Diagram *);
void diagramRemoved(QETProject *, Diagram *);
void projectDiagramsOrderChanged(QETProject *, int, int);
void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
void readOnlyChanged(QETProject *, bool);
@@ -181,4 +182,5 @@ class QETProject : public QObject {
/// Embedded title block templates collection
TitleBlockTemplatesProjectCollection titleblocks_;
};
Q_DECLARE_METATYPE(QETProject *)
#endif