diff options
author | bd <bdunaisky@umass.edu> | 2025-04-28 03:44:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 03:44:42 +0000 |
commit | 013a79547aa465872d0262b2f5c24e73f9556869 (patch) | |
tree | 28cc8f2ea6e5aa1a74f328de8594b0ad5995fa66 /gui/dynamicwaysentry.cc | |
parent | 5653b2a033e7a4173d2f178b5ce52384666d3d7b (diff) | |
parent | 336faf3fd701aaf962613abd1ff0a69cbdf021ce (diff) |
Merge pull request #69 from bdunahu/vector_ext
Vector ext
Diffstat (limited to 'gui/dynamicwaysentry.cc')
-rw-r--r-- | gui/dynamicwaysentry.cc | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/gui/dynamicwaysentry.cc b/gui/dynamicwaysentry.cc deleted file mode 100644 index cbd5342..0000000 --- a/gui/dynamicwaysentry.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Simulator for the RISC-V[ECTOR] mini-ISA -// Copyright (C) 2025 Siddarth Suresh -// Copyright (C) 2025 bdunahu - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. - -#include "dynamicwaysentry.h" -#include <QLabel> -#include <QLineEdit> -#include <QStringList> -#include <QVBoxLayout> -#include <QVector> -#include <QWidget> - -DynamicWaysEntry::DynamicWaysEntry(QWidget *parent) : QWidget(parent) -{ - this->l = new QVBoxLayout(this); - this->l->setAlignment(Qt::AlignTop); - this->l->setSpacing(6); - this->l->setContentsMargins(0, 0, 0, 0); - this->setLayout(l); - this->add_field(); -} - -QStringList DynamicWaysEntry::get_entries() const { return this->entries; } - -int DynamicWaysEntry::parse_valid_way(QString t) -{ - bool s; - int i; - i = t.toInt(&s); - return (s && i >= 0 && 5 > i) ? i : -1; -} - -// TODO if you enter something valid and then make it invalid, -// the next box still shows -void DynamicWaysEntry::on_number_enter(const QString &t) -{ - int i; - QLineEdit *sender_field; - - sender_field = qobject_cast<QLineEdit *>(sender()); - i = fields.indexOf(sender_field); - entries[i] = t; - - if (i == this->fields.size() - 1 && !t.isEmpty() && - (this->parse_valid_way(t) >= 0) && fields.size() < 4) - add_field(); - - // TODO, unlink, don't trash everything after - if (t.isEmpty()) { - while (this->fields.size() > i + 1) { - remove_last_field(); - } - while (entries.size() > fields.size()) { - entries.removeLast(); - } - } -} - -void DynamicWaysEntry::add_field() -{ - QLineEdit *f; - - f = new QLineEdit(this); - f->setPlaceholderText("# ways (a power of 2)"); - - this->l->addWidget(f);; - this->fields.append(f); - this->entries.append(QString()); - connect( - f, &QLineEdit::textChanged, this, &DynamicWaysEntry::on_number_enter); -} - -void DynamicWaysEntry::remove_last_field() -{ - QLineEdit *f; - - if (this->fields.isEmpty()) - return; - - f = this->fields.takeLast(); - this->l->removeWidget(f); - f->deleteLater(); - - if (!this->entries.isEmpty()) - entries.removeLast(); -} |