Commit 730008ac authored by Carsten Fuhrmann's avatar Carsten Fuhrmann
Browse files

fixed order problem

parent 7e76e934
......@@ -4,6 +4,7 @@
#include "plugin.h"
#include <qdebug.h>
#include "teamspeak\public_errors.h"
#include <QRegExp>
//#ifndef _DEBUG
......@@ -43,6 +44,7 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se
m_SCHID = serverConnectionHandlerID;
m_tree = new ChannelListWidget;
connect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
}
OverlayController::~OverlayController()
......@@ -218,20 +220,17 @@ void OverlayController::updateChannelList()
void OverlayController::displayChannelList()
{
// remove old stuff
while (int nb = m_tree->getTree()->topLevelItemCount())
{
auto item = m_tree->getTree()->takeTopLevelItem(nb - 1);
disconnect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
delete item;
}
delete m_tree->getTree()->takeTopLevelItem(nb - 1);
// get list of all channelIDs
uint64* channelIDList;
if (ts3.getChannelList(m_SCHID, &channelIDList) != ERROR_ok)
return;
// get a list of all channels containing name, id, parent,..
QVector<channelInfo> channelList;
// get Channels
int i(0);
while (channelIDList[i] != NULL)
{
......@@ -246,7 +245,10 @@ void OverlayController::displayChannelList()
tmp.entry->setData(0, Qt::DisplayRole, tmp.name);
tmp.entry->setData(1, Qt::UserRole, tmp.id);
if (tmp.name.startsWith('[') && tmp.name.contains("spacer"))
{
tmp.entry->setData(2, Qt::UserRole, spacer);
tmp.name = tmp.name.remove(QRegularExpression(""));
}
else
tmp.entry->setData(2, Qt::UserRole, channel);
......@@ -254,13 +256,31 @@ void OverlayController::displayChannelList()
i++;
}
// sort the list
qSort(channelList.begin(), channelList.end(), [](const channelInfo& a, const channelInfo& b) { return a.order < b.order; });
QVector<channelInfo> topLvlList;
for (int i = 0; i < channelList.size(); i++)
if (channelList[i].parent == 0)
topLvlList.push_back(channelList[i]);
int next = 0;
while(!topLvlList.isEmpty())
{
int i;
for (i = 0; i < topLvlList.size(); i++)
if (topLvlList[i].order == next)
break;
next = topLvlList[i].id;
m_tree->getTree()->addTopLevelItem(topLvlList.takeAt(i).entry);
}
// build tree structure
for (auto& it : channelList)
{
if (it.parent == 0)
m_tree->getTree()->addTopLevelItem(it.entry);
continue;
else
{
bool found(false);
......@@ -300,8 +320,8 @@ void OverlayController::displayChannelList()
}
}
// display everything
m_tree->getTree()->expandAll();
connect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
m_tree->getTree()->adjustSize();
m_tree->adjustSize();
m_tree->show();
......
......@@ -8,6 +8,7 @@
#define PLUGIN_H
#include <qstring.h>
#include "overlaycontroller.h"
#include <Windows.h>
#ifdef WIN32
#define PLUGINS_EXPORTDLL __declspec(dllexport)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment