2015-12-08 16:52:10 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2015-12-08 16:52:10 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
#include "elementscollectionwidget.h"
|
|
|
|
#include "elementscollectionmodel.h"
|
|
|
|
#include "elementcollectionitem.h"
|
|
|
|
#include "qeticons.h"
|
|
|
|
#include "fileelementcollectionitem.h"
|
|
|
|
#include "elementslocation.h"
|
|
|
|
#include "qetapp.h"
|
|
|
|
#include "qetmessagebox.h"
|
|
|
|
#include "elementscategoryeditor.h"
|
|
|
|
#include "newelementwizard.h"
|
2015-12-16 17:16:15 +00:00
|
|
|
#include "xmlprojectelementcollectionitem.h"
|
|
|
|
#include "qetproject.h"
|
2016-03-24 10:35:00 +00:00
|
|
|
#include "qetelementeditor.h"
|
2016-05-22 14:51:09 +00:00
|
|
|
#include "elementstreeview.h"
|
2016-11-10 19:49:33 +00:00
|
|
|
#include "qetdiagrameditor.h"
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2016-06-05 16:34:46 +00:00
|
|
|
#include <QTimer>
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::ElementsCollectionWidget
|
|
|
|
* Default constructor.
|
|
|
|
* @param parent : parent widget of this widget.
|
|
|
|
*/
|
|
|
|
ElementsCollectionWidget::ElementsCollectionWidget(QWidget *parent):
|
|
|
|
QWidget(parent),
|
2015-12-16 17:16:15 +00:00
|
|
|
m_model(nullptr)
|
2015-12-08 16:52:10 +00:00
|
|
|
{
|
|
|
|
setUpWidget();
|
|
|
|
setUpAction();
|
|
|
|
setUpConnection();
|
2016-06-10 16:20:01 +00:00
|
|
|
|
|
|
|
//Timer is used to avoid launching a new search for each letter typed by user
|
|
|
|
//Timer is started or restarted at every time user type a new letter.
|
|
|
|
//When the timer emit timeout, we start the search.
|
|
|
|
m_search_timer.setInterval(500);
|
|
|
|
m_search_timer.setSingleShot(true);
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::expandFirstItems
|
|
|
|
* Expand each first item in the tree view
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::expandFirstItems()
|
|
|
|
{
|
2016-06-05 16:34:46 +00:00
|
|
|
if (!m_model)
|
|
|
|
return;
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
for (int i=0; i < m_model->rowCount() ; i++)
|
|
|
|
showAndExpandItem(m_model->index(i, 0), false);
|
|
|
|
}
|
|
|
|
|
2015-12-16 17:16:15 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::addProject
|
|
|
|
* Add @project to be displayed
|
|
|
|
* @param project
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::addProject(QETProject *project) {
|
2016-06-30 09:12:25 +00:00
|
|
|
if (m_model) {
|
2016-07-14 11:58:56 +00:00
|
|
|
QList <QETProject *> prj; prj.append(project);
|
|
|
|
m_progress_bar->show();
|
|
|
|
connect(m_model, &ElementsCollectionModel::loadingMaxValue, m_progress_bar, &QProgressBar::setMaximum);
|
|
|
|
connect(m_model, &ElementsCollectionModel::loadingProgressValue, m_progress_bar, &QProgressBar::setValue);
|
|
|
|
m_model->loadCollections(false,false, prj);
|
|
|
|
disconnect(m_model, &ElementsCollectionModel::loadingMaxValue, m_progress_bar, &QProgressBar::setMaximum);
|
|
|
|
disconnect(m_model, &ElementsCollectionModel::loadingProgressValue, m_progress_bar, &QProgressBar::setValue);
|
|
|
|
m_progress_bar->hide();
|
2016-06-30 09:12:25 +00:00
|
|
|
m_model->highlightUnusedElement();
|
|
|
|
}
|
2016-06-06 19:07:13 +00:00
|
|
|
else
|
|
|
|
m_waiting_project.append(project);
|
2015-12-16 17:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElementsCollectionWidget::removeProject(QETProject *project) {
|
2016-06-06 19:07:13 +00:00
|
|
|
if (m_model)
|
|
|
|
m_model->removeProject(project);
|
2015-12-16 17:16:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::highlightUnusedElement
|
|
|
|
* highlight the unused element
|
|
|
|
* @See ElementsCollectionModel::highlightUnusedElement()
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::highlightUnusedElement()
|
|
|
|
{
|
|
|
|
m_model->highlightUnusedElement();
|
|
|
|
}
|
|
|
|
|
2016-06-05 16:34:46 +00:00
|
|
|
bool ElementsCollectionWidget::event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (m_first_show && event->type() == QEvent::WindowActivate) {
|
|
|
|
m_first_show = false;
|
2016-06-05 19:55:41 +00:00
|
|
|
QTimer::singleShot(250, this, SLOT(reload()));
|
2016-06-05 16:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:49:33 +00:00
|
|
|
void ElementsCollectionWidget::leaveEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (QETDiagramEditor *qde = QETApp::diagramEditorAncestorOf(this))
|
|
|
|
qde->statusBar()->clearMessage();
|
|
|
|
|
|
|
|
QWidget::leaveEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
void ElementsCollectionWidget::setUpAction()
|
|
|
|
{
|
|
|
|
m_open_dir = new QAction(QET::Icons::DocumentOpen, tr("Ouvrir le dossier correspondant"), this);
|
|
|
|
m_edit_element = new QAction(QET::Icons::ElementEdit, tr("Éditer l'élément"), this);
|
|
|
|
m_delete_element = new QAction(QET::Icons::ElementDelete, tr("Supprimer l'élément"), this);
|
|
|
|
m_delete_dir = new QAction(QET::Icons::FolderDelete, tr("Supprimer le dossier"), this);
|
|
|
|
m_reload = new QAction(QET::Icons::ViewRefresh, tr("Recharger les collections"), this);
|
|
|
|
m_edit_dir = new QAction(QET::Icons::FolderEdit, tr("Éditer le dossier"), this);
|
|
|
|
m_new_directory = new QAction(QET::Icons::FolderNew, tr("Nouveau dossier"), this);
|
|
|
|
m_new_element = new QAction(QET::Icons::ElementNew, tr("Nouvel élément"), this);
|
2016-02-26 09:58:55 +00:00
|
|
|
m_show_this_dir = new QAction(QET::Icons::ZoomDraw, tr("Afficher uniquement ce dossier"), this);
|
|
|
|
m_show_all_dir = new QAction(QET::Icons::ZoomOriginal, tr("Afficher tous les dossiers"), this);
|
2016-10-15 13:39:02 +00:00
|
|
|
m_dir_propertie = new QAction(QET::Icons::Folder, tr("Propriété du dossier"), this);
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::setUpWidget
|
|
|
|
* Setup this widget
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::setUpWidget()
|
|
|
|
{
|
|
|
|
//Setup the main layout
|
|
|
|
m_main_vlayout = new QVBoxLayout(this);
|
|
|
|
this->setLayout(m_main_vlayout);
|
|
|
|
|
|
|
|
m_search_field = new QLineEdit(this);
|
|
|
|
m_search_field->setPlaceholderText(tr("Rechercher"));
|
|
|
|
m_search_field->setClearButtonEnabled(true);
|
|
|
|
m_main_vlayout->addWidget(m_search_field);
|
|
|
|
|
|
|
|
//Setup the tree view
|
2016-05-22 14:51:09 +00:00
|
|
|
m_tree_view = new ElementsTreeView(this);
|
2015-12-08 16:52:10 +00:00
|
|
|
m_tree_view->setHeaderHidden(true);
|
|
|
|
m_tree_view->setIconSize(QSize(50, 50));
|
|
|
|
m_tree_view->setDragDropMode(QAbstractItemView::DragDrop);
|
|
|
|
m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
2016-01-16 14:25:20 +00:00
|
|
|
m_tree_view->setAutoExpandDelay(500);
|
|
|
|
m_tree_view->setAnimated(true);
|
2016-03-04 13:03:39 +00:00
|
|
|
m_tree_view->setMouseTracking(true);
|
2016-01-16 14:25:20 +00:00
|
|
|
m_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
2015-12-08 16:52:10 +00:00
|
|
|
m_main_vlayout->addWidget(m_tree_view);
|
|
|
|
|
2015-12-09 20:27:31 +00:00
|
|
|
//Setup the progress bar
|
|
|
|
m_progress_bar = new QProgressBar(this);
|
|
|
|
m_progress_bar->setFormat(tr("Chargement") + " %p%");
|
|
|
|
m_main_vlayout->addWidget(m_progress_bar);
|
|
|
|
m_progress_bar->hide();
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
m_context_menu = new QMenu(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::setUpConnection
|
|
|
|
* Setup the connection used in this widget
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::setUpConnection()
|
|
|
|
{
|
|
|
|
connect(m_tree_view, &QTreeView::customContextMenuRequested, this, &ElementsCollectionWidget::customContextMenu);
|
2016-06-10 16:20:01 +00:00
|
|
|
connect(m_search_field, &QLineEdit::textEdited, [this]() {m_search_timer.start();});
|
|
|
|
connect(&m_search_timer, &QTimer::timeout, this, &ElementsCollectionWidget::search);
|
2015-12-08 16:52:10 +00:00
|
|
|
connect(m_open_dir, &QAction::triggered, this, &ElementsCollectionWidget::openDir);
|
|
|
|
connect(m_edit_element, &QAction::triggered, this, &ElementsCollectionWidget::editElement);
|
|
|
|
connect(m_delete_element, &QAction::triggered, this, &ElementsCollectionWidget::deleteElement);
|
|
|
|
connect(m_delete_dir, &QAction::triggered, this, &ElementsCollectionWidget::deleteDirectory);
|
|
|
|
connect(m_reload, &QAction::triggered, this, &ElementsCollectionWidget::reload);
|
|
|
|
connect(m_edit_dir, &QAction::triggered, this, &ElementsCollectionWidget::editDirectory);
|
|
|
|
connect(m_new_directory, &QAction::triggered, this, &ElementsCollectionWidget::newDirectory);
|
|
|
|
connect(m_new_element, &QAction::triggered, this, &ElementsCollectionWidget::newElement);
|
2016-02-26 09:58:55 +00:00
|
|
|
connect(m_show_this_dir, &QAction::triggered, this, &ElementsCollectionWidget::showThisDir);
|
|
|
|
connect(m_show_all_dir, &QAction::triggered, this, &ElementsCollectionWidget::resetShowThisDir);
|
2016-10-15 13:39:02 +00:00
|
|
|
connect(m_dir_propertie, &QAction::triggered, this, &ElementsCollectionWidget::dirProperties);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
connect(m_tree_view, &QTreeView::doubleClicked, [this](const QModelIndex &index) {
|
2015-12-16 17:16:15 +00:00
|
|
|
this->m_index_at_context_menu = index ;
|
2015-12-08 16:52:10 +00:00
|
|
|
this->editElement();});
|
2016-11-10 19:49:33 +00:00
|
|
|
|
|
|
|
connect(m_tree_view, &QTreeView::entered, [this] (const QModelIndex &index) {
|
|
|
|
QETDiagramEditor *qde = QETApp::diagramEditorAncestorOf(this);
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(index);
|
|
|
|
if (qde && eci)
|
|
|
|
qde->statusBar()->showMessage(eci->localName());
|
|
|
|
});
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::customContextMenu
|
|
|
|
* Display the context menu of this widget at @point
|
|
|
|
* @param point
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
|
|
|
{
|
2015-12-12 11:09:31 +00:00
|
|
|
m_index_at_context_menu = m_tree_view->indexAt(point);
|
|
|
|
if (!m_index_at_context_menu.isValid()) return;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
m_context_menu->clear();
|
2015-12-16 17:16:15 +00:00
|
|
|
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
|
|
|
bool add_open_dir = false;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
if (eci->isElement())
|
|
|
|
m_context_menu->addAction(m_edit_element);
|
|
|
|
|
|
|
|
if (eci->type() == FileElementCollectionItem::Type)
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
add_open_dir = true;
|
2015-12-08 16:52:10 +00:00
|
|
|
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
|
|
|
|
if (!feci->isCommonCollection())
|
|
|
|
{
|
|
|
|
if (feci->isDir())
|
|
|
|
{
|
|
|
|
m_context_menu->addAction(m_new_element);
|
|
|
|
m_context_menu->addAction(m_new_directory);
|
|
|
|
if (!feci->isCollectionRoot())
|
|
|
|
{
|
|
|
|
m_context_menu->addAction(m_edit_dir);
|
|
|
|
m_context_menu->addAction(m_delete_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_context_menu->addAction(m_delete_element);
|
|
|
|
}
|
|
|
|
}
|
2015-12-16 17:16:15 +00:00
|
|
|
if (eci->type() == XmlProjectElementCollectionItem::Type)
|
|
|
|
{
|
|
|
|
XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem *>(eci);
|
|
|
|
if (xpeci->isCollectionRoot())
|
|
|
|
add_open_dir = true;
|
|
|
|
}
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
m_context_menu->addSeparator();
|
2016-02-26 09:58:55 +00:00
|
|
|
if (eci->isDir())
|
|
|
|
{
|
|
|
|
m_context_menu->addAction(m_show_this_dir);
|
|
|
|
//there is a current filtered dir, add entry to reset it
|
|
|
|
if (m_showed_index.isValid())
|
|
|
|
m_context_menu->addAction(m_show_all_dir);
|
2016-10-15 13:39:02 +00:00
|
|
|
|
|
|
|
m_context_menu->addAction(m_dir_propertie);
|
2016-02-26 09:58:55 +00:00
|
|
|
}
|
2015-12-16 17:16:15 +00:00
|
|
|
if (add_open_dir)
|
|
|
|
m_context_menu->addAction(m_open_dir);
|
2015-12-08 16:52:10 +00:00
|
|
|
m_context_menu->addAction(m_reload);
|
|
|
|
|
|
|
|
m_context_menu->popup(mapToGlobal(m_tree_view->mapToParent(point)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::openDir
|
|
|
|
* Open the directory represented by the current selected item
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::openDir()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
|
|
|
if (!eci) return;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2015-12-16 17:16:15 +00:00
|
|
|
if (eci->type() == FileElementCollectionItem::Type)
|
2016-10-04 00:54:13 +00:00
|
|
|
|
2016-10-04 10:37:02 +00:00
|
|
|
#ifdef Q_OS_LINUX
|
2016-10-04 00:54:13 +00:00
|
|
|
QDesktopServices::openUrl(static_cast<FileElementCollectionItem*>(eci)->dirPath());
|
2016-10-04 10:37:02 +00:00
|
|
|
#else
|
|
|
|
QDesktopServices::openUrl(QUrl("file:///" + static_cast<FileElementCollectionItem*>(eci)->dirPath()));
|
2016-10-04 00:54:13 +00:00
|
|
|
#endif
|
2015-12-16 17:16:15 +00:00
|
|
|
else if (eci->type() == XmlProjectElementCollectionItem::Type)
|
2016-10-04 00:54:13 +00:00
|
|
|
|
2016-10-04 10:37:02 +00:00
|
|
|
#ifdef Q_OS_LINUX
|
2016-10-04 00:54:13 +00:00
|
|
|
QDesktopServices::openUrl(static_cast<XmlProjectElementCollectionItem*>(eci)->project()->currentDir());
|
2016-10-04 10:37:02 +00:00
|
|
|
#else
|
|
|
|
QDesktopServices::openUrl(QUrl("file:///" + static_cast<XmlProjectElementCollectionItem*>(eci)->project()->currentDir()));
|
2016-10-04 00:54:13 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::editElement
|
|
|
|
* Edit the element represented by the current selected item
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::editElement()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2016-03-31 17:28:44 +00:00
|
|
|
if ( !(eci && eci->isElement()) ) return;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2016-03-31 17:28:44 +00:00
|
|
|
ElementsLocation location(eci->collectionPath());
|
2016-03-24 10:35:00 +00:00
|
|
|
|
|
|
|
QETApp *app = QETApp::instance();
|
|
|
|
app->openElementLocations(QList<ElementsLocation>() << location);
|
|
|
|
|
|
|
|
foreach (QETElementEditor *element_editor, app->elementEditors())
|
2016-06-17 08:41:09 +00:00
|
|
|
connect(element_editor, &QETElementEditor::saveToLocation, this, &ElementsCollectionWidget::locationWasSaved);
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::deleteElement
|
|
|
|
* Delete the element represented by the current selected item.
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::deleteElement()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2015-12-12 11:09:31 +00:00
|
|
|
if (!eci) return;
|
2016-05-05 13:31:04 +00:00
|
|
|
|
|
|
|
ElementsLocation loc(eci->collectionPath());
|
|
|
|
if (! (loc.isElement() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
if (QET::QetMessageBox::question(this,
|
|
|
|
tr("Supprimer l'élément ?", "message box title"),
|
|
|
|
tr("Êtes-vous sûr de vouloir supprimer cet élément ?\n", "message box content"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
|
|
|
|
{
|
2016-05-05 13:31:04 +00:00
|
|
|
QFile file(loc.fileSystemPath());
|
|
|
|
if (file.remove())
|
|
|
|
{
|
|
|
|
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
|
|
|
|
}
|
|
|
|
else
|
2015-12-08 16:52:10 +00:00
|
|
|
{
|
|
|
|
QET::QetMessageBox::warning(this,
|
|
|
|
tr("Suppression de l'élément", "message box title"),
|
|
|
|
tr("La suppression de l'élément a échoué.", "message box content"));
|
2016-05-05 13:31:04 +00:00
|
|
|
}
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::deleteDirectory
|
|
|
|
* Delete directory represented by the current selected item
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::deleteDirectory()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2015-12-12 11:09:31 +00:00
|
|
|
if (!eci) return;
|
2016-05-05 13:31:04 +00:00
|
|
|
|
|
|
|
ElementsLocation loc (eci->collectionPath());
|
|
|
|
if (! (loc.isDirectory() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
if (QET::QetMessageBox::question(this,
|
|
|
|
tr("Supprimer le dossier?", "message box title"),
|
|
|
|
tr("Êtes-vous sûr de vouloir supprimer le dossier ?\n"
|
|
|
|
"Tout les éléments et les dossier contenus dans ce dossier seront supprimés.",
|
|
|
|
"message box content"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
|
|
|
|
{
|
2016-05-05 13:31:04 +00:00
|
|
|
QDir dir (loc.fileSystemPath());
|
|
|
|
if (dir.removeRecursively())
|
|
|
|
{
|
|
|
|
m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
|
|
|
|
}
|
|
|
|
else
|
2015-12-08 16:52:10 +00:00
|
|
|
{
|
|
|
|
QET::QetMessageBox::warning(this,
|
|
|
|
tr("Suppression du dossier", "message box title"),
|
|
|
|
tr("La suppression du dossier a échoué.", "message box content"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::editDirectory
|
|
|
|
* Edit the directory represented by the current selected item
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::editDirectory()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
if (eci->type() != FileElementCollectionItem::Type) return;
|
|
|
|
|
|
|
|
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
|
|
|
|
if(feci->isCommonCollection()) return;
|
|
|
|
|
|
|
|
ElementsLocation location(feci->collectionPath());
|
|
|
|
ElementsCategoryEditor ece(location, true, this);
|
2016-05-12 15:41:55 +00:00
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
if (ece.exec() == QDialog::Accepted)
|
2016-05-12 15:41:55 +00:00
|
|
|
eci->clearData();
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::newDirectory
|
|
|
|
* Create a new directory
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::newDirectory()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
if (eci->type() != FileElementCollectionItem::Type) return;
|
|
|
|
|
|
|
|
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
|
|
|
|
if(feci->isCommonCollection()) return;
|
|
|
|
|
|
|
|
ElementsLocation location(feci->collectionPath());
|
|
|
|
ElementsCategoryEditor new_dir_editor(location, false, this);
|
2016-06-17 09:09:46 +00:00
|
|
|
if (new_dir_editor.exec() == QDialog::Accepted)
|
|
|
|
m_model->addLocation(new_dir_editor.createdLocation());
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::newElement
|
|
|
|
* Create a new element.
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::newElement()
|
|
|
|
{
|
2015-12-16 17:16:15 +00:00
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2016-05-15 14:46:01 +00:00
|
|
|
if (eci->type() != FileElementCollectionItem::Type) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
|
2016-05-15 14:46:01 +00:00
|
|
|
if(feci->isCommonCollection()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
NewElementWizard elmt_wizard(this);
|
2016-05-15 14:46:01 +00:00
|
|
|
ElementsLocation loc(feci->collectionPath());
|
|
|
|
elmt_wizard.preselectedLocation(loc);
|
2015-12-08 16:52:10 +00:00
|
|
|
elmt_wizard.exec();
|
2016-06-17 09:09:46 +00:00
|
|
|
|
|
|
|
foreach (QETElementEditor *element_editor, QETApp::instance()->elementEditors())
|
|
|
|
connect(element_editor, &QETElementEditor::saveToLocation, this, &ElementsCollectionWidget::locationWasSaved);
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 09:58:55 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::showThisDir
|
|
|
|
* Hide all directories except the pointed dir;
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::showThisDir()
|
|
|
|
{
|
|
|
|
//Disable the yellow background of the previous index
|
|
|
|
if (m_showed_index.isValid())
|
|
|
|
{
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
|
|
|
|
if (eci)
|
2016-06-05 16:34:46 +00:00
|
|
|
eci->setBackground(QBrush());
|
2016-02-26 09:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_showed_index = m_index_at_context_menu;
|
|
|
|
if (m_showed_index.isValid())
|
|
|
|
{
|
|
|
|
hideCollection(true);
|
|
|
|
showAndExpandItem(m_showed_index, true, true);
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
|
|
|
|
if (eci)
|
2016-06-05 16:34:46 +00:00
|
|
|
eci->setBackground(QBrush(Qt::yellow));
|
2016-06-10 16:20:01 +00:00
|
|
|
search();
|
2016-02-26 09:58:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
resetShowThisDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::resetShowThisDir
|
|
|
|
* reset show this dir, all collection are show.
|
|
|
|
* If search field isn't empty, apply the search after show all collection
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::resetShowThisDir()
|
|
|
|
{
|
|
|
|
if (m_showed_index.isValid())
|
|
|
|
{
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
|
|
|
|
if (eci)
|
2016-06-05 16:34:46 +00:00
|
|
|
eci->setBackground(QBrush());
|
2016-02-26 09:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_showed_index = QModelIndex();
|
2016-06-10 16:20:01 +00:00
|
|
|
search();
|
2016-02-26 09:58:55 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 13:39:02 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::dirProperties
|
|
|
|
* Open an informative dialog about the curent index
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::dirProperties()
|
|
|
|
{
|
|
|
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
|
|
|
if (eci && eci->isDir()) {
|
|
|
|
QString txt1 = tr("Le dossier %1 contient").arg(eci->localName());
|
|
|
|
QString txt2 = tr("%n élément(s), répartie(s)", "", eci->elementsChild().size());
|
|
|
|
QString txt3 = tr("dans %n dossier(s).", "" , eci->directoriesChild().size());
|
|
|
|
QString txt4 = tr("Chemin de la collection : %1").arg(eci->collectionPath());
|
|
|
|
QString txt5;
|
|
|
|
if (eci->type() == FileElementCollectionItem::Type) {
|
|
|
|
txt5 = tr("Chemin dans le système de fichiers : %1").arg(static_cast<FileElementCollectionItem*>(eci)->fileSystemPath());
|
|
|
|
}
|
|
|
|
QMessageBox::information(this,
|
|
|
|
tr("Propriété du dossier %1").arg(eci->localName()),
|
|
|
|
txt1 + " " + txt2 + " " + txt3 + "\n\n" + txt4 + "\n" + txt5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::reload, the displayed collections.
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::reload()
|
|
|
|
{
|
2015-12-09 20:27:31 +00:00
|
|
|
m_progress_bar->show();
|
2015-12-08 16:52:10 +00:00
|
|
|
ElementsCollectionModel *new_model = new ElementsCollectionModel(m_tree_view);
|
2016-06-06 19:07:13 +00:00
|
|
|
|
2016-07-14 11:58:56 +00:00
|
|
|
QList <QETProject *> project_list;
|
|
|
|
project_list.append(m_waiting_project);
|
|
|
|
m_waiting_project.clear();
|
2015-12-16 17:16:15 +00:00
|
|
|
if (m_model)
|
2016-07-14 11:58:56 +00:00
|
|
|
project_list.append(m_model->project());
|
|
|
|
|
|
|
|
|
|
|
|
connect(new_model, &ElementsCollectionModel::loadingMaxValue, m_progress_bar, &QProgressBar::setMaximum);
|
|
|
|
connect(new_model, &ElementsCollectionModel::loadingProgressValue, m_progress_bar, &QProgressBar::setValue);
|
|
|
|
|
|
|
|
new_model->loadCollections(true, true, project_list);
|
|
|
|
|
|
|
|
disconnect(new_model, &ElementsCollectionModel::loadingMaxValue, m_progress_bar, &QProgressBar::setMaximum);
|
|
|
|
disconnect(new_model, &ElementsCollectionModel::loadingProgressValue, m_progress_bar, &QProgressBar::setValue);
|
2015-12-09 20:27:31 +00:00
|
|
|
|
2016-06-30 09:12:25 +00:00
|
|
|
new_model->highlightUnusedElement();
|
2015-12-08 16:52:10 +00:00
|
|
|
m_tree_view->setModel(new_model);
|
2016-02-29 20:18:17 +00:00
|
|
|
m_index_at_context_menu = QModelIndex();
|
|
|
|
m_showed_index = QModelIndex();
|
2015-12-09 20:27:31 +00:00
|
|
|
if (m_model) delete m_model;
|
2015-12-08 16:52:10 +00:00
|
|
|
m_model = new_model;
|
|
|
|
expandFirstItems();
|
2015-12-09 20:27:31 +00:00
|
|
|
m_progress_bar->hide();
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 08:41:09 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::locationWasSaved
|
|
|
|
* This method is connected with the signal savedToLocation of Element editor (see ElementsCollectionWidget::editElement())
|
|
|
|
* Update or add the item represented by location to m_model
|
|
|
|
* @param location
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::locationWasSaved(ElementsLocation location)
|
|
|
|
{
|
|
|
|
//Because this method update an item in the model, location must
|
|
|
|
//represente an existing element (in file system of project)
|
|
|
|
if (!location.exist())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QModelIndex index = m_model->indexFromLocation(location);
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
QStandardItem *item = m_model->itemFromIndex(index);
|
|
|
|
if (item) {
|
|
|
|
static_cast<ElementCollectionItem *>(item)->clearData();
|
|
|
|
static_cast<ElementCollectionItem *>(item)->setUpData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_model->addLocation(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::search
|
2016-06-10 16:20:01 +00:00
|
|
|
* Search every item (directory or element) that match the text of m_search_field
|
2015-12-08 16:52:10 +00:00
|
|
|
* and display it, other item who does not match @text is hidden
|
|
|
|
*/
|
2016-06-10 16:20:01 +00:00
|
|
|
void ElementsCollectionWidget::search()
|
2015-12-08 16:52:10 +00:00
|
|
|
{
|
2016-06-10 16:20:01 +00:00
|
|
|
QString text = m_search_field->text();
|
2016-02-28 11:02:30 +00:00
|
|
|
//Reset the search
|
2015-12-08 16:52:10 +00:00
|
|
|
if (text.isEmpty())
|
|
|
|
{
|
|
|
|
QModelIndex current_index = m_tree_view->currentIndex();
|
2016-02-28 11:02:30 +00:00
|
|
|
m_tree_view->reset();
|
2016-02-26 09:58:55 +00:00
|
|
|
|
|
|
|
if (m_showed_index.isValid())
|
|
|
|
{
|
|
|
|
hideCollection(true);
|
|
|
|
showAndExpandItem(m_showed_index, true, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
expandFirstItems();
|
2015-12-08 16:52:10 +00:00
|
|
|
|
|
|
|
//Expand the tree and scroll to the last selected index
|
|
|
|
if (current_index.isValid())
|
|
|
|
{
|
|
|
|
showAndExpandItem(current_index);
|
|
|
|
m_tree_view->setCurrentIndex(current_index);
|
|
|
|
m_tree_view->scrollTo(current_index);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hideCollection(true);
|
2016-05-31 09:06:04 +00:00
|
|
|
QStringList text_list = text.split("+", QString::SkipEmptyParts);
|
|
|
|
QModelIndexList match_index;
|
|
|
|
foreach (QString txt, text_list) {
|
|
|
|
match_index << m_model->match(m_showed_index.isValid() ? m_model->index(0,0,m_showed_index) : m_model->index(0,0),
|
|
|
|
Qt::DisplayRole, QVariant(txt), -1, Qt::MatchContains | Qt::MatchRecursive);
|
|
|
|
}
|
|
|
|
|
2015-12-08 16:52:10 +00:00
|
|
|
foreach(QModelIndex index, match_index)
|
|
|
|
showAndExpandItem(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::hideCollection
|
|
|
|
* Hide all collection displayed in this tree
|
|
|
|
* @param hide- true = hide , false = visible
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::hideCollection(bool hide)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i <m_model->rowCount() ; i++)
|
|
|
|
hideItem(hide, m_model->index(i, 0), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::hideItem
|
|
|
|
* Hide the item @index. If @recursive is true, hide all subchilds of @index
|
|
|
|
* @param hide- true = hide , false = visible
|
|
|
|
* @param index- index to hide
|
|
|
|
* @param recursive- true = apply to child , false = only for @index
|
|
|
|
*/
|
|
|
|
void ElementsCollectionWidget::hideItem(bool hide, const QModelIndex &index, bool recursive)
|
|
|
|
{
|
|
|
|
m_tree_view->setRowHidden(index.row(), index.parent(), hide);
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
for (int i=0 ; i<m_model->rowCount(index) ; i++)
|
|
|
|
hideItem(hide, m_model->index(i, 0, index), recursive);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::showAndExpandItem
|
|
|
|
* Show the item @index and expand it.
|
2016-02-26 09:58:55 +00:00
|
|
|
* If parent is true, ensure parents of @index is show and expanded
|
|
|
|
* If child is true, ensure all childs of @index is show and expended
|
2015-12-08 16:52:10 +00:00
|
|
|
* @param index- index to show
|
2016-02-26 09:58:55 +00:00
|
|
|
* @param parent- Apply to parent
|
|
|
|
* @param child- Apply to all childs
|
2015-12-08 16:52:10 +00:00
|
|
|
*/
|
2016-02-26 09:58:55 +00:00
|
|
|
void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index, bool parent, bool child)
|
2015-12-08 16:52:10 +00:00
|
|
|
{
|
2016-06-05 16:34:46 +00:00
|
|
|
if (index.isValid()) {
|
|
|
|
if (parent)
|
|
|
|
showAndExpandItem(index.parent(), parent);
|
2015-12-08 16:52:10 +00:00
|
|
|
|
2016-06-05 16:34:46 +00:00
|
|
|
hideItem(false, index, child);
|
|
|
|
m_tree_view->expand(index);
|
|
|
|
}
|
2015-12-08 16:52:10 +00:00
|
|
|
}
|
2015-12-16 17:16:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsCollectionWidget::elementCollectionItemForIndex
|
|
|
|
* @param index
|
|
|
|
* @return The internal pointer of index casted to ElementCollectionItem;
|
|
|
|
*/
|
|
|
|
ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex(const QModelIndex &index) {
|
2016-10-15 13:39:02 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
return nullptr;
|
|
|
|
|
2016-06-05 16:34:46 +00:00
|
|
|
return static_cast<ElementCollectionItem*>(m_model->itemFromIndex(index));
|
2015-12-16 17:16:15 +00:00
|
|
|
}
|