Scaffold Qt6 Widgets app for Milestone 0

This commit is contained in:
Keith Smith
2026-03-01 08:56:10 -07:00
parent da11b96dab
commit 285a81d9b5
6 changed files with 279 additions and 0 deletions

135
src/profiles_window.cpp Normal file
View File

@@ -0,0 +1,135 @@
#include "profiles_window.h"
#include "session_window.h"
#include <algorithm>
#include <QAbstractItemView>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMessageBox>
#include <QPushButton>
#include <QStringList>
#include <QVBoxLayout>
#include <QWidget>
ProfilesWindow::ProfilesWindow(QWidget* parent)
: QMainWindow(parent),
m_searchBox(nullptr),
m_profilesList(nullptr),
m_newButton(nullptr),
m_editButton(nullptr),
m_deleteButton(nullptr)
{
setWindowTitle(QStringLiteral("OrbitHub Profiles"));
resize(520, 620);
setupUi();
populateSampleProfiles();
}
void ProfilesWindow::setupUi()
{
auto* central = new QWidget(this);
auto* rootLayout = new QVBoxLayout(central);
auto* searchLabel = new QLabel(QStringLiteral("Search"), central);
m_searchBox = new QLineEdit(central);
m_searchBox->setPlaceholderText(QStringLiteral("Filter profiles..."));
m_profilesList = new QListWidget(central);
m_profilesList->setSelectionMode(QAbstractItemView::SingleSelection);
auto* buttonRow = new QHBoxLayout();
m_newButton = new QPushButton(QStringLiteral("New"), central);
m_editButton = new QPushButton(QStringLiteral("Edit"), central);
m_deleteButton = new QPushButton(QStringLiteral("Delete"), central);
buttonRow->addWidget(m_newButton);
buttonRow->addWidget(m_editButton);
buttonRow->addWidget(m_deleteButton);
buttonRow->addStretch();
rootLayout->addWidget(searchLabel);
rootLayout->addWidget(m_searchBox);
rootLayout->addWidget(m_profilesList, 1);
rootLayout->addLayout(buttonRow);
setCentralWidget(central);
connect(m_searchBox,
&QLineEdit::textChanged,
this,
[this](const QString& text) { filterProfiles(text); });
connect(m_profilesList,
&QListWidget::itemDoubleClicked,
this,
[this](QListWidgetItem* item) { openSessionForItem(item); });
// Milestone 0 keeps profile management as placeholders.
auto showTodo = [this](const QString& action) {
QMessageBox::information(this,
QStringLiteral("Milestone 0"),
QStringLiteral("%1 is planned for Milestone 1.").arg(action));
};
connect(m_newButton, &QPushButton::clicked, this, [showTodo]() { showTodo(QStringLiteral("New Profile")); });
connect(m_editButton, &QPushButton::clicked, this, [showTodo]() { showTodo(QStringLiteral("Edit Profile")); });
connect(m_deleteButton,
&QPushButton::clicked,
this,
[showTodo]() { showTodo(QStringLiteral("Delete Profile")); });
}
void ProfilesWindow::populateSampleProfiles()
{
const QStringList sampleProfiles = {
QStringLiteral("Production Bastion"),
QStringLiteral("Staging API Host"),
QStringLiteral("Local Lab VM"),
QStringLiteral("CI Build Agent")};
m_profilesList->addItems(sampleProfiles);
}
void ProfilesWindow::filterProfiles(const QString& query)
{
const QString trimmed = query.trimmed();
for (int i = 0; i < m_profilesList->count(); ++i) {
QListWidgetItem* item = m_profilesList->item(i);
const bool matches = trimmed.isEmpty()
|| item->text().contains(trimmed, Qt::CaseInsensitive);
item->setHidden(!matches);
}
}
void ProfilesWindow::openSessionForItem(QListWidgetItem* item)
{
if (item == nullptr) {
return;
}
auto* session = new SessionWindow(item->text());
session->setAttribute(Qt::WA_DeleteOnClose);
m_sessionWindows.emplace_back(session);
connect(session,
&QObject::destroyed,
this,
[this](QObject* object) {
m_sessionWindows.erase(
std::remove_if(m_sessionWindows.begin(),
m_sessionWindows.end(),
[object](const QPointer<SessionWindow>& candidate) {
return candidate.isNull() || candidate.data() == object;
}),
m_sessionWindows.end());
});
session->show();
}