|
14 | 14 |
|
15 | 15 | class WarpSourcesModel final : public QAbstractTableModel |
16 | 16 | { |
17 | | - Q_OBJECT |
| 17 | + Q_OBJECT |
18 | 18 |
|
19 | 19 | public: |
20 | | - enum Columns : int |
21 | | - { |
22 | | - GuidCol = 0, |
23 | | - PathCol, |
24 | | - WritableCol, |
25 | | - UncommittedCol, |
26 | | - ColumnCount |
27 | | - }; |
28 | | - |
29 | | - explicit WarpSourcesModel(QObject *parent = nullptr) |
30 | | - : QAbstractTableModel(parent) |
31 | | - { |
32 | | - } |
33 | | - |
34 | | - void setContainer(Warp::Ref<Warp::Container> container) |
35 | | - { |
36 | | - m_container = std::move(container); |
37 | | - reload(); |
38 | | - } |
39 | | - |
40 | | - void reload() |
41 | | - { |
42 | | - // Fetch synchronously (can be adapted to async if needed) |
43 | | - beginResetModel(); |
44 | | - m_rows.clear(); |
45 | | - for (const auto &src: m_container->GetSources()) |
46 | | - { |
47 | | - QString guid = QString::fromStdString(src.ToString()); |
48 | | - QString path = QString::fromStdString(m_container->SourcePath(src).value_or(std::string{})); |
49 | | - bool writable = m_container->IsSourceWritable(src); |
50 | | - bool uncommitted = m_container->IsSourceUncommitted(src); |
51 | | - m_rows.push_back({guid, path, writable, uncommitted}); |
52 | | - } |
53 | | - endResetModel(); |
54 | | - } |
55 | | - |
56 | | - int rowCount(const QModelIndex &parent = QModelIndex()) const override |
57 | | - { |
58 | | - if (parent.isValid()) return 0; |
59 | | - return static_cast<int>(m_rows.size()); |
60 | | - } |
61 | | - |
62 | | - int columnCount(const QModelIndex &parent = QModelIndex()) const override |
63 | | - { |
64 | | - Q_UNUSED(parent); |
65 | | - return ColumnCount; |
66 | | - } |
67 | | - |
68 | | - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
69 | | - |
70 | | - QVariant headerData(int section, Qt::Orientation orientation, int role) const override |
71 | | - { |
72 | | - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) |
73 | | - { |
74 | | - switch (section) |
75 | | - { |
76 | | - case GuidCol: return "Source GUID"; |
77 | | - case PathCol: return "Path"; |
78 | | - case WritableCol: return "Writable"; |
79 | | - case UncommittedCol: return "Uncommitted"; |
80 | | - default: return {}; |
81 | | - } |
82 | | - } |
83 | | - return {}; |
84 | | - } |
| 20 | + enum Columns : int |
| 21 | + { |
| 22 | + GuidCol = 0, |
| 23 | + PathCol, |
| 24 | + WritableCol, |
| 25 | + UncommittedCol, |
| 26 | + ColumnCount |
| 27 | + }; |
| 28 | + |
| 29 | + explicit WarpSourcesModel(QObject* parent = nullptr) : QAbstractTableModel(parent) {} |
| 30 | + |
| 31 | + void setContainer(Warp::Ref<Warp::Container> container) |
| 32 | + { |
| 33 | + m_container = std::move(container); |
| 34 | + reload(); |
| 35 | + } |
| 36 | + |
| 37 | + void reload() |
| 38 | + { |
| 39 | + // Fetch synchronously (can be adapted to async if needed) |
| 40 | + beginResetModel(); |
| 41 | + m_rows.clear(); |
| 42 | + for (const auto& src : m_container->GetSources()) |
| 43 | + { |
| 44 | + QString guid = QString::fromStdString(src.ToString()); |
| 45 | + QString path = QString::fromStdString(m_container->SourcePath(src).value_or(std::string {})); |
| 46 | + bool writable = m_container->IsSourceWritable(src); |
| 47 | + bool uncommitted = m_container->IsSourceUncommitted(src); |
| 48 | + m_rows.push_back({guid, path, writable, uncommitted}); |
| 49 | + } |
| 50 | + endResetModel(); |
| 51 | + } |
| 52 | + |
| 53 | + int rowCount(const QModelIndex& parent = QModelIndex()) const override |
| 54 | + { |
| 55 | + if (parent.isValid()) |
| 56 | + return 0; |
| 57 | + return static_cast<int>(m_rows.size()); |
| 58 | + } |
| 59 | + |
| 60 | + int columnCount(const QModelIndex& parent = QModelIndex()) const override |
| 61 | + { |
| 62 | + Q_UNUSED(parent); |
| 63 | + return ColumnCount; |
| 64 | + } |
| 65 | + |
| 66 | + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
| 67 | + |
| 68 | + QVariant headerData(int section, Qt::Orientation orientation, int role) const override |
| 69 | + { |
| 70 | + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) |
| 71 | + { |
| 72 | + switch (section) |
| 73 | + { |
| 74 | + case GuidCol: |
| 75 | + return "Source GUID"; |
| 76 | + case PathCol: |
| 77 | + return "Path"; |
| 78 | + case WritableCol: |
| 79 | + return "Writable"; |
| 80 | + case UncommittedCol: |
| 81 | + return "Uncommitted"; |
| 82 | + default: |
| 83 | + return {}; |
| 84 | + } |
| 85 | + } |
| 86 | + return {}; |
| 87 | + } |
85 | 88 |
|
86 | 89 | private: |
87 | | - struct Row |
88 | | - { |
89 | | - QString guid; |
90 | | - QString path; |
91 | | - bool writable; |
92 | | - bool uncommitted; |
93 | | - }; |
94 | | - |
95 | | - std::vector<Row> m_rows; |
96 | | - Warp::Ref<Warp::Container> m_container; |
| 90 | + struct Row |
| 91 | + { |
| 92 | + QString guid; |
| 93 | + QString path; |
| 94 | + bool writable; |
| 95 | + bool uncommitted; |
| 96 | + }; |
| 97 | + |
| 98 | + std::vector<Row> m_rows; |
| 99 | + Warp::Ref<Warp::Container> m_container; |
97 | 100 | }; |
98 | 101 |
|
99 | 102 | class WarpContainerWidget : public QWidget |
100 | 103 | { |
101 | | - Q_OBJECT |
| 104 | + Q_OBJECT |
102 | 105 |
|
103 | 106 | public: |
104 | | - explicit WarpContainerWidget(Warp::Ref<Warp::Container> container, QWidget *parent = nullptr); |
| 107 | + explicit WarpContainerWidget(Warp::Ref<Warp::Container> container, QWidget* parent = nullptr); |
105 | 108 |
|
106 | 109 | private: |
107 | | - Warp::Ref<Warp::Container> m_container; |
| 110 | + Warp::Ref<Warp::Container> m_container; |
108 | 111 |
|
109 | | - QTabWidget *m_tabs = nullptr; |
| 112 | + QTabWidget* m_tabs = nullptr; |
110 | 113 |
|
111 | | - // Sources |
112 | | - QTableView *m_sourcesView = nullptr; |
113 | | - WarpSourcesModel *m_sourcesModel = nullptr; |
114 | | - QWidget* m_sourcesPage = nullptr; |
115 | | - QTimer* m_refreshTimer = nullptr; |
| 114 | + // Sources |
| 115 | + QTableView* m_sourcesView = nullptr; |
| 116 | + WarpSourcesModel* m_sourcesModel = nullptr; |
| 117 | + QWidget* m_sourcesPage = nullptr; |
| 118 | + QTimer* m_refreshTimer = nullptr; |
116 | 119 |
|
117 | | - // Search |
118 | | - WarpSearchWidget *m_searchTab = nullptr; |
| 120 | + // Search |
| 121 | + WarpSearchWidget* m_searchTab = nullptr; |
119 | 122 | }; |
120 | 123 |
|
121 | 124 | class WarpContainersPane : public QWidget |
122 | 125 | { |
123 | | - Q_OBJECT |
| 126 | + Q_OBJECT |
124 | 127 |
|
125 | 128 | public: |
126 | | - explicit WarpContainersPane(QWidget *parent = nullptr); |
127 | | - |
128 | | - void refresh() |
129 | | - { |
130 | | - // Clear and repopulate from current container list |
131 | | - m_list->clear(); |
132 | | - while (m_stack->count() > 0) |
133 | | - { |
134 | | - QWidget *w = m_stack->widget(0); |
135 | | - m_stack->removeWidget(w); |
136 | | - delete w; |
137 | | - } |
138 | | - m_containers.clear(); |
139 | | - populate(); |
140 | | - if (m_list->count() > 0) |
141 | | - m_list->setCurrentRow(0); |
142 | | - } |
| 129 | + explicit WarpContainersPane(QWidget* parent = nullptr); |
| 130 | + |
| 131 | + void refresh() |
| 132 | + { |
| 133 | + // Clear and repopulate from current container list |
| 134 | + m_list->clear(); |
| 135 | + while (m_stack->count() > 0) |
| 136 | + { |
| 137 | + QWidget* w = m_stack->widget(0); |
| 138 | + m_stack->removeWidget(w); |
| 139 | + delete w; |
| 140 | + } |
| 141 | + m_containers.clear(); |
| 142 | + populate(); |
| 143 | + if (m_list->count() > 0) |
| 144 | + m_list->setCurrentRow(0); |
| 145 | + } |
143 | 146 |
|
144 | 147 | private: |
145 | | - void populate() |
146 | | - { |
147 | | - // Retrieve all available containers |
148 | | - const auto all = Warp::Container::All(); |
149 | | - m_containers = all; // copy vector<Ref<Container>> |
150 | | - |
151 | | - for (const auto &c: m_containers) |
152 | | - { |
153 | | - const QString name = QString::fromStdString(c->GetName()); |
154 | | - auto *item = new QListWidgetItem(name, m_list); |
155 | | - item->setSizeHint(QSize(item->sizeHint().width(), itemHeightPx())); |
156 | | - auto *widget = new WarpContainerWidget(c, m_stack); |
157 | | - m_stack->addWidget(widget); |
158 | | - } |
159 | | - |
160 | | - // Visual style: behave like a vertical tab bar |
161 | | - // m_list->setFrameShape(QFrame::NoFrame); |
162 | | - // m_list->setSpacing(0); |
163 | | - } |
164 | | - |
165 | | - static int itemHeightPx() |
166 | | - { |
167 | | - // A reasonable, readable height per entry |
168 | | - return 28; |
169 | | - } |
| 148 | + void populate() |
| 149 | + { |
| 150 | + // Retrieve all available containers |
| 151 | + const auto all = Warp::Container::All(); |
| 152 | + m_containers = all; // copy vector<Ref<Container>> |
| 153 | + |
| 154 | + for (const auto& c : m_containers) |
| 155 | + { |
| 156 | + const QString name = QString::fromStdString(c->GetName()); |
| 157 | + auto* item = new QListWidgetItem(name, m_list); |
| 158 | + item->setSizeHint(QSize(item->sizeHint().width(), itemHeightPx())); |
| 159 | + auto* widget = new WarpContainerWidget(c, m_stack); |
| 160 | + m_stack->addWidget(widget); |
| 161 | + } |
| 162 | + |
| 163 | + // Visual style: behave like a vertical tab bar |
| 164 | + // m_list->setFrameShape(QFrame::NoFrame); |
| 165 | + // m_list->setSpacing(0); |
| 166 | + } |
| 167 | + |
| 168 | + static int itemHeightPx() |
| 169 | + { |
| 170 | + // A reasonable, readable height per entry |
| 171 | + return 28; |
| 172 | + } |
170 | 173 |
|
171 | 174 | private: |
172 | | - QListWidget *m_list = nullptr; |
173 | | - QStackedWidget *m_stack = nullptr; |
174 | | - std::vector<Warp::Ref<Warp::Container> > m_containers; |
| 175 | + QListWidget* m_list = nullptr; |
| 176 | + QStackedWidget* m_stack = nullptr; |
| 177 | + std::vector<Warp::Ref<Warp::Container>> m_containers; |
175 | 178 | }; |
0 commit comments