mirror of
				https://github.com/YACReader/yacreader
				synced 2025-10-31 00:04:26 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			101 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <QStringList>
 | ||
| 
 | ||
| #include "folder_item.h"
 | ||
| #include "qnaturalsorting.h"
 | ||
| 
 | ||
| FolderItem::FolderItem(const QList<QVariant> &data, FolderItem *parent)
 | ||
| {
 | ||
|     parentItem = parent;
 | ||
|     itemData = data;
 | ||
| }
 | ||
| 
 | ||
| FolderItem::~FolderItem()
 | ||
| {
 | ||
|     qDeleteAll(childItems);
 | ||
| }
 | ||
| 
 | ||
| void FolderItem::appendChild(FolderItem *item)
 | ||
| {
 | ||
|     item->parentItem = this;
 | ||
| 
 | ||
|     if (childItems.isEmpty())
 | ||
|         childItems.append(item);
 | ||
|     else {
 | ||
|         FolderItem *last = childItems.back();
 | ||
|         QString nameLast = last->data(1).toString(); // TODO usar info name si est<73> disponible, sino el nombre del fichero.....
 | ||
|         QString nameCurrent = item->data(1).toString();
 | ||
|         QList<FolderItem *>::iterator i;
 | ||
|         i = childItems.end();
 | ||
|         i--;
 | ||
|         while (naturalSortLessThanCI(nameCurrent, nameLast) && i != childItems.begin()) {
 | ||
|             i--;
 | ||
|             nameLast = (*i)->data(1).toString();
 | ||
|         }
 | ||
|         if (!naturalSortLessThanCI(nameCurrent, nameLast)) // si se ha encontrado un elemento menor que current, se inserta justo despu<70>s
 | ||
|             childItems.insert(++i, item);
 | ||
|         else
 | ||
|             childItems.insert(i, item);
 | ||
|     }
 | ||
| 
 | ||
|     // childItems.append(item);
 | ||
| }
 | ||
| 
 | ||
| FolderItem *FolderItem::child(int row)
 | ||
| {
 | ||
|     return childItems.value(row);
 | ||
| }
 | ||
| 
 | ||
| int FolderItem::childCount() const
 | ||
| {
 | ||
|     return childItems.count();
 | ||
| }
 | ||
| 
 | ||
| int FolderItem::columnCount() const
 | ||
| {
 | ||
|     return itemData.count();
 | ||
| }
 | ||
| 
 | ||
| QVariant FolderItem::data(int column) const
 | ||
| {
 | ||
|     return itemData.value(column);
 | ||
| }
 | ||
| 
 | ||
| void FolderItem::setData(int column, const QVariant &value)
 | ||
| {
 | ||
|     itemData[column] = value;
 | ||
| }
 | ||
| 
 | ||
| void FolderItem::removeChild(int childIndex)
 | ||
| {
 | ||
|     childItems.removeAt(childIndex);
 | ||
| }
 | ||
| 
 | ||
| void FolderItem::clearChildren()
 | ||
| {
 | ||
|     qDeleteAll(childItems);
 | ||
|     childItems.clear();
 | ||
| }
 | ||
| 
 | ||
| QList<FolderItem *> FolderItem::children()
 | ||
| {
 | ||
|     return childItems;
 | ||
| }
 | ||
| 
 | ||
| FolderItem *FolderItem::parent()
 | ||
| {
 | ||
|     return parentItem;
 | ||
| }
 | ||
| 
 | ||
| int FolderItem::row() const
 | ||
| {
 | ||
|     if (parentItem)
 | ||
|         return parentItem->childItems.indexOf(const_cast<FolderItem *>(this));
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 | ||
| QList<QVariant> FolderItem::getData() const
 | ||
| {
 | ||
|     return itemData;
 | ||
| }
 |