diff --git a/ChangeLog b/ChangeLog index 2b3dfaa0..0a7e73f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2019-01-05 Markus Gans + * Use of initializer_list for FListBox, FListView and FTextView + 2019-01-04 Markus Gans * Use the final specifier diff --git a/README.md b/README.md index 47c30e97..69fa5553 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ ### Building and code analysis *Latest release:*
     [![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases)
+*License:*
+     [![license](https://img.shields.io/github/license/gansm/finalcut.svg?colorA=#333)](COPYING)
*Travis CI:*
     [![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut)
*Coverity Scan:*
diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 74fb6e6f..a365f0a6 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -111,7 +111,7 @@ CheckList::~CheckList() // destructor //---------------------------------------------------------------------- void CheckList::populate() { - std::string list[][2] = + const std::string list[][2] = { { "Milk", "Highest" }, { "Cheese", "High" }, diff --git a/examples/listview.cpp b/examples/listview.cpp index 223e17f8..482b68f0 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -128,7 +128,7 @@ Listview::~Listview() // destructor //---------------------------------------------------------------------- void Listview::populate() { - std::string weather[][5] = + const std::string weather[][5] = { { "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }, { "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" }, diff --git a/src/flistview.cpp b/src/flistview.cpp index 0fda28b2..a98869ee 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -3,7 +3,7 @@ * * * 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 * * 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); } -//---------------------------------------------------------------------- -FObject::FObjectIterator FListView::insert ( const std::vector& 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() { diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 266c8fef..04b0ae1a 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -211,6 +211,11 @@ class FListBox : public FWidget template void insert (Container, LazyConverter); void insert (FListBoxItem); + template + void insert ( const std::initializer_list& list + , fc::brackets_type = fc::NoBrackets + , bool = false + , FDataPtr = nullptr ); template void insert ( const ItemT& , fc::brackets_type = fc::NoBrackets @@ -489,6 +494,22 @@ void FListBox::insert (Container container, LazyConverter convert) recalculateVerticalBar(size); } +//---------------------------------------------------------------------- +template +void FListBox::insert ( const std::initializer_list& 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 void FListBox::insert ( const ItemT& item diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 8642dbed..af0b156f 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -324,13 +324,27 @@ class FListView : public FWidget FObjectIterator insert ( const FStringList& , FDataPtr , FObjectIterator ); - FObjectIterator insert ( const std::vector& + template + FObjectIterator insert ( const std::initializer_list& , FDataPtr = nullptr ); - FObjectIterator insert ( const std::vector& + template + FObjectIterator insert ( const std::initializer_list& , FObjectIterator ); - FObjectIterator insert ( const std::vector& + template + FObjectIterator insert ( const std::initializer_list& , FDataPtr , FObjectIterator ); + template + FObjectIterator insert ( const std::vector& + , FDataPtr = nullptr ); + template + FObjectIterator insert ( const std::vector& + , FObjectIterator ); + template + FObjectIterator insert ( const std::vector& + , FDataPtr + , FObjectIterator ); + FObjectIterator beginOfList(); FObjectIterator endOfList(); virtual void sort(); @@ -537,16 +551,63 @@ inline FObject::FObjectIterator { return insert (cols, 0, parent_iter); } //---------------------------------------------------------------------- +template inline FObject::FObjectIterator - FListView::insert (const std::vector& cols, FDataPtr d) + FListView::insert (const std::initializer_list& list, FDataPtr d) +{ return insert (list, d, root); } + +//---------------------------------------------------------------------- +template +inline FObject::FObjectIterator + FListView::insert ( const std::initializer_list& list + , FObjectIterator parent_iter ) +{ return insert (list, 0, parent_iter); } + +//---------------------------------------------------------------------- +template +FObject::FObjectIterator + FListView::insert ( const std::initializer_list& 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 +inline FObject::FObjectIterator + FListView::insert (const std::vector& cols, FDataPtr d) { return insert (cols, d, root); } //---------------------------------------------------------------------- +template inline FObject::FObjectIterator - FListView::insert ( const std::vector& cols + FListView::insert ( const std::vector& cols , FObjectIterator parent_iter ) { return insert (cols, 0, parent_iter); } +//---------------------------------------------------------------------- +template +FObject::FObjectIterator + FListView::insert ( const std::vector& 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() { return itemlist.begin(); } diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index e5a9b251..f44b5a10 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -109,7 +109,11 @@ class FTextView : public FWidget // Methods virtual void hide() override; + template + void append (const std::initializer_list&); void append (const FString&); + template + void insert (const std::initializer_list&, int); void insert (const FString&, int); void replaceRange (const FString&, int, int); void deleteRange (int, int); @@ -187,6 +191,25 @@ inline const FStringList& FTextView::getLines() const inline void FTextView::scrollTo (const FPoint& pos) { scrollTo(pos.getX(), pos.getY()); } +//---------------------------------------------------------------------- +template +void FTextView::append (const std::initializer_list& list) +{ + for (auto& str : list) + insert(str, -1); +} + +//---------------------------------------------------------------------- +template +void FTextView::insert (const std::initializer_list& list, int pos) +{ + for (auto& str : list) + { + insert(str, pos); + pos++; + } +} + //---------------------------------------------------------------------- inline void FTextView::deleteRange (int from, int to) { replaceRange (FString(), from, to); }