mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
element collection widget : highlight unused element in a project.
the feature "clean project" does not clean unused elements yet git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4561 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -341,6 +341,32 @@ QList<QETProject *> ElementsCollectionModel::project() const
|
||||
return m_project_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::highlightUnusedElement
|
||||
* Highlight every unused element of managed project.
|
||||
* @See QETProject::unusedElements()
|
||||
*/
|
||||
void ElementsCollectionModel::highlightUnusedElement()
|
||||
{
|
||||
QList <ElementsLocation> unused;
|
||||
|
||||
foreach (QETProject *project, m_project_list)
|
||||
unused.append(project->unusedElements());
|
||||
|
||||
QBrush brush;
|
||||
brush.setStyle(Qt::Dense4Pattern);
|
||||
brush.setColor(Qt::red);
|
||||
|
||||
foreach (ElementsLocation location, unused) {
|
||||
QModelIndex index = indexFromLocation(location);
|
||||
if (index.isValid()) {
|
||||
QStandardItem *qsi = itemFromIndex(index);
|
||||
if (qsi)
|
||||
qsi->setBackground(brush);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::items
|
||||
* @return every ElementCollectionItem owned by this model
|
||||
|
||||
@@ -21,14 +21,13 @@
|
||||
#include <QStandardItemModel>
|
||||
#include "elementslocation.h"
|
||||
|
||||
template<>
|
||||
class QList<QETProject>;
|
||||
class XmlProjectElementCollectionItem;
|
||||
template<>
|
||||
class QHash<QETProject, XmlProjectElementCollectionItem>;
|
||||
class ElementCollectionItem;
|
||||
template<>
|
||||
class QList<ElementCollectionItem>;
|
||||
template<> class QList<QETProject>;
|
||||
template<> class QHash<QETProject, XmlProjectElementCollectionItem>;
|
||||
template<> class QList<ElementCollectionItem>;
|
||||
|
||||
|
||||
|
||||
class ElementsCollectionModel : public QStandardItemModel
|
||||
{
|
||||
@@ -50,6 +49,8 @@ class ElementsCollectionModel : public QStandardItemModel
|
||||
void addProject(QETProject *project, bool set_data = true);
|
||||
void removeProject(QETProject *project);
|
||||
QList<QETProject *> project() const;
|
||||
void highlightUnusedElement();
|
||||
|
||||
|
||||
QList <ElementCollectionItem *> items() const;
|
||||
void hideElement();
|
||||
|
||||
@@ -76,8 +76,10 @@ void ElementsCollectionWidget::expandFirstItems()
|
||||
* @param project
|
||||
*/
|
||||
void ElementsCollectionWidget::addProject(QETProject *project) {
|
||||
if (m_model)
|
||||
if (m_model) {
|
||||
m_model->addProject(project);
|
||||
m_model->highlightUnusedElement();
|
||||
}
|
||||
else
|
||||
m_waiting_project.append(project);
|
||||
}
|
||||
@@ -87,6 +89,16 @@ void ElementsCollectionWidget::removeProject(QETProject *project) {
|
||||
m_model->removeProject(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionWidget::highlightUnusedElement
|
||||
* highlight the unused element
|
||||
* @See ElementsCollectionModel::highlightUnusedElement()
|
||||
*/
|
||||
void ElementsCollectionWidget::highlightUnusedElement()
|
||||
{
|
||||
m_model->highlightUnusedElement();
|
||||
}
|
||||
|
||||
bool ElementsCollectionWidget::event(QEvent *event)
|
||||
{
|
||||
if (m_first_show && event->type() == QEvent::WindowActivate) {
|
||||
@@ -471,6 +483,7 @@ void ElementsCollectionWidget::reload()
|
||||
m_progress_bar->setValue(futur.progressValue());
|
||||
}
|
||||
|
||||
new_model->highlightUnusedElement();
|
||||
m_tree_view->setModel(new_model);
|
||||
m_index_at_context_menu = QModelIndex();
|
||||
m_showed_index = QModelIndex();
|
||||
|
||||
@@ -50,6 +50,7 @@ class ElementsCollectionWidget : public QWidget
|
||||
|
||||
void addProject (QETProject *project);
|
||||
void removeProject (QETProject *project);
|
||||
void highlightUnusedElement();
|
||||
|
||||
protected:
|
||||
virtual bool event(QEvent *event);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "nameslist.h"
|
||||
#include "qetxml.h"
|
||||
#include "elementslocation.h"
|
||||
#include "qetproject.h"
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::XmlElementCollection
|
||||
@@ -29,10 +30,11 @@
|
||||
* </category>
|
||||
* </collection>
|
||||
* All elements and category are stored as child of <category name="import>
|
||||
* @param parent
|
||||
* @param project : the project of this collection
|
||||
*/
|
||||
XmlElementCollection::XmlElementCollection(QObject *parent) :
|
||||
QObject(parent)
|
||||
XmlElementCollection::XmlElementCollection(QETProject *project) :
|
||||
QObject(project),
|
||||
m_project(project)
|
||||
{
|
||||
QDomElement collection = m_dom_document.createElement("collection");
|
||||
m_dom_document.appendChild(collection);
|
||||
@@ -67,10 +69,11 @@ XmlElementCollection::XmlElementCollection(QObject *parent) :
|
||||
* @brief XmlElementCollection::XmlElementCollection
|
||||
* Constructor with an collection. The tagName of @dom_element must be "collection"
|
||||
* @param dom_element -the collection in a dom_element (the dom element in cloned)
|
||||
* @param parent -parent QObject
|
||||
* @param project : the project of this collection
|
||||
*/
|
||||
XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QObject *parent) :
|
||||
QObject(parent)
|
||||
XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QETProject *project) :
|
||||
QObject(project),
|
||||
m_project(project)
|
||||
{
|
||||
if (dom_element.tagName() == "collection")
|
||||
m_dom_document.appendChild(m_dom_document.importNode(dom_element, true));
|
||||
@@ -169,7 +172,7 @@ QDomElement XmlElementCollection::child(const QString &path) const
|
||||
* @param parent_element
|
||||
* @return A list of directory stored in @parent_element
|
||||
*/
|
||||
QList<QDomElement> XmlElementCollection::directories(const QDomElement &parent_element)
|
||||
QList<QDomElement> XmlElementCollection::directories(const QDomElement &parent_element) const
|
||||
{
|
||||
QList <QDomElement> directory_list;
|
||||
QDomNodeList node_list = childs(parent_element);
|
||||
@@ -190,7 +193,7 @@ QList<QDomElement> XmlElementCollection::directories(const QDomElement &parent_e
|
||||
* @param parent_element
|
||||
* @return a list of names for every child directories of @parent_element
|
||||
*/
|
||||
QStringList XmlElementCollection::directoriesNames(const QDomElement &parent_element)
|
||||
QStringList XmlElementCollection::directoriesNames(const QDomElement &parent_element) const
|
||||
{
|
||||
QList <QDomElement> childs = directories(parent_element);
|
||||
QStringList names;
|
||||
@@ -210,7 +213,7 @@ QStringList XmlElementCollection::directoriesNames(const QDomElement &parent_ele
|
||||
* @param parent_element
|
||||
* @return A list of element stored in @parent_element
|
||||
*/
|
||||
QList<QDomElement> XmlElementCollection::elements(const QDomElement &parent_element)
|
||||
QList<QDomElement> XmlElementCollection::elements(const QDomElement &parent_element) const
|
||||
{
|
||||
QList <QDomElement> element_list;
|
||||
QDomNodeList node_list = childs(parent_element);
|
||||
@@ -231,7 +234,7 @@ QList<QDomElement> XmlElementCollection::elements(const QDomElement &parent_elem
|
||||
* @param parent_element
|
||||
* @return A list of names fr every childs element of @parent_element
|
||||
*/
|
||||
QStringList XmlElementCollection::elementsNames(const QDomElement &parent_element)
|
||||
QStringList XmlElementCollection::elementsNames(const QDomElement &parent_element) const
|
||||
{
|
||||
QList <QDomElement> childs = elements(parent_element);
|
||||
QStringList names;
|
||||
@@ -252,7 +255,7 @@ QStringList XmlElementCollection::elementsNames(const QDomElement &parent_elemen
|
||||
* @return the QDomElement that represent the element at path @path
|
||||
* or a null QDomElement if not found or doesn't represent an element
|
||||
*/
|
||||
QDomElement XmlElementCollection::element(const QString &path)
|
||||
QDomElement XmlElementCollection::element(const QString &path) const
|
||||
{
|
||||
if (!path.endsWith(".elmt")) return QDomElement();
|
||||
|
||||
@@ -270,7 +273,7 @@ QDomElement XmlElementCollection::element(const QString &path)
|
||||
* @return the QDomElement that represent the directory at path @path
|
||||
* or a null QDomElement if not found.
|
||||
*/
|
||||
QDomElement XmlElementCollection::directory(const QString &path)
|
||||
QDomElement XmlElementCollection::directory(const QString &path) const
|
||||
{
|
||||
QDomElement directory = child(path);
|
||||
|
||||
@@ -457,7 +460,7 @@ ElementsLocation XmlElementCollection::copy(ElementsLocation &source, ElementsLo
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
bool XmlElementCollection::exist(const QString &path)
|
||||
bool XmlElementCollection::exist(const QString &path) const
|
||||
{
|
||||
if (child(path).isNull())
|
||||
return false;
|
||||
@@ -499,6 +502,75 @@ bool XmlElementCollection::createDir(QString path, QString name, const NamesList
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::elementsLocation
|
||||
* Return all locations stored in dom_element (element and directory).
|
||||
* If dom_element is null, return all location owned by this collection
|
||||
* dom_element must be a child of this collection.
|
||||
* @param dom_element : dom_element where we must to search location.
|
||||
* @param childs = if true return all childs location of dom_element, if false, only return the direct childs location of dom_element.
|
||||
* @return
|
||||
*/
|
||||
QList<ElementsLocation> XmlElementCollection::elementsLocation(QDomElement dom_element, bool childs) const
|
||||
{
|
||||
QList <ElementsLocation> location_list;
|
||||
|
||||
if (dom_element.isNull())
|
||||
dom_element = m_dom_document.documentElement();
|
||||
|
||||
if (dom_element.ownerDocument() != m_dom_document)
|
||||
return location_list;
|
||||
|
||||
//get element childs
|
||||
QList <QDomElement> element_list = elements(dom_element);
|
||||
|
||||
foreach (QDomElement elmt, element_list) {
|
||||
ElementsLocation location = domToLocation(elmt);
|
||||
if (location.exist())
|
||||
location_list << location;
|
||||
}
|
||||
|
||||
//get directory childs
|
||||
QList <QDomElement> directory_list = directories(dom_element);
|
||||
|
||||
foreach (QDomElement dir, directory_list) {
|
||||
ElementsLocation location = domToLocation(dir);
|
||||
if (location.exist())
|
||||
location_list << location;
|
||||
|
||||
if (childs)
|
||||
location_list.append(elementsLocation(dir, childs));
|
||||
}
|
||||
|
||||
return location_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::domToLocation
|
||||
* Return the element location who represent the xml element : dom_element
|
||||
* dom_element must be owned by this collection
|
||||
* @param dom_element : the dom_element of this collection that represent an element.
|
||||
* The tag name of dom_element must be "element"
|
||||
* @return the element location, location can be null if fail.
|
||||
*/
|
||||
ElementsLocation XmlElementCollection::domToLocation(QDomElement dom_element) const
|
||||
{
|
||||
if (dom_element.ownerDocument() == m_dom_document) {
|
||||
QString path = dom_element.attribute("name");
|
||||
|
||||
while (!dom_element.parentNode().isNull() && dom_element.parentNode().isElement()) {
|
||||
dom_element = dom_element.parentNode().toElement();
|
||||
|
||||
if (dom_element.tagName() == "category")
|
||||
path.prepend(dom_element.attribute("name") + "/");
|
||||
}
|
||||
|
||||
return ElementsLocation(path, m_project);
|
||||
}
|
||||
else
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::copyDirectory
|
||||
* Copy the directory represented by source to destination.
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
class QDomElement;
|
||||
class QFile;
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The XmlElementCollection class
|
||||
@@ -32,26 +33,30 @@ class QFile;
|
||||
class XmlElementCollection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
XmlElementCollection (QObject *parent = nullptr);
|
||||
XmlElementCollection (const QDomElement &dom_element, QObject *parent = nullptr);
|
||||
XmlElementCollection (QETProject *project);
|
||||
XmlElementCollection (const QDomElement &dom_element, QETProject *project);
|
||||
QDomElement root() const;
|
||||
QDomElement importCategory() const;
|
||||
QDomNodeList childs(const QDomElement &parent_element) const;
|
||||
QDomElement child(const QDomElement &parent_element, const QString &child_name) const;
|
||||
QDomElement child(const QString &path) const;
|
||||
QList<QDomElement> directories(const QDomElement &parent_element);
|
||||
QStringList directoriesNames(const QDomElement &parent_element);
|
||||
QList<QDomElement> elements(const QDomElement &parent_element);
|
||||
QStringList elementsNames(const QDomElement &parent_element);
|
||||
QDomElement element(const QString &path);
|
||||
QDomElement directory(const QString &path);
|
||||
QList<QDomElement> directories(const QDomElement &parent_element) const;
|
||||
QStringList directoriesNames(const QDomElement &parent_element) const;
|
||||
QList<QDomElement> elements(const QDomElement &parent_element) const;
|
||||
QStringList elementsNames(const QDomElement &parent_element) const;
|
||||
QDomElement element(const QString &path) const;
|
||||
QDomElement directory(const QString &path) const;
|
||||
QString addElement (ElementsLocation &location);
|
||||
bool addElementDefinition (const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition);
|
||||
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
bool exist (const QString &path);
|
||||
bool exist (const QString &path) const;
|
||||
bool createDir (QString path, QString name, const NamesList &name_list);
|
||||
|
||||
QList <ElementsLocation> elementsLocation (QDomElement dom_element = QDomElement(), bool childs = true) const;
|
||||
ElementsLocation domToLocation(QDomElement dom_element) const;
|
||||
|
||||
private:
|
||||
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
@@ -78,6 +83,7 @@ class XmlElementCollection : public QObject
|
||||
|
||||
private:
|
||||
QDomDocument m_dom_document;
|
||||
QETProject *m_project = nullptr;
|
||||
};
|
||||
|
||||
#endif // XMLELEMENTCOLLECTION_H
|
||||
|
||||
Reference in New Issue
Block a user