Skip to content

Commit

Permalink
Start reworking UI after learning more about Qt
Browse files Browse the repository at this point in the history
The sliderules tab will now use two "models" that contains encoding
and decoding data. Custom Qt widgets and the Qt signal/slot mechanism
will be used for all data/filter updates.

For example, a signal that is emitted when the encoding table's ISA
family is changed is connected only to a slot in the encoding model. The
model would then emit its own signal that is connected to any UI slot
that needs to display the changed data. This flow of `User Interaction ->
Model Update -> UI Update` will ensure there are no recursive loops in the
signal/slot connection tree.
  • Loading branch information
raccog committed Jan 19, 2024
1 parent 1d0f205 commit 5164176
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 461 deletions.
32 changes: 32 additions & 0 deletions src/sliderulesmodels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "sliderulesmodels.h"

#include "processorhandler.h"

namespace Ripes {

ISAEncodingTableModel::ISAEncodingTableModel(QObject *parent)
: QAbstractTableModel(parent) {
const auto isaInfo = ProcessorHandler::currentISA();
setFamily(isaInfo->isaFamily());
}

void ISAEncodingTableModel::setFamily(ISAFamily family) {
if (!m_isaInfo || m_isaInfo->isaFamily() != family) {
m_isaInfo = ISAInfoRegistry::getISA(*ISAFamilySets.at(family).begin(),
QStringList());
emit familyChanged(family);
}
}

int ISAEncodingTableModel::rowCount(const QModelIndex &) const { return 1; }

int ISAEncodingTableModel::columnCount(const QModelIndex &) const { return 1; }

QVariant ISAEncodingTableModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
return QVariant::fromValue(m_isaInfo->isaFamily());
}
return QVariant();
}

} // namespace Ripes
55 changes: 55 additions & 0 deletions src/sliderulesmodels.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include "isainfo.h"

#include <QTableView>

namespace Ripes {

class ISAEncodingTableModel : public QAbstractTableModel {
Q_OBJECT
public:
ISAEncodingTableModel(QObject *parent = nullptr);

// TODO(raccog): This could be a variable that is controlable in the UI.
constexpr static size_t BIT_COLUMNS = 32;

enum Column {
EXTENSION = 0,
TYPE,
DESCRIPTION,
OPCODE,
// TODO(raccog): The field columns should be variable based on the maximum
// number of fields
FIELD0,
FIELD1,
FIELD2,
BIT_START,
BIT_END = BIT_START + BIT_COLUMNS
};

virtual int rowCount(const QModelIndex &) const override;
virtual int columnCount(const QModelIndex &) const override;
virtual QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
// virtual QVariant headerData(int section, Qt::Orientation orientation,
// int role = Qt::DisplayRole) const override;

public slots:
/// Updates the Model and emits `familyChanged()` signal if the model's ISA
/// family has changed.
///
/// This should only be `connect()`ed to UI signals whose function names end
/// in `Activated`. Can also be `connect()`ed to
/// `ProcessorHandler::processorChanged()`.
void setFamily(ISAFamily family);

signals:
/// Called when the ISA family of the model changes. Use this to update UI.
void familyChanged(ISAFamily family);

protected:
std::shared_ptr<const ISAInfoBase> m_isaInfo = nullptr;
};

} // namespace Ripes
Loading

0 comments on commit 5164176

Please sign in to comment.