mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibGUI: Make descendants of AbstractView define their own select_all() (#1201)
AbstractView does not know which column it's displaying which makes it impossible to implement the select_all functionality up there. Now descendants override the pure virtual select_all method and implement it themselves.
This commit is contained in:
parent
6824cb17a6
commit
8e1645423f
10 changed files with 54 additions and 14 deletions
|
@ -48,6 +48,15 @@ AbstractTableView::~AbstractTableView()
|
|||
{
|
||||
}
|
||||
|
||||
void AbstractTableView::select_all()
|
||||
{
|
||||
selection().clear();
|
||||
for (int item_index = 0; item_index < item_count(); ++item_index) {
|
||||
auto index = model()->index(item_index);
|
||||
selection().add(index);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractTableView::update_column_sizes()
|
||||
{
|
||||
if (!m_size_columns_to_fit_content)
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
virtual ModelIndex index_at_event_position(const Gfx::Point&, bool& is_toggle) const;
|
||||
virtual ModelIndex index_at_event_position(const Gfx::Point&) const override;
|
||||
|
||||
virtual void select_all() override;
|
||||
protected:
|
||||
virtual ~AbstractTableView() override;
|
||||
AbstractTableView();
|
||||
|
|
|
@ -125,18 +125,6 @@ void AbstractView::stop_editing()
|
|||
}
|
||||
}
|
||||
|
||||
void AbstractView::select_all()
|
||||
{
|
||||
ASSERT(model());
|
||||
int rows = model()->row_count();
|
||||
int columns = model()->column_count();
|
||||
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
for (int j = 0; j < columns; ++j)
|
||||
selection().add(model()->index(i, j));
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractView::activate(const ModelIndex& index)
|
||||
{
|
||||
if (on_activation)
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
|
||||
ModelSelection& selection() { return m_selection; }
|
||||
const ModelSelection& selection() const { return m_selection; }
|
||||
void select_all();
|
||||
virtual void select_all() = 0;
|
||||
|
||||
bool is_editable() const { return m_editable; }
|
||||
void set_editable(bool editable) { m_editable = editable; }
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
#include <LibGfx/CharacterBitmap.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
@ -59,6 +58,28 @@ ColumnsView::~ColumnsView()
|
|||
{
|
||||
}
|
||||
|
||||
void ColumnsView::select_all()
|
||||
{
|
||||
Vector<Column> columns_for_selection;
|
||||
selection().for_each_index([&](auto& index) {
|
||||
for (auto& column : m_columns) {
|
||||
if (column.parent_index == index.parent()) {
|
||||
columns_for_selection.append(column);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
});
|
||||
|
||||
for (Column& column : columns_for_selection) {
|
||||
int row_count = model()->row_count(column.parent_index);
|
||||
for (int row = 0; row < row_count; row++) {
|
||||
ModelIndex index = model()->index(row, m_model_column, column.parent_index);
|
||||
selection().add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ColumnsView::paint_event(PaintEvent& event)
|
||||
{
|
||||
AbstractView::paint_event(event);
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
virtual void mousedown_event(MouseEvent& event) override;
|
||||
virtual void keydown_event(KeyEvent& event) override;
|
||||
|
||||
virtual void select_all() override;
|
||||
struct Column {
|
||||
ModelIndex parent_index;
|
||||
int width;
|
||||
|
|
|
@ -48,6 +48,15 @@ ItemView::~ItemView()
|
|||
{
|
||||
}
|
||||
|
||||
void ItemView::select_all()
|
||||
{
|
||||
selection().clear();
|
||||
for (int item_index = 0; item_index < item_count(); ++item_index) {
|
||||
auto index = model()->index(item_index, model_column());
|
||||
selection().add(index);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemView::scroll_into_view(const ModelIndex& index, Orientation orientation)
|
||||
{
|
||||
ScrollableWidget::scroll_into_view(item_rect(index.row()), orientation);
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
virtual ModelIndex index_at_event_position(const Gfx::Point&) const override;
|
||||
|
||||
virtual void select_all() override;
|
||||
private:
|
||||
ItemView();
|
||||
|
||||
|
|
|
@ -43,6 +43,15 @@ ListView::~ListView()
|
|||
{
|
||||
}
|
||||
|
||||
void ListView::select_all()
|
||||
{
|
||||
selection().clear();
|
||||
for (int item_index = 0; item_index < item_count(); ++item_index) {
|
||||
auto index = model()->index(item_index, m_model_column);
|
||||
selection().add(index);
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::update_content_size()
|
||||
{
|
||||
if (!model())
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
int model_column() const { return m_model_column; }
|
||||
void set_model_column(int column) { m_model_column = column; }
|
||||
|
||||
virtual void select_all() override;
|
||||
private:
|
||||
ListView();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue