diff options
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp new file mode 100644 index 0000000..4860f2b --- /dev/null +++ b/src/mainwindow.cpp @@ -0,0 +1,73 @@ +#include "mainwindow.h" +#include "slxoutput.h" + +MainWindow::MainWindow() : QDialog() +{ + setupUi(this); + setWindowFlags(Qt::WindowStaysOnTopHint | windowFlags()); +} + +MainWindow::~MainWindow() +{ + +} + +// Need to pass newSink as new widget's sink isn't set here yet, so always empty +SlxOutput* MainWindow::getOutput(const QString &id, bool isSink, const QString &newTitle) +{ + SlxOutput* w = _widgets.value(id, nullptr); + if (w == nullptr) { + w = new SlxOutput(nullptr, id); + _widgets.insert(id, w); + bool done = false; + printf("New %s - %s\n", isSink ? "SINK" : "PROF", newTitle.toLocal8Bit().constData()); + printf("Conteints: %d\n", container->count()); + int idx; + for (idx = 0; idx < container->count(); ++idx) { + auto *l = container->itemAt(idx); + SlxOutput *other = qobject_cast<SlxOutput*>(l->widget()); + if (other == nullptr) + continue; + printf(" Comparing %s - %s\n", other->isSink() ? "SINK" : "PROF", other->nameLabel->text().toLocal8Bit().constData()); + if (isSink != other->isSink()) { + if (isSink) + break; + continue; + } + if (newTitle.compare(other->nameLabel->text()) < 0) { + done = true; + printf("Inserting before that (%d)!\n", idx); + container->insertWidget(idx, w); + break; + } + } + if (!done) { + if (idx == -1) { + idx = 0; + } + printf("Inserting before that (%d) 2!\n", idx); + container->insertWidget(idx, w); + } + } + return w; +} + +void MainWindow::mark() +{ + for (auto *w : _widgets) { + w->unused = true; + } +} + +void MainWindow::sweep() +{ + for (QMutableMapIterator<QString, SlxOutput*> it(_widgets); it.hasNext(); ) { + it.next(); + auto *w = it.value(); + if (w->unused) { + printf("Killing %p\n", w); + it.remove(); + w->deleteLater(); + } + } +} |