1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Merge branch 'feature/editable_table_cells'

This commit is contained in:
Timur Doumler 2015-04-20 17:02:42 +01:00
commit c825bc378f

View file

@ -741,10 +741,13 @@ public:
}
// This is overloaded from TableListBoxModel, and should fill in the background of the whole row
void paintRowBackground (Graphics& g, int /*rowNumber*/, int /*width*/, int /*height*/, bool rowIsSelected) override
void paintRowBackground (Graphics& g, int rowNumber, int /*width*/, int /*height*/, bool rowIsSelected) override
{
if (rowIsSelected)
g.fillAll (Colours::lightblue);
else if (rowNumber % 2)
g.fillAll (Colour (0xffeeeeee));
}
// This is overloaded from TableListBoxModel, and must paint any cells that aren't using custom
@ -785,7 +788,12 @@ public:
Component* refreshComponentForCell (int rowNumber, int columnId, bool /*isRowSelected*/,
Component* existingComponentToUpdate) override
{
if (columnId == 5) // If it's the ratings column, we'll return our custom component..
if (columnId == 1 || columnId == 7) // The ID and Length columns do not have a custom component
{
jassert (existingComponentToUpdate == 0);
return 0;
}
else if (columnId == 5) // For the ratings column, we return the custom combobox component
{
RatingColumnCustomComponent* ratingsBox = (RatingColumnCustomComponent*) existingComponentToUpdate;
@ -798,12 +806,17 @@ public:
return ratingsBox;
}
else
else // The other columns are editable text columns, for which we use the custom Label component
{
// for any other column, just return 0, as we'll be painting these columns directly.
jassert (existingComponentToUpdate == 0);
return 0;
EditableTextCustomComponent* textLabel = (EditableTextCustomComponent*) existingComponentToUpdate;
// same as above...
if (textLabel == 0)
textLabel = new EditableTextCustomComponent (*this);
textLabel->setRowAndColumn (rowNumber, columnId);
return textLabel;
}
}
@ -812,7 +825,7 @@ public:
int getColumnAutoSizeWidth (int columnId) override
{
if (columnId == 5)
return 100; // (this is the ratings column, containing a custom component)
return 100; // (this is the ratings column, containing a custom combobox component)
int widest = 32;
@ -832,8 +845,7 @@ public:
return widest + 8;
}
// A couple of quick methods to set and get the "rating" value when the user
// changes the combo box
// A couple of quick methods to set and get cell values when the user changes them
int getRating (const int rowNumber) const
{
return dataList->getChildElement (rowNumber)->getIntAttribute ("Rating");
@ -843,6 +855,17 @@ public:
{
dataList->getChildElement (rowNumber)->setAttribute ("Rating", newRating);
}
String getText (const int columnNumber, const int rowNumber) const
{
return dataList->getChildElement (rowNumber)->getStringAttribute ( getAttributeNameForColumnId(columnNumber));
}
void setText (const int columnNumber, const int rowNumber, const String& newText)
{
const String& columnName = table.getHeader().getColumnName (columnNumber);
dataList->getChildElement (rowNumber)->setAttribute (columnName, newText);
}
//==============================================================================
void resized() override
@ -861,6 +884,37 @@ private:
XmlElement* dataList; // A pointer to the sub-node of demoData that contains the list of data rows
int numRows; // The number of rows of data we've got
//==============================================================================
// This is a custom Label component, which we use for the table's editable text columns.
class EditableTextCustomComponent : public Label
{
public:
EditableTextCustomComponent (TableDemoComponent& owner_)
: owner (owner_)
{
setEditable (false, true, false);
setColour (textColourId, Colours::black);
}
void textWasEdited() override
{
owner.setText (columnId, row, getText());
}
// Our demo code will call this when we may need to update our contents
void setRowAndColumn (const int newRow, const int newColumn)
{
row = newRow;
columnId = newColumn;
setText (owner.getText(columnId, row), dontSendNotification);
}
private:
TableDemoComponent& owner;
int row, columnId;
};
//==============================================================================
// This is a custom component containing a combo box, which we're going to put inside
// our table's "rating" column.