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;