示例#1
0
//-------------------------------------------------------------------------------
void DialogSelectMetar::slotBtOK()
{
	QTreeWidgetItemIterator iter (treeWidget);
	QTreeWidgetItem *it;
	QString val;
	QStringList expandedlist, icaolist;
	// Write expanded items in settings
    while (*iter) {
		it = *iter;
		if (it->data(0, Qt::UserRole) == "country"
			|| it->data(0, Qt::UserRole) == "state") 
		{
			if (it->isExpanded()) {
				val = (it->data(0, Qt::UserRole+1)).toString();
				expandedlist << val;
			}
		}
		iter ++;
	}
	iter = QTreeWidgetItemIterator (treeWidget, QTreeWidgetItemIterator::Checked);
    while (*iter) {
		it = *iter;
		if (it->data(0, Qt::UserRole) == "icao") 
		{
			val = (it->data(0, Qt::UserRole+1)).toString();
			icaolist << val;
		}
		iter ++;
	}
	Util::setSetting ("metar_country_expanded", expandedlist);
	Util::setSetting ("metar_selected", icaolist);
	emit metarListChanged ();
	Util::setSetting ("metar_tree_offset", treeWidget->verticalScrollBar()->sliderPosition());
    accept();
}
示例#2
0
void TreeFinder::find(const QString& text, bool forward, bool backward, bool typed)
{
    Q_UNUSED(backward);
    if (!d.tree || text.isEmpty())
        return;

    if (typed) {
        QList<QTreeWidgetItem*> items = d.tree->findItems(text, Qt::MatchExactly | Qt::MatchWrap | Qt::MatchRecursive);
        if (items.isEmpty())
            items = d.tree->findItems(text, Qt::MatchContains | Qt::MatchWrap | Qt::MatchRecursive);
        if (!items.isEmpty() && !items.contains(d.tree->currentItem()))
            d.tree->setCurrentItem(items.first());
        setError(items.isEmpty());
    } else {
        QTreeWidgetItem* item = d.tree->currentItem();
        if (item) {
            QTreeWidgetItemIterator it(item);
            if (forward)
                ++it;
            else
                --it;
            bool wrapped = false;
            while (*it) {
                if ((*it)->text(0).contains(text, Qt::CaseInsensitive)) {
                    d.tree->setCurrentItem(*it);
                    return;
                }
                if (forward)
                    ++it;
                else
                    --it;
                if (!(*it) && !wrapped) {
                    if (forward)
                        it = QTreeWidgetItemIterator(d.tree);
                    else
                        it = QTreeWidgetItemIterator(lastItem());
                    wrapped = true;
                }
            }
        }
    }
}
void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem *itemToBeRemoved)
{
    Q_Q(QTreeWidgetItemIterator);
    Q_ASSERT(itemToBeRemoved);

    if (!q->current) return;
    QTreeWidgetItem *nextItem = q->current;

    // Do not walk to the ancestor to find the other item if they have the same parent.
    if (nextItem->parent() != itemToBeRemoved->parent()) {
        while (nextItem->parent() && nextItem != itemToBeRemoved) {
            nextItem = nextItem->parent();
        }
    }
    // If the item to be removed is an ancestor of the current iterator item,
    // we need to adjust the iterator.
    if (nextItem == itemToBeRemoved) {
        QTreeWidgetItem *parent = nextItem;
        nextItem = 0;
        while (parent && !nextItem) {
            nextItem = nextSibling(parent);
            parent = parent->parent();
        }
        if (nextItem) {
            // Ooooh... Set the iterator to the next valid item
            *q = QTreeWidgetItemIterator(nextItem, q->flags);
            if (!(q->matchesFlags(nextItem))) ++(*q);
        } else {
            // set it to null.
            q->current = 0;
            m_parentIndex.clear();
            return;
        }
    }
    if (nextItem->parent() == itemToBeRemoved->parent()) {
        // They have the same parent, i.e. we have to adjust the m_currentIndex member of the iterator
        // if the deleted item is to the left of the nextItem.

        QTreeWidgetItem *par = itemToBeRemoved->parent();   // We know they both have the same parent.
        QTreeWidget *tw = itemToBeRemoved->treeWidget();    // ..and widget
        int indexOfItemToBeRemoved = par ? par->indexOfChild(const_cast<QTreeWidgetItem *>(itemToBeRemoved))
            : tw->indexOfTopLevelItem(const_cast<QTreeWidgetItem *>(itemToBeRemoved));
        int indexOfNextItem = par ? par->indexOfChild(nextItem) : tw->indexOfTopLevelItem(nextItem);

        if (indexOfItemToBeRemoved <= indexOfNextItem) {
            // A sibling to the left of us was deleted, adjust the m_currentIndex member of the iterator.
            // Note that the m_currentIndex will be wrong until the item is actually removed!
            m_currentIndex--;
        }
    }
}
示例#4
0
void ResourceDock::searchAct(const QString &Pharase) {
	auto allItems = QTreeWidgetItemIterator(resTree);
	while (*allItems) {
		if ((*allItems)->parent() != nullptr) {
			if (!Pharase.isEmpty()) {
				if ((*allItems)->text(0).contains(Pharase)) {
					(*allItems)->setHidden(false);
				} else {
					(*allItems)->setHidden(true);
				}
			} else {
				(*allItems)->setHidden(false);
			}
		}
		++allItems;
	}
}
示例#5
0
void BasicMibView::Find(bool reevaluate)
{
    if (reevaluate)
    {
        find_string = find_uid.comboFind->currentText();
        if (!find_strings.contains(find_string))
            find_strings.append(find_string);

        if (find_uid.checkWords->isChecked())
            find_word = true;
        else
            find_word = false;
        if (find_uid.checkCase->isChecked())
            find_cs = true;
        else
            find_cs = false;
        if (find_uid.checkBackward->isChecked())
            find_back = true;
        else
            find_back = false;
    }

    QTreeWidgetItem *start = NULL, *begin = NULL, *end = NULL, *cur = NULL;
  
    // Determine begin of tree 
    begin = itemFromIndex(model()->index(0, 0, QModelIndex()));
 
    // Determine end of tree
    if (find_back)
    {
        QTreeWidgetItemIterator it(begin);
        while ( *it ) end = *it++;
    }

    // Determine where we start the find 
    if ((start = itemFromIndex(find_last)) == NULL)
        start = begin;

    // Create iterator
    QTreeWidgetItemIterator it( start );

    goto start_find;

    // Loop thru tree items and break if item is found
    while ( *it && (*it != start))
    {
        cur = *it;

        if ((find_word && !cur->text(0).compare(find_string, 
                           find_cs?Qt::CaseSensitive:Qt::CaseInsensitive)) ||
            (!find_word && cur->text(0).contains(find_string, 
                           find_cs?Qt::CaseSensitive:Qt::CaseInsensitive)))
        {
            // Found item
            setCurrentItem(cur);
            find_last = indexFromItem(cur);
            break;
        }

start_find:
        // Move to next item, handle tree wrap-around
        if (find_back)
        {
            --it;
            if (!*it) it = QTreeWidgetItemIterator(end);
        }
        else
        {
            ++it;
            if (!*it) it = QTreeWidgetItemIterator(begin);
        }
    }
}