added a second user-collection

This commit is contained in:
plc-user
2023-12-09 12:02:04 +01:00
parent 457aeb6883
commit f519499a66
30 changed files with 589 additions and 335 deletions

View File

@@ -258,6 +258,7 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data,
@param projects : list of projects to load
*/
void ElementsCollectionModel::loadCollections(bool common_collection,
bool company_collection,
bool custom_collection,
QList<QETProject *> projects)
{
@@ -265,10 +266,12 @@ void ElementsCollectionModel::loadCollections(bool common_collection,
if (common_collection)
addCommonCollection(false);
if (company_collection)
addCompanyCollection(false);
if (custom_collection)
addCustomCollection(false);
if (common_collection || custom_collection)
if (common_collection || company_collection || custom_collection)
m_items_list_to_setUp.append(items());
@@ -321,22 +324,41 @@ void ElementsCollectionModel::addCommonCollection(bool set_data)
}
/**
@brief ElementsCollectionModel::addCustomCollection
Add the custom elements collection to this model
@param set_data
@brief ElementsCollectionModel::addCompanyCollection
Add the company elements collection to this model
@param set_data
*/
void ElementsCollectionModel::addCompanyCollection(bool set_data)
{
FileElementCollectionItem *feci = new FileElementCollectionItem();
if (feci->setRootPath(QETApp::companyElementsDirN(),
set_data,
m_hide_element)) {
invisibleRootItem()->appendRow(feci);
if (set_data)
feci->setUpData();
}
else
delete feci;
}
/**
@brief ElementsCollectionModel::addCustomCollection
Add the custom elements collection to this model
@param set_data
*/
void ElementsCollectionModel::addCustomCollection(bool set_data)
{
FileElementCollectionItem *feci = new FileElementCollectionItem();
if (feci->setRootPath(QETApp::customElementsDirN(),
set_data,
m_hide_element)) {
invisibleRootItem()->appendRow(feci);
if (set_data)
feci->setUpData();
}
else
delete feci;
FileElementCollectionItem *feci = new FileElementCollectionItem();
if (feci->setRootPath(QETApp::customElementsDirN(),
set_data,
m_hide_element)) {
invisibleRootItem()->appendRow(feci);
if (set_data)
feci->setUpData();
}
else
delete feci;
}
/**
@@ -557,8 +579,9 @@ QModelIndex ElementsCollectionModel::indexFromLocation(
{
QList <ElementCollectionItem *> child_list;
for (int i=0 ; i<rowCount() ; i++)
for (int i=0 ; i<rowCount() ; i++){
child_list.append(static_cast<ElementCollectionItem *>(item(i)));
}
foreach(ElementCollectionItem *eci, child_list) {
@@ -567,7 +590,8 @@ QModelIndex ElementsCollectionModel::indexFromLocation(
if (eci->type() == FileElementCollectionItem::Type) {
if (FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci)) {
if ( (location.isCommonCollection() && feci->isCommonCollection()) ||
(location.isCustomCollection() && !feci->isCommonCollection()) ) {
(location.isCompanyCollection() && feci->isCompanyCollection()) ||
(location.isCustomCollection() && !feci->isCommonCollection()) ) {
match_eci = feci->itemAtPath(location.collectionPath(false));
}
}

View File

@@ -42,10 +42,11 @@ class ElementsCollectionModel : public QStandardItemModel
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
void loadCollections(bool common_collection, bool custom_collection, QList<QETProject *> projects);
void loadCollections(bool common_collection, bool company_collection, bool custom_collection, QList<QETProject *> projects);
void addCommonCollection(bool set_data = true);
void addCustomCollection(bool set_data = true);
void addCommonCollection(bool set_data = true);
void addCompanyCollection(bool set_data = true);
void addCustomCollection(bool set_data = true);
void addLocation(const ElementsLocation& location);
void addProject(QETProject *project, bool set_data = true);

View File

@@ -96,7 +96,7 @@ void ElementsCollectionWidget::addProject(QETProject *project)
m_progress_bar->show();
m_tree_view->setDisabled(true);
QList <QETProject *> prj; prj.append(project);
m_model->loadCollections(false,false, prj);
m_model->loadCollections(false, false, false, prj);
}
else {
m_waiting_project.append(project);
@@ -387,7 +387,8 @@ void ElementsCollectionWidget::deleteElement()
if (! (loc.isElement()
&& loc.exist()
&& loc.isFileSystem()
&& loc.collectionPath().startsWith("custom://")) ) return;
&& (loc.collectionPath().startsWith("company://")
|| loc.collectionPath().startsWith("custom://"))) ) return;
if (QET::QetMessageBox::question(
this,
@@ -430,7 +431,8 @@ void ElementsCollectionWidget::deleteDirectory()
if (! (loc.isDirectory()
&& loc.exist()
&& loc.isFileSystem()
&& loc.collectionPath().startsWith("custom://")) ) return;
&& (loc.collectionPath().startsWith("company://")
|| loc.collectionPath().startsWith("custom://"))) ) return;
if (QET::QetMessageBox::question(
this,
@@ -655,7 +657,7 @@ void ElementsCollectionWidget::reload()
this,
&ElementsCollectionWidget::loadingFinished);
m_new_model->loadCollections(true, true, project_list);
m_new_model->loadCollections(true, true, true, project_list);
}
/**

View File

@@ -168,7 +168,7 @@ QString ElementsLocation::baseName() const
@brief ElementsLocation::collectionPath
Return the path of the represented element relative to collection
if protocol is true the path is prepended by
the collection type (common://, custom:// or embed://)
the collection type (common://, company://, custom:// or embed://)
else if false,
only the collection path is returned without the collection type.
@param protocol
@@ -181,7 +181,7 @@ QString ElementsLocation::collectionPath(bool protocol) const
else
{
QString path = m_collection_path;
return path.remove(QRegularExpression("common://|custom://|embed://"));
return path.remove(QRegularExpression("common://|company://|custom://|embed://"));
}
}
@@ -229,7 +229,7 @@ QString ElementsLocation::path() const
@brief ElementsLocation::setPath
Set the path of this item.
The path can be relative to a collection
(start by common:// , custom:// or embed://) or not.
(start by common://, company://, custom:// or embed://) or not.
@param path
*/
void ElementsLocation::setPath(const QString &path)
@@ -290,15 +290,20 @@ void ElementsLocation::setPath(const QString &path)
// The path is in file system,
// the given path is relative to common or custom collection
else if (path.startsWith("common://") || path.startsWith("custom://"))
else if (path.startsWith("common://") || path.startsWith("company://") || path.startsWith("custom://"))
{
QString p;
if (path.startsWith("common://"))
{
tmp_path.remove("common://");
p = QETApp::commonElementsDirN() + "/" + tmp_path;
}
else
if (path.startsWith("common://"))
{
tmp_path.remove("common://");
p = QETApp::commonElementsDirN() + "/" + tmp_path;
}
else if (path.startsWith("company://"))
{
tmp_path.remove("company://");
p = QETApp::companyElementsDirN() + "/" + tmp_path;
}
else
{
tmp_path.remove("custom://");
p = QETApp::customElementsDirN() + "/" + tmp_path;
@@ -314,13 +319,19 @@ void ElementsLocation::setPath(const QString &path)
if(path_.endsWith(".elmt"))
{
m_file_system_path = path_;
if (path_.startsWith(QETApp::commonElementsDirN()))
{
path_.remove(QETApp::commonElementsDirN()+="/");
path_.prepend("common://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
if (path_.startsWith(QETApp::commonElementsDirN()))
{
path_.remove(QETApp::commonElementsDirN()+="/");
path_.prepend("common://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::companyElementsDirN()))
{
path_.remove(QETApp::companyElementsDirN()+="/");
path_.prepend("company://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
{
path_.remove(QETApp::customElementsDirN()+="/");
path_.prepend("custom://");
@@ -330,13 +341,19 @@ void ElementsLocation::setPath(const QString &path)
else
{
m_file_system_path = path_;
if (path_.startsWith(QETApp::commonElementsDirN()))
{
path_.remove(QETApp::commonElementsDirN()+="/");
path_.prepend("common://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
if (path_.startsWith(QETApp::commonElementsDirN()))
{
path_.remove(QETApp::commonElementsDirN()+="/");
path_.prepend("common://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::companyElementsDirN()))
{
path_.remove(QETApp::companyElementsDirN()+="/");
path_.prepend("company://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
{
path_.remove(QETApp::customElementsDirN()+="/");
path_.prepend("custom://");
@@ -484,13 +501,23 @@ bool ElementsLocation::isFileSystem() const
}
/**
@brief ElementsLocation::isCommonCollection
@return
True if this location represent an item from the common collection
@brief ElementsLocation::isCommonCollection
@return
True if this location represent an item from the common collection
*/
bool ElementsLocation::isCommonCollection() const
{
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
}
/**
@brief ElementsLocation::isCompanyCollection
@return
True if this location represent an item from the company collection
*/
bool ElementsLocation::isCompanyCollection() const
{
return fileSystemPath().startsWith(QETApp::companyElementsDirN());
}
/**

View File

@@ -75,8 +75,9 @@ class ElementsLocation
bool isElement() const;
bool isDirectory() const;
bool isFileSystem() const;
bool isCommonCollection() const;
bool isCustomCollection() const;
bool isCommonCollection() const;
bool isCompanyCollection() const;
bool isCustomCollection() const;
bool isProject() const;
bool exist() const;
bool isWritable() const;

View File

@@ -120,9 +120,11 @@ QString FileElementCollectionItem::localName()
else if (isDir()) {
if (isCollectionRoot()) {
if (m_path == QETApp::commonElementsDirN())
setText(QObject::tr("Collection QET"));
else if (m_path == QETApp::customElementsDirN())
if (m_path == QETApp::commonElementsDirN())
setText(QObject::tr("Collection QET"));
else if (m_path == QETApp::companyElementsDirN())
setText(QObject::tr("Collection Company"));
else if (m_path == QETApp::customElementsDirN())
setText(QObject::tr("Collection utilisateur"));
else
setText(QObject::tr("Collection inconnue"));
@@ -194,6 +196,8 @@ QString FileElementCollectionItem::collectionPath() const
if (isCollectionRoot()) {
if (m_path == QETApp::commonElementsDirN())
return "common://";
else if (m_path == QETApp::companyElementsDirN())
return "company://";
else
return "custom://";
}
@@ -217,19 +221,29 @@ QString FileElementCollectionItem::collectionPath() const
bool FileElementCollectionItem::isCollectionRoot() const
{
if (m_path == QETApp::commonElementsDirN()
|| m_path == QETApp::customElementsDirN())
return true;
|| m_path == QETApp::companyElementsDirN()
|| m_path == QETApp::customElementsDirN())
return true;
else
return false;
}
/**
@brief FileElementCollectionItem::isCommonCollection
@return True if this item represent the common collection
@brief FileElementCollectionItem::isCommonCollection
@return True if this item represent the common collection
*/
bool FileElementCollectionItem::isCommonCollection() const
{
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
}
/**
@brief FileElementCollectionItem::isCompanyCollection
@return True if this item represent the company collection
*/
bool FileElementCollectionItem::isCompanyCollection() const
{
return fileSystemPath().startsWith(QETApp::companyElementsDirN());
}
/**
@@ -306,6 +320,8 @@ void FileElementCollectionItem::setUpIcon()
if (isCollectionRoot()) {
if (m_path == QETApp::commonElementsDirN())
setIcon(QIcon(":/ico/16x16/qet.png"));
else if (m_path == QETApp::companyElementsDirN())
setIcon(QIcon(":/ico/16x16/go-company.png"));
else
setIcon(QIcon(":/ico/16x16/go-home.png"));
}

View File

@@ -47,8 +47,9 @@ class FileElementCollectionItem : public ElementCollectionItem
QString name() const override;
QString collectionPath() const override;
bool isCollectionRoot() const override;
bool isCommonCollection() const;
bool isCustomCollection() const;
bool isCommonCollection() const;
bool isCompanyCollection() const;
bool isCustomCollection() const;
void addChildAtPath(const QString &collection_name) override;
void setUpData() override;