Skip to content

Commit

Permalink
Allow a buttonlist item position to be specified
Browse files Browse the repository at this point in the history
This allows a new button list item to be inserted at any position in
the list so that a full list rebuild can be avoided.
  • Loading branch information
stuartm committed Jun 20, 2011
1 parent bc3942b commit c64efc1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.25.20110616-1"
#define MYTH_BINARY_VERSION "0.25.20110620-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
23 changes: 17 additions & 6 deletions mythtv/libs/libmythui/mythuibuttonlist.cpp
Expand Up @@ -1344,10 +1344,21 @@ void MythUIButtonList::ItemVisible(MythUIButtonListItem* item)
emit itemVisible(item);
}

void MythUIButtonList::InsertItem(MythUIButtonListItem *item)
void MythUIButtonList::InsertItem(MythUIButtonListItem *item, int listPosition)
{
bool wasEmpty = m_itemList.isEmpty();
m_itemList.append(item);
if (listPosition >= 0 && listPosition <= m_itemList.count())
{
m_itemList.insert(listPosition, item);

if (listPosition <= m_selPosition)
m_selPosition++;

if (listPosition <= m_topPosition)
m_topPosition++;
}
else
m_itemList.append(item);

m_itemCount++;

Expand Down Expand Up @@ -2643,7 +2654,7 @@ bool MythUIButtonList::DoFind(bool doMove, bool searchForward)
MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList* lbtype,
const QString& text, const QString& image,
bool checkable, CheckState state,
bool showArrow)
bool showArrow, int listPosition)
{
if (!lbtype)
VERBOSE(VB_IMPORTANT, "Cannot add a button to a non-existent list!");
Expand All @@ -2661,12 +2672,12 @@ MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList* lbtype,
m_checkable = true;

if (m_parent)
m_parent->InsertItem(this);
m_parent->InsertItem(this, listPosition);
}

MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList* lbtype,
const QString& text,
QVariant data)
QVariant data, int listPosition)
{
if (!lbtype)
VERBOSE(VB_IMPORTANT, "Cannot add a button to a non-existent list!");
Expand All @@ -2682,7 +2693,7 @@ MythUIButtonListItem::MythUIButtonListItem(MythUIButtonList* lbtype,
m_showArrow = false;

if (m_parent)
m_parent->InsertItem(this);
m_parent->InsertItem(this, listPosition);
}

MythUIButtonListItem::~MythUIButtonListItem()
Expand Down
7 changes: 4 additions & 3 deletions mythtv/libs/libmythui/mythuibuttonlist.h
Expand Up @@ -32,9 +32,10 @@ class MUI_PUBLIC MythUIButtonListItem

MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
const QString& image = "", bool checkable = false,
CheckState state = CantCheck, bool showArrow = false);
CheckState state = CantCheck, bool showArrow = false,
int listPosition = -1);
MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
QVariant data);
QVariant data, int listPosition = -1);
virtual ~MythUIButtonListItem();

MythUIButtonList *parent() const;
Expand Down Expand Up @@ -197,7 +198,7 @@ class MUI_PUBLIC MythUIButtonList : public MythUIType
void Const();
virtual void Init();

void InsertItem(MythUIButtonListItem *item);
void InsertItem(MythUIButtonListItem *item, int listPosition = -1);

int minButtonWidth(const MythRect & area);
int minButtonHeight(const MythRect & area);
Expand Down

0 comments on commit c64efc1

Please sign in to comment.