Skip to content

Commit

Permalink
ThreadsWidget: make ColumnIndex a class member
Browse files Browse the repository at this point in the history
This brings ThreadsWidget into alignment with ProcessesWidget and
others which have column index enumerators as class members. This also
avoids cluttering global scope with generic names, making it easier to
avoid C++ ODR violations with differing definitions.

Closes: #3316
Signed-off-by: John Helmert III <[email protected]>
  • Loading branch information
ajakk authored and karliss committed Mar 11, 2024
1 parent 1a09a5c commit 4395024
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/widgets/ThreadsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@

#define DEBUGGED_PID (-1)

enum ColumnIndex {
COLUMN_PID = 0,
COLUMN_STATUS,
COLUMN_PATH,
};

ThreadsWidget::ThreadsWidget(MainWindow *main) : CutterDockWidget(main), ui(new Ui::ThreadsWidget)
{
ui->setupUi(this);

// Setup threads model
modelThreads = new QStandardItemModel(1, 3, this);
modelThreads->setHorizontalHeaderItem(COLUMN_PID, new QStandardItem(tr("PID")));
modelThreads->setHorizontalHeaderItem(COLUMN_STATUS, new QStandardItem(tr("Status")));
modelThreads->setHorizontalHeaderItem(COLUMN_PATH, new QStandardItem(tr("Path")));
modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_PID, new QStandardItem(tr("PID")));
modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_STATUS,
new QStandardItem(tr("Status")));
modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_PATH,
new QStandardItem(tr("Path")));
ui->viewThreads->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
ui->viewThreads->verticalHeader()->setVisible(false);
ui->viewThreads->setFont(Config()->getFont());
Expand Down Expand Up @@ -120,9 +116,9 @@ void ThreadsWidget::setThreadsGrid()
rowStatus->setFont(font);
QStandardItem *rowPath = new QStandardItem(path);
rowPath->setFont(font);
modelThreads->setItem(i, COLUMN_PID, rowPid);
modelThreads->setItem(i, COLUMN_STATUS, rowStatus);
modelThreads->setItem(i, COLUMN_PATH, rowPath);
modelThreads->setItem(i, ThreadsWidget::COLUMN_PID, rowPid);
modelThreads->setItem(i, ThreadsWidget::COLUMN_STATUS, rowStatus);
modelThreads->setItem(i, ThreadsWidget::COLUMN_PATH, rowPath);
i++;
}

Expand All @@ -146,7 +142,7 @@ void ThreadsWidget::onActivated(const QModelIndex &index)
if (!index.isValid())
return;

int tid = modelFilter->data(index.sibling(index.row(), COLUMN_PID)).toInt();
int tid = modelFilter->data(index.sibling(index.row(), ThreadsWidget::COLUMN_PID)).toInt();

// Verify that the selected tid is still in the threads list since dpt= will
// attach to any given id. If it isn't found simply update the UI.
Expand All @@ -169,7 +165,7 @@ ThreadsFilterModel::ThreadsFilterModel(QObject *parent) : QSortFilterProxyModel(
bool ThreadsFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{
// All columns are checked for a match
for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) {
for (int i = ThreadsWidget::COLUMN_PID; i <= ThreadsWidget::COLUMN_PATH; ++i) {
QModelIndex index = sourceModel()->index(row, i, parent);
if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) {
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/ThreadsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class ThreadsWidget : public CutterDockWidget
Q_OBJECT

public:
enum ColumnIndex {
COLUMN_PID = 0,
COLUMN_STATUS,
COLUMN_PATH,
};

explicit ThreadsWidget(MainWindow *main);
~ThreadsWidget();

Expand Down

0 comments on commit 4395024

Please sign in to comment.