BookmarksComboBoxWidget::BookmarksComboBoxWidget(QWidget *parent) : QComboBox(parent),
	m_view(new QTreeView(this))
{
	setView(m_view);
	setModel(BookmarksManager::getModel());
	updateBranch();

	m_view->viewport()->installEventFilter(this);
	m_view->setHeaderHidden(true);
	m_view->setItemsExpandable(false);
	m_view->setRootIsDecorated(false);
	m_view->setStyleSheet(QLatin1String("QTreeView::branch { border-image:url(invalid.png); }"));

	connect(BookmarksManager::getModel(), SIGNAL(layoutChanged()), this, SLOT(updateBranch()));
}
void BookmarksComboBoxWidget::updateBranch(QStandardItem *branch)
{
	if (!branch)
	{
		branch = qobject_cast<BookmarksModel*>(model())->invisibleRootItem();
	}

	for (int i = 0; i < branch->rowCount(); ++i)
	{
		QStandardItem *item = branch->child(i, 0);

		if (item)
		{
			const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(item->data(BookmarksModel::TypeRole).toInt());

			if (type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark)
			{
				updateBranch(item);
			}
			else
			{
				m_view->setRowHidden(i, branch->index(), true);
			}
		}
	}

	m_view->expandAll();
}
Example #3
0
void BookmarksComboBoxWidget::updateBranch(const QModelIndex &parent)
{
	for (int i = 0; i < m_model->rowCount(parent); ++i)
	{
		const QModelIndex index(m_model->index(i, 0, parent));

		if (index.isValid())
		{
			const BookmarksModel::BookmarkType type(static_cast<BookmarksModel::BookmarkType>(index.data(BookmarksModel::TypeRole).toInt()));

			if (type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark)
			{
				updateBranch(index);
			}
			else
			{
				getView()->setRowHidden(i, parent, true);
			}
		}
	}

	if (!parent.isValid())
	{
		getView()->expandAll();
	}
}
Example #4
0
BookmarksComboBoxWidget::BookmarksComboBoxWidget(QWidget *parent) : ComboBoxWidget(parent),
	m_model(BookmarksManager::getModel())
{
	setModel(m_model);
	updateBranch();

	connect(m_model, &BookmarksModel::layoutChanged, this, &BookmarksComboBoxWidget::handleLayoutChanged);
}
Example #5
0
void UserTreeModel::addUser(const QString &nick, bool op, bool voice)
{
    QModelIndex newUser;
    QModelIndex rootBranchIndex = getRootBranch(op, voice);
    UserItem* rootBranchItem = getItem(rootBranchIndex);

    if (rootBranchItem->childCount() == 0) {
        //case for no users in the branch
        insertRow(0, rootBranchIndex);
        newUser = index(0, 0, rootBranchIndex);
    } else if (rootBranchItem->childCount() == 1) {
        //case for one user in the branch
        if (QString::localeAwareCompare(nick, rootBranchItem->child(0)->data()) < 0) {
            insertRow(0, rootBranchIndex);
            newUser = index(0, 0, rootBranchIndex);
        } else {
            insertRow(1, rootBranchIndex);
            newUser = index(1, 0, rootBranchIndex);
        }
    } else {
        //case for >=2 users in the branch
        //uses binary search
        QModelIndex previousItemIndex;
        int state = 0;
        int min = 0;
        int max = rootBranchItem->childCount()-1;
        while (max > min) {
            int mid = min + ((max - min) / 2 ) + 1;
            int previous = QString::localeAwareCompare(nick, rootBranchItem->child(mid-1)->data());
            int current = QString::localeAwareCompare(nick, rootBranchItem->child(mid)->data());
            if (previous  >= 0 && current <= 0) {
                previousItemIndex = index(mid, 0, createIndex(0, 0, rootBranchItem));
                state = 0;
                break;
            } else if (previous < 0 && current < 0) {
                max = mid - 1;
                state = -1;
            } else if (previous > 0 && current > 0) {
                min = mid;
                state = 1;
            }
        }
        if (state == 0) {
            insertRow(previousItemIndex.row(), rootBranchIndex);
            newUser = index(previousItemIndex.row(), 0, rootBranchIndex);
        } else if (state == 1){
            int row = rootBranchItem->childCount();
            insertRow(row, rootBranchIndex);
            newUser = index(row, 0, rootBranchIndex);
        } else if (state == -1) {
            insertRow(0, rootBranchIndex);
            newUser = index(0, 0, rootBranchIndex);
        }
    }
    setData(newUser, QVariant(nick));
    updateBranch(newUser.parent());
}
Example #6
0
void UserTreeModel::removeUser(const QString &nick, bool op, bool voice)
{
    QModelIndex removedUser = getUser(nick, getRootBranch(op, voice));

    if (!removedUser.isValid()) {
        qDebug() << "error: removeUser -> couldn't find \"" << nick << "\"";
    }
    removeRow(removedUser.row(), removedUser.parent());
    updateBranch(getRootBranch(op, voice));
}
Example #7
0
void BookmarksComboBoxWidget::setMode(BookmarksModel::FormatMode mode)
{
	disconnect(m_model, &BookmarksModel::layoutChanged, this, &BookmarksComboBoxWidget::handleLayoutChanged);

	m_model = ((mode == BookmarksModel::NotesMode) ? NotesManager::getModel() : BookmarksManager::getModel());

	setModel(m_model);
	updateBranch();

	connect(m_model, &BookmarksModel::layoutChanged, this, &BookmarksComboBoxWidget::handleLayoutChanged);
}
Example #8
0
void UserTreeModel::removeUser(const QString &nick)
{
    QModelIndex removedUser = getUser(nick);

    if (!removedUser.isValid()) {
        qDebug() << "error: removeUser -> couldn't find \"" << nick << "\"";
    }
    QModelIndex parent = removedUser.parent();

    removeRow(removedUser.row(), removedUser.parent());
    updateBranch(parent);
}
void BookmarksComboBoxWidget::setMode(BookmarksModel::FormatMode mode)
{
	disconnect(model(), SIGNAL(layoutChanged()), this, SLOT(updateBranch()));

	m_mode = mode;

	switch (mode)
	{
		case BookmarksModel::BookmarksMode:
			setModel(BookmarksManager::getModel());

			break;
		case BookmarksModel::NotesMode:
			setModel(NotesManager::getModel());

			break;
		default:
			break;
	}

	updateBranch();

	connect(model(), SIGNAL(layoutChanged()), this, SLOT(updateBranch()));
}
void FiberSelector::roiDeleted( const QModelIndex &parent, int start, int end )
{
    //qDebug() << "roi deleted" << parent.row() << start << end;
    if ( parent.row() == -1 )
    {
        m_bitfields.removeAt( start );
        m_branchfields.removeAt( start );
        updateRoot();
    }
    else
    {
        m_bitfields[parent.row()].removeAt( start + 1 );
        updateBranch( parent.row() );
    }
}
void FiberSelector::updateBox( int branch, int pos )
{
    if ( Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::ACTIVE ), Qt::DisplayRole ).toBool() )
    {
        m_x = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::X ), Qt::DisplayRole ).toFloat();
        m_y = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::Y ), Qt::DisplayRole ).toFloat();
        m_z = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::Z ), Qt::DisplayRole ).toFloat();
        m_dx = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::DX ), Qt::DisplayRole ).toFloat() / 2;
        m_dy = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::DY ), Qt::DisplayRole ).toFloat() / 2;
        m_dz = Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::DZ ), Qt::DisplayRole ).toFloat() / 2;
        m_boxMin[0] = m_x - m_dx;
        m_boxMax[0] = m_x + m_dx;
        m_boxMin[1] = m_y - m_dy;
        m_boxMax[1] = m_y + m_dy;
        m_boxMin[2] = m_z - m_dz;
        m_boxMax[2] = m_z + m_dz;

        for ( int i = 0; i < m_numLines; ++i )
        {
            m_bitfields[branch][pos][i] = false;
        }
        boxTest( m_bitfields[branch][pos], 0, m_numPoints - 1, 0 );

        if ( Models::r()->data( createIndex( branch, pos, (int)Fn::ROI::SHAPE ), Qt::DisplayRole ).toInt() == 0 )
        {
            sphereTest( m_bitfields[branch][pos] );
        }
    }
    else
    {
        for ( int i = 0; i < m_numLines; ++i )
        {
            m_bitfields[branch][pos][i] = true;
        }
    }

    updateBranch( branch );
    if ( m_isInitialized )
    {
        Models::r()->setData( createIndex( branch, pos, (int)Fn::ROI::UPDATED ), true, Qt::DisplayRole );
    }
}
Example #12
0
void BookmarksComboBoxWidget::handleLayoutChanged()
{
	updateBranch();
}