Mod doc, Improve code style

This commit is contained in:
Simon De Backer
2020-08-08 23:58:17 +02:00
parent d9ec9bf274
commit 7834d6fb84
5 changed files with 339 additions and 249 deletions

View File

@@ -28,22 +28,22 @@
#include <QtConcurrent>
/**
* @brief ElementsCollectionModel::ElementsCollectionModel
* Constructor
* @param parent
*/
@brief ElementsCollectionModel::ElementsCollectionModel
Constructor
@param parent
*/
ElementsCollectionModel::ElementsCollectionModel(QObject *parent) :
QStandardItemModel(parent)
{
}
/**
* @brief ElementsCollectionModel::data
* Reimplemented from QStandardItemModel
* @param index
* @param role
* @return
*/
@brief ElementsCollectionModel::data
Reimplemented from QStandardItemModel
@param index
@param role
@return
*/
QVariant ElementsCollectionModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DecorationRole) {
@@ -59,11 +59,11 @@ QVariant ElementsCollectionModel::data(const QModelIndex &index, int role) const
}
/**
* @brief ElementsCollectionModel::mimeData
* Reimplemented from QStandardItemModel
* @param indexes
* @return
*/
@brief ElementsCollectionModel::mimeData
Reimplemented from QStandardItemModel
@param indexes
@return
*/
QMimeData *ElementsCollectionModel::mimeData(const QModelIndexList &indexes) const
{
QModelIndex index = indexes.first();
@@ -86,14 +86,15 @@ QMimeData *ElementsCollectionModel::mimeData(const QModelIndexList &indexes) con
}
/**
* @brief ElementsCollectionModel::mimeTypes
* Reimplemented from QStandardItemModel
* @return
*/
@brief ElementsCollectionModel::mimeTypes
Reimplemented from QStandardItemModel
@return
*/
QStringList ElementsCollectionModel::mimeTypes() const
{
QStringList mime_list = QAbstractItemModel::mimeTypes();
mime_list << "application/x-qet-element-uri" << "application/x-qet-category-uri";
mime_list << "application/x-qet-element-uri"
<< "application/x-qet-category-uri";
return mime_list;
}
@@ -107,12 +108,21 @@ QStringList ElementsCollectionModel::mimeTypes() const
* @param parent
* @return
*/
bool ElementsCollectionModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
bool ElementsCollectionModel::canDropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent) const
{
if (!(QStandardItemModel::canDropMimeData(data, action, row, column, parent) && parent.isValid()))
if (!(QStandardItemModel::canDropMimeData(data,
action,
row,
column,
parent) && parent.isValid()))
return false;
QStandardItem *qsi = itemFromIndex(parent.QModelIndex::model()->index(row, column));
QStandardItem *qsi = itemFromIndex(parent.QModelIndex::model()->index(
row, column));
if (!qsi)
qsi = itemFromIndex(parent);
@@ -123,12 +133,14 @@ bool ElementsCollectionModel::canDropMimeData(const QMimeData *data, Qt::DropAct
ElementCollectionItem *eci = static_cast<ElementCollectionItem *>(qsi);
if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri"))
if (data->hasFormat("application/x-qet-element-uri")
|| data->hasFormat("application/x-qet-category-uri"))
{
//Return false if user try to drop a item from a folder to the same folder
//Return false if user try to drop a item from a folder to the same folder
ElementsLocation drop_location(data->text());
for (int i=0 ; i<eci->rowCount() ; i++)
if (static_cast<ElementCollectionItem *>(eci->child(i))->collectionPath() == drop_location.collectionPath())
if (static_cast<ElementCollectionItem *>(eci->child(i))->collectionPath()
== drop_location.collectionPath())
return false;
return true;
@@ -138,19 +150,24 @@ bool ElementsCollectionModel::canDropMimeData(const QMimeData *data, Qt::DropAct
}
/**
* @brief ElementsCollectionModel::dropMimeData
* Reimplemented from QStandardItemModel
* @param data
* @param action
* @param row
* @param column
* @param parent
* @return
*/
bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
@brief ElementsCollectionModel::dropMimeData
Reimplemented from QStandardItemModel
@param data
@param action
@param row
@param column
@param parent
@return
*/
bool ElementsCollectionModel::dropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent)
{
Q_UNUSED(action)
QStandardItem *qsi = itemFromIndex(parent.QModelIndex::model()->index(row, column));
QStandardItem *qsi = itemFromIndex(
parent.QModelIndex::model()->index(row, column));
if (!qsi)
qsi = itemFromIndex(parent);
@@ -161,7 +178,8 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction
if (feci->isCommonCollection())
return false;
if (feci->isElement() && feci->parent() && feci->parent()->type() == FileElementCollectionItem::Type)
if (feci->isElement() && feci->parent() && feci->parent()->type()
== FileElementCollectionItem::Type)
feci = static_cast<FileElementCollectionItem *>(feci->parent());
ElementCollectionHandler ech;
@@ -175,7 +193,9 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction
//If feci have a child with the same path of location,
//we remove the existing child befor insert new child
for (int i=0 ; i<feci->rowCount() ; i++) {
if (static_cast<FileElementCollectionItem *>(feci->child(i))->collectionPath() == location.collectionPath())
if (static_cast<FileElementCollectionItem *>(
feci->child(i))->collectionPath()
== location.collectionPath())
feci->removeRow(i);
}
feci->addChildAtPath(location.fileName());
@@ -187,18 +207,26 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction
else if (qsi->type() == XmlProjectElementCollectionItem::Type) {
XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem*>(qsi);
if (xpeci->isElement() && xpeci->parent() && xpeci->parent()->type() == XmlProjectElementCollectionItem::Type)
if (xpeci->isElement() && xpeci->parent() && xpeci->parent()->type()
== XmlProjectElementCollectionItem::Type)
xpeci = static_cast<XmlProjectElementCollectionItem *>(xpeci->parent());
//before do the copy, we get all collection path of xpeci child,
//for remove it if the copied item have the same path of an existing child.
//We can't do this after the copy, because at the copy if the xml collection have a DomElement with the same path,
//he was removed before the new xml DomElement is inserted
//So the existing child of this will return a null QString when call collectionPath(), because the item
//doesn't exist anymore in the xml collection.
/* before do the copy, we get all collection path of xpeci child,
* for remove it
* if the copied item have the same path of an existing child.
* We can't do this after the copy,
* because at the copy
* if the xml collection have a DomElement with the same path,
* he was removed before the new xml DomElement is inserted
* So the existing child of this will return a null QString
* when call collectionPath(), because the item
* doesn't exist anymore in the xml collection.
*/
QList <QString> child_path_list;
for (int i=0 ; i<xpeci->rowCount() ; i++)
child_path_list.append(static_cast<XmlProjectElementCollectionItem *>(xpeci->child(i, 0))->collectionPath());
child_path_list.append(
static_cast<XmlProjectElementCollectionItem *>(
xpeci->child(i, 0))->collectionPath());
ElementCollectionHandler ech;
@@ -213,18 +241,23 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction
}
/**
* @brief ElementsCollectionModel::loadCollections
* Load the several collections in this model.
* Prefer use this method instead of addCommonCollection, addCustomCollection and addProject,
* because it use multithreading to speed up the loading.
* This method emit loadingProgressRangeChanged(int, int) for know the minimu and maximum progress value
* This method emit loadingProgressValueChanged(int) for know the current progress value
* This method emit loadingFinished for know when loading finished.
* @param common_collection : true for load the common collection
* @param custom_collection : true for load the custom collection
* @param projects : list of projects to load
*/
void ElementsCollectionModel::loadCollections(bool common_collection, bool custom_collection, QList<QETProject *> projects)
@brief ElementsCollectionModel::loadCollections
Load the several collections in this model.
Prefer use this method instead of addCommonCollection,
addCustomCollection and addProject,
because it use multithreading to speed up the loading.
This method emit loadingProgressRangeChanged(int, int)
for know the minimu and maximum progress value
This method emit loadingProgressValueChanged(int)
for know the current progress value
This method emit loadingFinished for know when loading finished.
@param common_collection : true for load the common collection
@param custom_collection : true for load the custom collection
@param projects : list of projects to load
*/
void ElementsCollectionModel::loadCollections(bool common_collection,
bool custom_collection,
QList<QETProject *> projects)
{
m_items_list_to_setUp.clear();
@@ -243,22 +276,29 @@ void ElementsCollectionModel::loadCollections(bool common_collection, bool custo
m_items_list_to_setUp.append(projectItems(project));
}
auto *watcher = new QFutureWatcher<void>();
connect(watcher, &QFutureWatcher<void>::progressValueChanged, this, &ElementsCollectionModel::loadingProgressValueChanged);
connect(watcher, &QFutureWatcher<void>::progressRangeChanged, this, &ElementsCollectionModel::loadingProgressRangeChanged);
connect(watcher, &QFutureWatcher<void>::finished, this, &ElementsCollectionModel::loadingFinished);
connect(watcher, &QFutureWatcher<void>::finished, watcher, &QFutureWatcher<void>::deleteLater);
connect(watcher, &QFutureWatcher<void>::progressValueChanged,
this, &ElementsCollectionModel::loadingProgressValueChanged);
connect(watcher, &QFutureWatcher<void>::progressRangeChanged,
this, &ElementsCollectionModel::loadingProgressRangeChanged);
connect(watcher, &QFutureWatcher<void>::finished,
this, &ElementsCollectionModel::loadingFinished);
connect(watcher, &QFutureWatcher<void>::finished,
watcher, &QFutureWatcher<void>::deleteLater);
m_future = QtConcurrent::map(m_items_list_to_setUp, setUpData);
watcher->setFuture(m_future);
}
/**
* @brief ElementsCollectionModel::addCommonCollection
* Add the common elements collection to this model
*/
@brief ElementsCollectionModel::addCommonCollection
Add the common elements collection to this model
@param set_data
*/
void ElementsCollectionModel::addCommonCollection(bool set_data)
{
FileElementCollectionItem *feci = new FileElementCollectionItem();
if (feci->setRootPath(QETApp::commonElementsDirN(), set_data, m_hide_element)) {
if (feci->setRootPath(QETApp::commonElementsDirN(),
set_data,
m_hide_element)) {
invisibleRootItem()->appendRow(feci);
if (set_data)
feci->setUpData();
@@ -268,9 +308,10 @@ void ElementsCollectionModel::addCommonCollection(bool set_data)
}
/**
* @brief ElementsCollectionModel::addCustomCollection
* Add the custom elements collection to this model
*/
@brief ElementsCollectionModel::addCustomCollection
Add the custom elements collection to this model
@param set_data
*/
void ElementsCollectionModel::addCustomCollection(bool set_data)
{
FileElementCollectionItem *feci = new FileElementCollectionItem();
@@ -284,11 +325,11 @@ void ElementsCollectionModel::addCustomCollection(bool set_data)
}
/**
* @brief ElementsCollectionModel::addLocation
* Add the element or directory to this model.
* If the location is already managed by this model, do nothing.
* @param location
*/
@brief ElementsCollectionModel::addLocation
Add the element or directory to this model.
If the location is already managed by this model, do nothing.
@param location
*/
void ElementsCollectionModel::addLocation(const ElementsLocation& location)
{
QModelIndex index = indexFromLocation(location);
@@ -302,9 +343,12 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location)
QETProject *project = location.project();
if (project) {
XmlProjectElementCollectionItem *xpeci = m_project_hash.value(project);
XmlProjectElementCollectionItem *xpeci =
m_project_hash.value(project);
last_item = xpeci->lastItemForPath(location.collectionPath(false), collection_name);
last_item = xpeci->lastItemForPath(
location.collectionPath(false),
collection_name);
}
}
else if (location.isCustomCollection()) {
@@ -316,10 +360,13 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location)
foreach(ElementCollectionItem *eci, child_list) {
if (eci->type() == FileElementCollectionItem::Type) {
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci);
FileElementCollectionItem *feci =
static_cast<FileElementCollectionItem *>(eci);
if (feci->isCustomCollection()) {
last_item = feci->lastItemForPath(location.collectionPath(false), collection_name);
last_item = feci->lastItemForPath(
location.collectionPath(false),
collection_name);
if(last_item)
break;
}
@@ -332,11 +379,12 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location)
}
/**
* @brief ElementsCollectionModel::addProject
* Add project to this model
* @param project : project to add.
* @param set_data : if true, setUpData is called for every ElementCollectionItem of project
*/
@brief ElementsCollectionModel::addProject
Add project to this model
@param project : project to add.
@param set_data :
if true, setUpData is called for every ElementCollectionItem of project
*/
void ElementsCollectionModel::addProject(QETProject *project, bool set_data)
{
if (m_project_list.contains(project))
@@ -351,17 +399,25 @@ void ElementsCollectionModel::addProject(QETProject *project, bool set_data)
insertRow(row, xpeci);
if (set_data)
xpeci->setUpData();
connect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
connect(project->embeddedElementCollection(), &XmlElementCollection::elementRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
connect(project->embeddedElementCollection(), &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
connect(project->embeddedElementCollection(),
&XmlElementCollection::elementAdded,
this, &ElementsCollectionModel::elementIntegratedToCollection);
connect(project->embeddedElementCollection(),
&XmlElementCollection::elementChanged,
this, &ElementsCollectionModel::updateItem);
connect(project->embeddedElementCollection(),
&XmlElementCollection::elementRemoved,
this, &ElementsCollectionModel::itemRemovedFromCollection);
connect(project->embeddedElementCollection(),
&XmlElementCollection::directoryRemoved,
this, &ElementsCollectionModel::itemRemovedFromCollection);
}
/**
* @brief ElementsCollectionModel::removeProject
* Remove project from this model
* @param project
*/
@brief ElementsCollectionModel::removeProject
Remove project from this model
@param project
*/
void ElementsCollectionModel::removeProject(QETProject *project)
{
if (!m_project_list.contains(project))
@@ -371,27 +427,38 @@ void ElementsCollectionModel::removeProject(QETProject *project)
if (removeRows(row, 1, QModelIndex())) {
m_project_list.removeOne(project);
m_project_hash.remove(project);
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
disconnect(project->embeddedElementCollection(), &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
disconnect(project->embeddedElementCollection(),
&XmlElementCollection::elementAdded,
this,
&ElementsCollectionModel::elementIntegratedToCollection);
disconnect(project->embeddedElementCollection(),
&XmlElementCollection::elementChanged,
this, &ElementsCollectionModel::updateItem);
disconnect(project->embeddedElementCollection(),
&XmlElementCollection::elementRemoved,
this,
&ElementsCollectionModel::itemRemovedFromCollection);
disconnect(project->embeddedElementCollection(),
&XmlElementCollection::directoryRemoved,
this,
&ElementsCollectionModel::itemRemovedFromCollection);
}
}
/**
* @brief ElementsCollectionModel::project
* @return every project added to this model
*/
@brief ElementsCollectionModel::project
@return every project added to this model
*/
QList<QETProject *> ElementsCollectionModel::project() const
{
return m_project_list;
}
/**
* @brief ElementsCollectionModel::highlightUnusedElement
* Highlight every unused element of managed project.
* @See QETProject::unusedElements()
*/
@brief ElementsCollectionModel::highlightUnusedElement
Highlight every unused element of managed project.
@see QETProject::unusedElements()
*/
void ElementsCollectionModel::highlightUnusedElement()
{
QList <ElementsLocation> unused;
@@ -414,9 +481,9 @@ void ElementsCollectionModel::highlightUnusedElement()
}
/**
* @brief ElementsCollectionModel::items
* @return every ElementCollectionItem owned by this model
*/
@brief ElementsCollectionModel::items
@return every ElementCollectionItem owned by this model
*/
QList <ElementCollectionItem *> ElementsCollectionModel::items() const
{
QList <ElementCollectionItem *> list;
@@ -431,10 +498,10 @@ QList <ElementCollectionItem *> ElementsCollectionModel::items() const
}
/**
* @brief ElementsCollectionModel::projectItems
* @param project
* @return return all items for project @project. the list can be empty
*/
@brief ElementsCollectionModel::projectItems
@param project
@return return all items for project @project. the list can be empty
*/
QList<ElementCollectionItem *> ElementsCollectionModel::projectItems(QETProject *project) const
{
QList <ElementCollectionItem *> list;
@@ -449,9 +516,9 @@ QList<ElementCollectionItem *> ElementsCollectionModel::projectItems(QETProject
}
/**
* @brief ElementsCollectionModel::hideElement
* Hide element in this model, only directory is managed
*/
@brief ElementsCollectionModel::hideElement
Hide element in this model, only directory is managed
*/
void ElementsCollectionModel::hideElement()
{
m_hide_element = true;
@@ -463,13 +530,14 @@ void ElementsCollectionModel::hideElement()
}
/**
* @brief ElementsCollectionModel::indexFromLocation
* Return the index who represent @location.
* Index can be non valid
* @param location
* @return
*/
QModelIndex ElementsCollectionModel::indexFromLocation(const ElementsLocation &location)
@brief ElementsCollectionModel::indexFromLocation
Return the index who represent @location.
Index can be non valid
@param location
@return
*/
QModelIndex ElementsCollectionModel::indexFromLocation(
const ElementsLocation &location)
{
QList <ElementCollectionItem *> child_list;
@@ -502,11 +570,12 @@ QModelIndex ElementsCollectionModel::indexFromLocation(const ElementsLocation &l
}
/**
* @brief ElementsCollectionModel::elementIntegratedToCollection
* When an element is added to embedded collection of a project,
* this method create and display the new element
* @param path -The path of the new element in the embedded collection of a project
*/
@brief ElementsCollectionModel::elementIntegratedToCollection
When an element is added to embedded collection of a project,
this method create and display the new element
@param path :
-The path of the new element in the embedded collection of a project
*/
void ElementsCollectionModel::elementIntegratedToCollection(const QString& path)
{
QObject *object = sender();
@@ -536,10 +605,10 @@ void ElementsCollectionModel::elementIntegratedToCollection(const QString& path)
}
/**
* @brief ElementsCollectionModel::itemRemovedFromCollection
* This method must be called by a signal, to get a sender.
* @param path
*/
@brief ElementsCollectionModel::itemRemovedFromCollection
This method must be called by a signal, to get a sender.
@param path
*/
void ElementsCollectionModel::itemRemovedFromCollection(const QString& path)
{
QObject *object = sender();
@@ -564,10 +633,10 @@ void ElementsCollectionModel::itemRemovedFromCollection(const QString& path)
}
/**
* @brief ElementsCollectionModel::updateItem
* Update the item at path
* @param path
*/
@brief ElementsCollectionModel::updateItem
Update the item at path
@param path
*/
void ElementsCollectionModel::updateItem(const QString& path)
{
QObject *object = sender();