Use of initializer_list for FListBox, FListView and FTextView

This commit is contained in:
Markus Gans 2019-01-05 22:58:06 +01:00
parent a56ba6274e
commit 2b110d87d8
8 changed files with 122 additions and 30 deletions

View File

@ -1,3 +1,6 @@
2019-01-05 Markus Gans <guru.mail@muenster.de>
* Use of initializer_list for FListBox, FListView and FTextView
2019-01-04 Markus Gans <guru.mail@muenster.de> 2019-01-04 Markus Gans <guru.mail@muenster.de>
* Use the final specifier * Use the final specifier

View File

@ -4,6 +4,8 @@
### Building and code analysis ### Building and code analysis
*Latest release:*<br /> *Latest release:*<br />
&#160;&#160;&#160;&#160;&#160;[![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases) <br /> &#160;&#160;&#160;&#160;&#160;[![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases) <br />
*License:*<br />
&#160;&#160;&#160;&#160;&#160;[![license](https://img.shields.io/github/license/gansm/finalcut.svg?colorA=#333)](COPYING) <br />
*Travis CI:*<br /> *Travis CI:*<br />
&#160;&#160;&#160;&#160;&#160;[![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut) <br /> &#160;&#160;&#160;&#160;&#160;[![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut) <br />
*Coverity Scan:*<br /> *Coverity Scan:*<br />

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2017-2018 Markus Gans * * Copyright 2017-2019 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -111,7 +111,7 @@ CheckList::~CheckList() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void CheckList::populate() void CheckList::populate()
{ {
std::string list[][2] = const std::string list[][2] =
{ {
{ "Milk", "Highest" }, { "Milk", "Highest" },
{ "Cheese", "High" }, { "Cheese", "High" },

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2017-2018 Markus Gans * * Copyright 2017-2019 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -128,7 +128,7 @@ Listview::~Listview() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Listview::populate() void Listview::populate()
{ {
std::string weather[][5] = const std::string weather[][5] =
{ {
{ "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }, { "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" },
{ "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" }, { "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" },

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2017-2018 Markus Gans * * Copyright 2017-2019 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -818,24 +818,6 @@ FObject::FObjectIterator FListView::insert ( const FStringList& cols
return insert(item, parent_iter); return insert(item, parent_iter);
} }
//----------------------------------------------------------------------
FObject::FObjectIterator FListView::insert ( const std::vector<uInt64>& cols
, FDataPtr d
, FObjectIterator parent_iter )
{
FStringList str_cols;
if ( ! cols.empty() )
{
for (uInt i = 0; i < cols.size(); i++)
str_cols.push_back (FString().setNumber(cols[i]));
}
auto item_iter = insert (str_cols, d, parent_iter);
return item_iter;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::sort() void FListView::sort()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2018 Markus Gans * e Copyright 2014-2019 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -211,6 +211,11 @@ class FListBox : public FWidget
template <typename Container, typename LazyConverter> template <typename Container, typename LazyConverter>
void insert (Container, LazyConverter); void insert (Container, LazyConverter);
void insert (FListBoxItem); void insert (FListBoxItem);
template <typename T>
void insert ( const std::initializer_list<T>& list
, fc::brackets_type = fc::NoBrackets
, bool = false
, FDataPtr = nullptr );
template <typename ItemT> template <typename ItemT>
void insert ( const ItemT& void insert ( const ItemT&
, fc::brackets_type = fc::NoBrackets , fc::brackets_type = fc::NoBrackets
@ -489,6 +494,22 @@ void FListBox::insert (Container container, LazyConverter convert)
recalculateVerticalBar(size); recalculateVerticalBar(size);
} }
//----------------------------------------------------------------------
template <typename T>
void FListBox::insert ( const std::initializer_list<T>& list
, fc::brackets_type b
, bool s
, FDataPtr d )
{
for (auto& item : list)
{
FListBoxItem listItem (FString() << item, d);
listItem.brackets = b;
listItem.selected = s;
insert (listItem);
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template <typename ItemT> template <typename ItemT>
void FListBox::insert ( const ItemT& item void FListBox::insert ( const ItemT& item

View File

@ -324,13 +324,27 @@ class FListView : public FWidget
FObjectIterator insert ( const FStringList& FObjectIterator insert ( const FStringList&
, FDataPtr , FDataPtr
, FObjectIterator ); , FObjectIterator );
FObjectIterator insert ( const std::vector<uInt64>& template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
, FDataPtr = nullptr ); , FDataPtr = nullptr );
FObjectIterator insert ( const std::vector<uInt64>& template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
, FObjectIterator ); , FObjectIterator );
FObjectIterator insert ( const std::vector<uInt64>& template <typename T>
FObjectIterator insert ( const std::initializer_list<T>&
, FDataPtr , FDataPtr
, FObjectIterator ); , FObjectIterator );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
, FDataPtr = nullptr );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
, FObjectIterator );
template <typename ColT>
FObjectIterator insert ( const std::vector<ColT>&
, FDataPtr
, FObjectIterator );
FObjectIterator beginOfList(); FObjectIterator beginOfList();
FObjectIterator endOfList(); FObjectIterator endOfList();
virtual void sort(); virtual void sort();
@ -537,16 +551,63 @@ inline FObject::FObjectIterator
{ return insert (cols, 0, parent_iter); } { return insert (cols, 0, parent_iter); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template<typename T>
inline FObject::FObjectIterator inline FObject::FObjectIterator
FListView::insert (const std::vector<uInt64>& cols, FDataPtr d) FListView::insert (const std::initializer_list<T>& list, FDataPtr d)
{ return insert (list, d, root); }
//----------------------------------------------------------------------
template<typename T>
inline FObject::FObjectIterator
FListView::insert ( const std::initializer_list<T>& list
, FObjectIterator parent_iter )
{ return insert (list, 0, parent_iter); }
//----------------------------------------------------------------------
template<typename T>
FObject::FObjectIterator
FListView::insert ( const std::initializer_list<T>& list
, FDataPtr d
, FObjectIterator parent_iter )
{
FStringList str_cols;
for (auto& col : list)
str_cols.push_back (FString() << col);
auto item_iter = insert (str_cols, d, parent_iter);
return item_iter;
}
//----------------------------------------------------------------------
template <typename ColT>
inline FObject::FObjectIterator
FListView::insert (const std::vector<ColT>& cols, FDataPtr d)
{ return insert (cols, d, root); } { return insert (cols, d, root); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template <typename ColT>
inline FObject::FObjectIterator inline FObject::FObjectIterator
FListView::insert ( const std::vector<uInt64>& cols FListView::insert ( const std::vector<ColT>& cols
, FObjectIterator parent_iter ) , FObjectIterator parent_iter )
{ return insert (cols, 0, parent_iter); } { return insert (cols, 0, parent_iter); }
//----------------------------------------------------------------------
template <typename ColT>
FObject::FObjectIterator
FListView::insert ( const std::vector<ColT>& cols
, FDataPtr d
, FObjectIterator parent_iter )
{
FStringList str_cols;
for (auto& col : cols)
str_cols.push_back (FString() << col);
auto item_iter = insert (str_cols, d, parent_iter);
return item_iter;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FObject::FObjectIterator FListView::beginOfList() inline FObject::FObjectIterator FListView::beginOfList()
{ return itemlist.begin(); } { return itemlist.begin(); }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2014-2018 Markus Gans * * Copyright 2014-2019 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -109,7 +109,11 @@ class FTextView : public FWidget
// Methods // Methods
virtual void hide() override; virtual void hide() override;
template<typename T>
void append (const std::initializer_list<T>&);
void append (const FString&); void append (const FString&);
template<typename T>
void insert (const std::initializer_list<T>&, int);
void insert (const FString&, int); void insert (const FString&, int);
void replaceRange (const FString&, int, int); void replaceRange (const FString&, int, int);
void deleteRange (int, int); void deleteRange (int, int);
@ -187,6 +191,25 @@ inline const FStringList& FTextView::getLines() const
inline void FTextView::scrollTo (const FPoint& pos) inline void FTextView::scrollTo (const FPoint& pos)
{ scrollTo(pos.getX(), pos.getY()); } { scrollTo(pos.getX(), pos.getY()); }
//----------------------------------------------------------------------
template<typename T>
void FTextView::append (const std::initializer_list<T>& list)
{
for (auto& str : list)
insert(str, -1);
}
//----------------------------------------------------------------------
template<typename T>
void FTextView::insert (const std::initializer_list<T>& list, int pos)
{
for (auto& str : list)
{
insert(str, pos);
pos++;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTextView::deleteRange (int from, int to) inline void FTextView::deleteRange (int from, int to)
{ replaceRange (FString(), from, to); } { replaceRange (FString(), from, to); }