made TableModel clonable

This commit is contained in:
Peter Schojer 2008-10-06 10:44:48 +00:00
parent 442f575356
commit 099db5f875
6 changed files with 42 additions and 2 deletions

View File

@ -41,6 +41,7 @@
#include "Poco/WebWidgets/TableModel.h"
#include "Poco/Mutex.h"
#include <vector>
@ -55,6 +56,7 @@ class WebWidgets_API SimpleTableModel: public TableModel
public:
typedef std::vector<Poco::Any> Row;
typedef std::vector<Row> TableData;
typedef Poco::AutoPtr<SimpleTableModel> Ptr;
SimpleTableModel(std::size_t colCnt);
/// Creates the SimpleTableModel.
@ -69,10 +71,13 @@ public:
/// Sets the value at pos(row, col)
void deleteRow(std::size_t row);
/// Removes the row from the TableModel
/// Removes the row from the TableModel. NOT IMPLEMENTED!
void clear();
/// Deletes all rows from the TableModel
TableModel::Ptr clone() const;
/// Creates a deep-copy of the table
protected:
virtual ~SimpleTableModel();
@ -80,6 +85,7 @@ protected:
private:
TableData _data;
mutable Poco::FastMutex _mutex;
};
@ -97,6 +103,7 @@ inline std::size_t SimpleTableModel::getRowCount() const
inline void SimpleTableModel::setValue(const Poco::Any& val, std::size_t row, std::size_t col)
{
Poco::FastMutex::ScopedLock lock(_mutex);
if (_data.size() < row+1)
_data.resize(row+1, Row(getColumnCount()));
_data[row][col] = val;

View File

@ -88,6 +88,9 @@ public:
std::size_t mapping(std::size_t) const;
TableModel::Ptr clone() const;
/// SortedTableModel doesn't clone the inner table.
protected:
virtual ~SortedTableModel();
/// Destroys the SortedTableModel.

View File

@ -187,6 +187,9 @@ public:
const TableModel& getModel() const;
/// Returns the table model
void setModel(TableModel::Ptr ptr);
/// Sets the table model
void handleForm(const std::string& field, const std::string& value);
/// Handles a form field submitted by the client.
@ -280,6 +283,13 @@ inline const TableModel& Table::getModel() const
}
inline void Table::setModel(TableModel::Ptr ptr)
{
poco_check_ptr (ptr);
_pModel = ptr;
}
inline void Table::setSelectionModel(Table::SelectionModel sm)
{
_sm = sm;

View File

@ -75,7 +75,10 @@ public:
/// Removes the row from the TableModel
virtual void clear() = 0;
/// Deletes all rows from the TableModel
/// Deletes all rows from the TableModel
virtual TableModel::Ptr clone() const = 0;
/// Creates a deep-copy of the table
protected:
virtual ~TableModel();

View File

@ -52,4 +52,14 @@ SimpleTableModel::~SimpleTableModel()
}
TableModel::Ptr SimpleTableModel::clone() const
{
SimpleTableModel::Ptr pModel(new SimpleTableModel(getColumnCount()));
Poco::FastMutex::ScopedLock lock(_mutex);
pModel->_data = _data;
return pModel;
}
} } // namespace Poco::WebWidgets

View File

@ -141,4 +141,11 @@ void SortedTableModel::forceResort(std::size_t col, bool sortAscending)
}
TableModel::Ptr SortedTableModel::clone() const
{
SortedTableModel::Ptr pModel(new SortedTableModel(_pTable, _sortCol, _sortAscending));
return pModel;
}
} } // namespace Poco::WebWidgets