New Element Wizard : tree view only display directory

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4484 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2016-05-15 14:46:01 +00:00
parent 3261809227
commit 8dd3e7394a
7 changed files with 168 additions and 38 deletions

View File

@ -61,10 +61,22 @@ QModelIndex ElementsCollectionModel::index(int row, int column, const QModelInde
parent_item = static_cast<ElementCollectionItem*>(parent.internalPointer());
ElementCollectionItem *child_item = parent_item->child(row);
if (child_item->isValid())
return createIndex(row, column, child_item);
else
if (child_item->isValid()) {
if (m_hide_element) {
if (child_item->isDir()) {
return createIndex(row, column, child_item);
}
else {
return QModelIndex();
}
}
else {
return createIndex(row, column, child_item);
}
}
else {
return QModelIndex();
}
}
/**
@ -102,7 +114,21 @@ int ElementsCollectionModel::rowCount(const QModelIndex &parent) const
else
parent_item = static_cast<ElementCollectionItem*> (parent.internalPointer());
return parent_item->childCount();
if (m_hide_element) {
int count_ = 0;
for (int i = 0 ; i<parent_item->childCount() ; i++)
{
if (parent_item->child(i)->isDir()) {
count_ ++;
}
}
return count_;
}
else {
return parent_item->childCount();
}
}
/**
@ -324,6 +350,62 @@ QList<QETProject *> ElementsCollectionModel::project() const {
return m_project_list;
}
/**
* @brief ElementsCollectionModel::index
* @param location
* @return Return the index of the item represented by location.
* index can be no valid
*/
QModelIndex ElementsCollectionModel::index(const ElementsLocation &location) const
{
if (!location.exist()) {
return QModelIndex();
}
QList <ElementCollectionItem *> child_list;
for (int i=0 ; i<m_root_item->childCount() ; i++) {
child_list.append(m_root_item->child(i));
}
foreach(ElementCollectionItem *eci, child_list) {
ElementCollectionItem *match_eci = nullptr;
if (eci->type() == FileElementCollectionItem::Type) {
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci);
if (feci) {
if ( (location.isCommonCollection() && feci->isCommonCollection()) ||
(location.isCustomCollection() && !feci->isCommonCollection()) ) {
match_eci = feci->itemAtPath(location.collectionPath(false));
}
}
}
else if (eci->type() == XmlProjectElementCollectionItem::Type) {
XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem *>(eci);
if (xpeci) {
match_eci = xpeci->itemAtPath(location.collectionPath(false));
}
}
if (match_eci) {
return createIndex(match_eci->row(), 0, match_eci);
}
}
return QModelIndex();
}
/**
* @brief ElementsCollectionModel::hideElement
* Hide element.
* Only directory is provided by the model
*/
void ElementsCollectionModel::hideElement()
{
m_hide_element = true;
}
/**
* @brief ElementsCollectionModel::itemForProject
* @param project

View File

@ -19,6 +19,7 @@
#define ELEMENTSCOLLECTIONMODEL_H
#include <QAbstractItemModel>
#include "elementslocation.h"
class ElementCollectionItem;
class QETProject;
@ -58,6 +59,8 @@ class ElementsCollectionModel : public QAbstractItemModel
bool addProject(QETProject *project);
bool removeProject(QETProject *project);
QList<QETProject *> project() const;
QModelIndex index(const ElementsLocation &location) const;
void hideElement();
private:
XmlProjectElementCollectionItem *itemForProject(QETProject *project);
@ -71,6 +74,7 @@ class ElementsCollectionModel : public QAbstractItemModel
ElementCollectionItem *m_root_item;
QList <QETProject *> m_project_list;
QModelIndex m_parent_at_drop;
bool m_hide_element = false;
};
#endif // ELEMENTSCOLLECTIONMODEL_H

View File

@ -25,7 +25,6 @@
#include "qetmessagebox.h"
#include "elementscategoryeditor.h"
#include "newelementwizard.h"
#include "elementscategory.h"
#include "xmlprojectelementcollectionitem.h"
#include "qetproject.h"
#include "qetelementeditor.h"
@ -368,16 +367,18 @@ void ElementsCollectionWidget::newElement()
{
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
if (eci->type() != FileElementCollectionItem::Type) return;
if (eci->type() != FileElementCollectionItem::Type) {
return;
}
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
if(feci->isCommonCollection()) return;
ElementsCollectionItem *category = QETApp::collectionItem(ElementsLocation(feci->collectionPath()), false);
ElementsCategory *selected_category = category -> toCategory();
if (!selected_category) return;
if(feci->isCommonCollection()) {
return;
}
NewElementWizard elmt_wizard(this);
ElementsLocation loc(feci->collectionPath());
elmt_wizard.preselectedLocation(loc);
elmt_wizard.exec();
}

View File

@ -387,6 +387,24 @@ bool ElementsLocation::isFileSystem() const
return true;
}
/**
* @brief ElementsLocation::isCommonCollection
* @return True if this location represent an item from the common collection
*/
bool ElementsLocation::isCommonCollection() const
{
return fileSystemPath().startsWith(QETApp::commonElementsDirN());
}
/**
* @brief ElementsLocation::isCustomCollection
* @return True if this location represent an item from the custom collection
*/
bool ElementsLocation::isCustomCollection() const
{
return fileSystemPath().startsWith(QETApp::customElementsDirN());
}
/**
* @brief ElementsLocation::isProject
* @return True if this location represent an item from a project.

View File

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

View File

@ -54,11 +54,26 @@ NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
NewElementWizard::~NewElementWizard() {
}
/**
* @brief NewElementWizard::preselectedLocation
* Select item in the tree view represented by location,
* @param location
*/
void NewElementWizard::preselectedLocation(const ElementsLocation &location)
{
QModelIndex index = m_model->index(location);
if (index.isValid()) {
m_tree_view->scrollTo(index);
m_tree_view->setCurrentIndex(index);
}
}
/**
* @brief NewElementWizard::buildStep1
* @return
*/
QWizardPage *NewElementWizard::buildStep1() {
QWizardPage *NewElementWizard::buildStep1()
{
QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Category);
page -> setTitle(tr("Étape 1/3 : Catégorie parente", "wizard page title"));
@ -66,14 +81,17 @@ QWizardPage *NewElementWizard::buildStep1() {
QVBoxLayout *layout = new QVBoxLayout();
m_tree_view = new QTreeView(this);
ElementsCollectionModel *model_ = new ElementsCollectionModel(m_tree_view);
model_->addCustomCollection();
m_tree_view->setModel(model_);
m_tree_view->setHeaderHidden(true);
layout->addWidget(m_tree_view);
m_model = new ElementsCollectionModel(m_tree_view);
m_model->hideElement();
m_model->addCustomCollection();
m_tree_view->setModel(m_model);
m_tree_view->setHeaderHidden(true);
m_tree_view->setAnimated(true);
layout->addWidget(m_tree_view);
page -> setLayout(layout);
page->setLayout(layout);
return(page);
}

View File

@ -24,6 +24,7 @@
class NamesListWidget;
class QFileNameEdit;
class QTreeView;
class ElementsCollectionModel;
/**
This class provides a wizard dialog enabling users to to specify the basic
@ -34,34 +35,38 @@ class QTreeView;
- the filename the element should be saved to
- localized names
*/
class NewElementWizard : public QWizard {
class NewElementWizard : public QWizard
{
Q_OBJECT
// constructors, destructor
// constructors, destructor
public:
NewElementWizard(QWidget * = 0, Qt::WindowFlags = 0);
virtual ~NewElementWizard();
NewElementWizard(QWidget * = 0, Qt::WindowFlags = 0);
virtual ~NewElementWizard();
void preselectedLocation(const ElementsLocation &location);
private:
NewElementWizard(const NewElementWizard &);
NewElementWizard(const NewElementWizard &);
// attributes
// attributes
private:
enum WizardState { Category, Filename, Names };
QFileNameEdit *m_qle_filename;
NamesListWidget *m_names_list;
QString m_chosen_file;
QTreeView *m_tree_view = nullptr;
ElementsLocation m_chosen_location;
enum WizardState { Category, Filename, Names };
QFileNameEdit *m_qle_filename;
NamesListWidget *m_names_list;
QString m_chosen_file;
QTreeView *m_tree_view = nullptr;
ElementsLocation m_chosen_location;
ElementsCollectionModel *m_model = nullptr;
// methods
// methods
private:
QWizardPage *buildStep1();
QWizardPage *buildStep2();
QWizardPage *buildStep3();
bool validStep1();
bool validStep2();
bool validateCurrentPage();
void createNewElement();
QWizardPage *buildStep1();
QWizardPage *buildStep2();
QWizardPage *buildStep3();
bool validStep1();
bool validStep2();
bool validateCurrentPage();
void createNewElement();
};
#endif