2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* treeview.cpp - Example of a FListView widget with a tree hierarchy *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-08-24 00:47:35 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2019-04-26 21:06:04 +02:00
|
|
|
namespace fc = finalcut::fc;
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2018-11-13 02:51:41 +01:00
|
|
|
// Function prototypes
|
2020-09-25 00:48:58 +02:00
|
|
|
sInt64 stringToNumber (const finalcut::FString&);
|
2018-11-13 02:51:41 +01:00
|
|
|
bool sortAscending (const finalcut::FObject*, const finalcut::FObject*);
|
|
|
|
bool sortDescending (const finalcut::FObject*, const finalcut::FObject*);
|
2020-04-25 02:32:33 +02:00
|
|
|
bool isLessThanInteger (const finalcut::FString&, const finalcut::FString&);
|
|
|
|
bool isLessThanDouble (const finalcut::FString&, const finalcut::FString&);
|
|
|
|
bool isGreaterThanInteger (const finalcut::FString&, const finalcut::FString&);
|
|
|
|
bool isGreaterThanDouble (const finalcut::FString&, const finalcut::FString&);
|
2018-11-13 02:51:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
// non-member functions
|
|
|
|
//----------------------------------------------------------------------
|
2020-09-25 00:48:58 +02:00
|
|
|
sInt64 stringToNumber (const finalcut::FString& str)
|
2018-11-13 02:51:41 +01:00
|
|
|
{
|
2018-12-30 04:24:46 +01:00
|
|
|
// Cut off one character (because LONG_MAX = 2147483647)
|
2020-09-25 00:48:58 +02:00
|
|
|
auto num_string = str.left(str.getLength() - 1);
|
|
|
|
num_string = num_string.replace(",", "");
|
|
|
|
num_string = num_string.replace('.', "");
|
2020-10-04 02:55:15 +02:00
|
|
|
auto number = sInt64(num_string.toLong());
|
2018-11-13 02:51:41 +01:00
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
2020-04-25 02:32:33 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-04-26 20:45:57 +02:00
|
|
|
inline bool isLessThanInteger ( const finalcut::FString& lhs
|
|
|
|
, const finalcut::FString& rhs )
|
2020-04-25 02:32:33 +02:00
|
|
|
{
|
2020-09-25 00:48:58 +02:00
|
|
|
const sInt64 l_number = stringToNumber(lhs);
|
|
|
|
const sInt64 r_number = stringToNumber(rhs);
|
2020-04-25 02:32:33 +02:00
|
|
|
return bool( l_number < r_number ); // lhs < rhs
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-26 20:45:57 +02:00
|
|
|
inline bool isLessThanDouble ( const finalcut::FString& lhs
|
|
|
|
, const finalcut::FString& rhs )
|
2020-04-25 02:32:33 +02:00
|
|
|
{
|
|
|
|
std::setlocale(LC_NUMERIC, "C");
|
|
|
|
const double l_number = lhs.toDouble();
|
|
|
|
const double r_number = rhs.toDouble();
|
|
|
|
return bool( l_number < r_number ); // lhs < rhs
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-26 20:45:57 +02:00
|
|
|
inline bool isGreaterThanInteger ( const finalcut::FString& lhs
|
|
|
|
, const finalcut::FString& rhs )
|
2020-04-25 02:32:33 +02:00
|
|
|
{
|
2020-09-25 00:48:58 +02:00
|
|
|
const sInt64 l_number = stringToNumber(lhs);
|
|
|
|
const sInt64 r_number = stringToNumber(rhs);
|
2020-04-25 02:32:33 +02:00
|
|
|
return bool( l_number > r_number ); // lhs > rhs
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-04-26 20:45:57 +02:00
|
|
|
inline bool isGreaterThanDouble ( const finalcut::FString& lhs
|
2020-04-25 02:32:33 +02:00
|
|
|
, const finalcut::FString& rhs )
|
|
|
|
{
|
|
|
|
std::setlocale(LC_NUMERIC, "C");
|
|
|
|
const double l_number = lhs.toDouble();
|
|
|
|
const double r_number = rhs.toDouble();
|
|
|
|
return bool( l_number > r_number ); // lhs > rhs
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:51:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool sortAscending ( const finalcut::FObject* lhs
|
|
|
|
, const finalcut::FObject* rhs )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
const auto& l_item = static_cast<const finalcut::FListViewItem*>(lhs);
|
|
|
|
const auto& r_item = static_cast<const finalcut::FListViewItem*>(rhs);
|
2018-11-13 02:51:41 +01:00
|
|
|
const int column = l_item->getSortColumn();
|
2020-04-25 02:32:33 +02:00
|
|
|
const auto& l_str = l_item->getText(column);
|
|
|
|
const auto& r_str = r_item->getText(column);
|
2018-11-13 02:51:41 +01:00
|
|
|
|
2020-04-25 02:32:33 +02:00
|
|
|
if ( column == 2 )
|
|
|
|
{
|
|
|
|
return isGreaterThanInteger(l_str, r_str);
|
|
|
|
}
|
|
|
|
else if ( column == 3 )
|
2018-11-13 02:51:41 +01:00
|
|
|
{
|
2020-04-25 02:32:33 +02:00
|
|
|
return isGreaterThanDouble(l_str, r_str);
|
2018-11-13 02:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool sortDescending ( const finalcut::FObject* lhs
|
|
|
|
, const finalcut::FObject* rhs )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
const auto& l_item = static_cast<const finalcut::FListViewItem*>(lhs);
|
|
|
|
const auto& r_item = static_cast<const finalcut::FListViewItem*>(rhs);
|
2018-11-13 02:51:41 +01:00
|
|
|
const int column = l_item->getSortColumn();
|
2020-04-25 02:32:33 +02:00
|
|
|
const auto& l_str = l_item->getText(column);
|
|
|
|
const auto& r_str = r_item->getText(column);
|
2018-11-13 02:51:41 +01:00
|
|
|
|
2020-04-25 02:32:33 +02:00
|
|
|
if ( column == 2 )
|
|
|
|
{
|
|
|
|
return isLessThanInteger(l_str, r_str);
|
|
|
|
}
|
|
|
|
else if ( column == 3 )
|
2018-11-13 02:51:41 +01:00
|
|
|
{
|
2020-04-25 02:32:33 +02:00
|
|
|
return isLessThanDouble(l_str, r_str);
|
2018-11-13 02:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-24 00:47:35 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Treeview
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Treeview final : public finalcut::FDialog
|
2017-08-24 00:47:35 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Treeview (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Treeview (const Treeview&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~Treeview() override = default;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
Treeview& operator = (const Treeview&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
2017-10-14 22:20:19 +02:00
|
|
|
// Typedefs
|
|
|
|
struct TreeItem; // forward declaration
|
|
|
|
|
2018-02-04 19:42:30 +01:00
|
|
|
// Methods
|
2020-12-05 23:54:40 +01:00
|
|
|
auto initAfrica() const -> std::initializer_list<TreeItem>;
|
|
|
|
auto initAsia() const -> std::initializer_list<TreeItem>;
|
|
|
|
auto initEurope() const -> std::initializer_list<TreeItem>;
|
|
|
|
auto initNorthAmerica() const -> std::initializer_list<TreeItem>;
|
|
|
|
auto initSouthAmerica() const -> std::initializer_list<TreeItem>;
|
|
|
|
auto initOceania() const -> std::initializer_list<TreeItem>;
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2018-11-18 01:15:38 +01:00
|
|
|
// Event handler
|
2019-01-03 07:36:18 +01:00
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
bool initialized{false};
|
2020-09-25 00:48:58 +02:00
|
|
|
finalcut::FListView listview{this};
|
|
|
|
finalcut::FButton quit{this};
|
2020-11-24 21:06:39 +01:00
|
|
|
std::vector<TreeItem> africa{initAfrica()};
|
|
|
|
std::vector<TreeItem> asia{initAsia()};
|
|
|
|
std::vector<TreeItem> europe{initEurope()};
|
|
|
|
std::vector<TreeItem> north_america{initNorthAmerica()};
|
|
|
|
std::vector<TreeItem> south_america{initSouthAmerica()};
|
|
|
|
std::vector<TreeItem> oceania{initOceania()};
|
2017-10-14 22:20:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// struct Treeview::TreeItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct Treeview::TreeItem
|
|
|
|
{
|
|
|
|
const char* const* begin() const
|
|
|
|
{ return &name; }
|
|
|
|
|
|
|
|
const char* const* end() const
|
2017-10-15 15:27:36 +02:00
|
|
|
{ return reinterpret_cast<const char* const*>(&child_element); }
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2017-10-14 22:20:19 +02:00
|
|
|
const char* name;
|
|
|
|
const char* population;
|
|
|
|
const char* density;
|
2020-11-24 21:06:39 +01:00
|
|
|
std::vector<TreeItem> child_element;
|
2017-08-24 00:47:35 +02:00
|
|
|
};
|
|
|
|
|
2018-01-17 21:11:26 +01:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
// constructors and destructor
|
2018-01-17 21:11:26 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Treeview::Treeview (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2018-01-17 21:11:26 +01:00
|
|
|
{
|
2018-11-18 01:15:38 +01:00
|
|
|
// Set FListView geometry
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.setGeometry(FPoint{2, 1}, FSize{53, 14});
|
2018-01-17 21:11:26 +01:00
|
|
|
|
|
|
|
// Add columns to the view
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.addColumn ("Name", 23);
|
|
|
|
listview.addColumn ("Population");
|
|
|
|
listview.addColumn ("Density/km²");
|
2018-01-17 21:11:26 +01:00
|
|
|
|
|
|
|
// Set right alignment for the second and third column
|
2020-12-31 20:45:10 +01:00
|
|
|
listview.setColumnAlignment (2, finalcut::Align::Right);
|
|
|
|
listview.setColumnAlignment (3, finalcut::Align::Right);
|
2018-01-17 21:11:26 +01:00
|
|
|
|
2018-11-13 02:51:41 +01:00
|
|
|
// Set the type of sorting
|
2020-12-31 20:45:10 +01:00
|
|
|
listview.setColumnSortType (1, finalcut::SortType::Name);
|
|
|
|
listview.setColumnSortType (2, finalcut::SortType::UserDefined);
|
|
|
|
listview.setColumnSortType (3, finalcut::SortType::UserDefined);
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.setUserAscendingCompare(sortAscending);
|
|
|
|
listview.setUserDescendingCompare(sortDescending);
|
2018-11-13 02:51:41 +01:00
|
|
|
|
2018-01-17 21:11:26 +01:00
|
|
|
// Activate tree view
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.setTreeView();
|
2018-01-17 21:11:26 +01:00
|
|
|
|
|
|
|
// Populate FListView with a list of items
|
2020-11-24 21:06:39 +01:00
|
|
|
const std::vector<TreeItem> continent_list
|
2017-10-14 22:20:19 +02:00
|
|
|
{
|
|
|
|
{ "Africa", "944,000,000", "31.2", africa },
|
|
|
|
{ "Asia", "4,010,000,000", "90.3", asia },
|
|
|
|
{ "Europe", "733,000,000", "69.9", europe },
|
|
|
|
{ "North America", "523,000,000", "21", north_america },
|
|
|
|
{ "South America", "381,000,000", "21.4", south_america },
|
2020-11-24 21:06:39 +01:00
|
|
|
{ "Antarctica", "1000", "0", {} },
|
2019-10-14 01:44:24 +02:00
|
|
|
{ "Australia/Oceania", "34,000,000", "4", oceania }
|
2017-10-14 22:20:19 +02:00
|
|
|
};
|
|
|
|
|
2019-10-14 01:44:24 +02:00
|
|
|
for (const auto& continent : continent_list)
|
2017-10-14 22:20:19 +02:00
|
|
|
{
|
2019-10-14 01:44:24 +02:00
|
|
|
finalcut::FStringList continent_line ( continent.begin()
|
|
|
|
, continent.end() );
|
2020-09-25 00:48:58 +02:00
|
|
|
auto iter = listview.insert (continent_line);
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2020-11-24 21:06:39 +01:00
|
|
|
for (const auto& country : continent.child_element)
|
2017-10-14 22:20:19 +02:00
|
|
|
{
|
2020-11-24 21:06:39 +01:00
|
|
|
finalcut::FStringList country_line ( country.begin()
|
|
|
|
, country.end() );
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.insert (country_line, iter);
|
2017-10-14 22:20:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 00:48:58 +02:00
|
|
|
// quit button
|
|
|
|
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
|
|
|
|
quit.setText (L"&Quit");
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Callback function
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.addCallback
|
2017-08-24 00:47:35 +02:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
finalcut::getFApplication(),
|
|
|
|
&finalcut::FApplication::cb_exitApp,
|
|
|
|
this
|
2017-08-24 00:47:35 +02:00
|
|
|
);
|
2018-10-03 22:23:55 +02:00
|
|
|
|
|
|
|
initialized = true;
|
2017-08-24 00:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initAfrica() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Algeria", "40,400,000", "15.9", {} },
|
|
|
|
{ "Angola", "25,789,024", "20.69", {} },
|
|
|
|
{ "Botswana", "2,250,260", "3.7", {} },
|
|
|
|
{ "Cameroon", "22,534,532", "39.7", {} },
|
|
|
|
{ "Chad", "13,670,084", "8.6", {} },
|
|
|
|
{ "Egypt", "94,666,000", "87", {} },
|
|
|
|
{ "Ethiopia", "102,374,044", "92.7", {} },
|
|
|
|
{ "Ivory Coast", "23,740,424", "63.9", {} },
|
|
|
|
{ "Libya", "6,541,948", "3.55", {} },
|
|
|
|
{ "Madagascar", "24,430,325", "35.2", {} },
|
|
|
|
{ "Mali", "14,517,176", "11.7", {} },
|
|
|
|
{ "Mauritania", "4,301,018", "3.4", {} },
|
|
|
|
{ "Mozambique", "24,692,144", "28.7", {} },
|
|
|
|
{ "Namibia", "2,113,077", "2.54", {} },
|
|
|
|
{ "Niger", "20,672,987", "12.1", {} },
|
|
|
|
{ "Nigeria", "185,989,640", "197.2", {} },
|
|
|
|
{ "Somalia", "14,317,996", "19.31", {} },
|
|
|
|
{ "South Africa", "54,956,900", "42.4", {} },
|
|
|
|
{ "South Sudan", "12,340,000", "13.33", {} },
|
|
|
|
{ "Sudan", "39,578,828", "21.3", {} },
|
|
|
|
{ "Tanzania", "51,820,00", "47.5", {} },
|
|
|
|
{ "Zambia", "16,212,000", "17.2", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initAsia() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Afghanistan", "34,656,032", "49.88", {} },
|
|
|
|
{ "China", "1,403,500,365", "145.0", {} },
|
|
|
|
{ "India", "1,324,171,354", "393.9", {} },
|
|
|
|
{ "Indonesia", "261,115,456", "124.66", {} },
|
|
|
|
{ "Iran", "80,829,192", "48.0", {} },
|
|
|
|
{ "Iraq", "37,202,572", "82.7", {} },
|
|
|
|
{ "Japan", "126,740,000", "336.0", {} },
|
|
|
|
{ "Kazakhstan", "17,987,736", "6.49", {} },
|
|
|
|
{ "Mongolia", "3,081,677", "1.97", {} },
|
|
|
|
{ "Myanmar", "51,486,253", "76.0", {} },
|
|
|
|
{ "Pakistan", "207,774,520", "244.4", {} },
|
|
|
|
{ "Russia", "144,463,451", "8.4", {} },
|
|
|
|
{ "Saudi Arabia", "33,000,000", "15.0", {} },
|
|
|
|
{ "Thailand", "68,863,514", "132.1", {} },
|
|
|
|
{ "Turkey", "79,814,871", "102.0", {} },
|
|
|
|
{ "Turkmenistan", "5,662,544", "10.5", {} },
|
|
|
|
{ "Uzbekistan", "32,979,000", "70.5", {} },
|
|
|
|
{ "Vietnam", "94,569,072", "276.03", {} },
|
|
|
|
{ "Yemen", "27,584,213", "44.7", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initEurope() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Austria", "8,794,267", "104.0", {} },
|
|
|
|
{ "Belarus", "9,498,700", "45.8", {} },
|
|
|
|
{ "Bulgaria", "7,101,859", "64.9", {} },
|
|
|
|
{ "Czech Republic", "10,610,947", "134.0", {} },
|
|
|
|
{ "Finland", "5,506,312", "16.0", {} },
|
|
|
|
{ "France", "66,991,000", "103.0", {} },
|
|
|
|
{ "Germany", "82,175,700", "227.0", {} },
|
|
|
|
{ "Greece", "11,183,716", "82.0", {} },
|
|
|
|
{ "Hungary", "9,797,561", "105.3", {} },
|
|
|
|
{ "Iceland", "332,529", "3.2", {} },
|
|
|
|
{ "Italy", "60,589,445", "201.3", {} },
|
|
|
|
{ "Norway", "5,267,146", "15.8", {} },
|
|
|
|
{ "Poland", "38,634,007", "123.0", {} },
|
|
|
|
{ "Portugal", "10,309,573", "115.0", {} },
|
|
|
|
{ "Romania", "19,638,000", "84.4", {} },
|
|
|
|
{ "Serbia", "7,058,322", "91.1", {} },
|
|
|
|
{ "Spain", "46,468,102", "92.0", {} },
|
|
|
|
{ "Sweden", "10,065,389", "22.0", {} },
|
|
|
|
{ "United Kingdom", "65,648,000", "270.7", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initNorthAmerica() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Canada", "35,151,728", "3.92", {} },
|
|
|
|
{ "Cuba", "11,239,224", "102.3", {} },
|
|
|
|
{ "Greenland", "56,483", "0.028", {} },
|
|
|
|
{ "Guatemala", "16,582,469", "129.0", {} },
|
|
|
|
{ "Honduras", "9,112,867", "64.0", {} },
|
|
|
|
{ "Mexico", "119,530,753", "61.0", {} },
|
|
|
|
{ "Nicaragua", "6,167,237", "51.0", {} },
|
|
|
|
{ "USA", "325,365,189", "35.0", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initSouthAmerica() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Argentina", "43,847,430", "14.4", {} },
|
|
|
|
{ "Bolivia", "11,410,651", "10.4", {} },
|
|
|
|
{ "Brazil", "208,064,000", "24.35", {} },
|
|
|
|
{ "Chile", "18,006,407", "24.0", {} },
|
|
|
|
{ "Colombia", "49,364,592", "40.74", {} },
|
|
|
|
{ "Ecuador", "16,385,068", "58.95", {} },
|
|
|
|
{ "Guyana", "773,303", "3.502", {} },
|
|
|
|
{ "Paraguay", "6,725,308", "17.2", {} },
|
|
|
|
{ "Peru", "31,826,018", "23.0", {} },
|
|
|
|
{ "Venezuela", "31,568,179", "33.75", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-12-05 23:54:40 +01:00
|
|
|
auto Treeview::initOceania() const -> std::initializer_list<Treeview::TreeItem>
|
2020-11-24 21:06:39 +01:00
|
|
|
{
|
|
|
|
static const auto list = std::initializer_list<Treeview::TreeItem>
|
|
|
|
{
|
|
|
|
{ "Australia", "24,675,900", "3.2", {} },
|
|
|
|
{ "Papua New Guinea", "7,059,653", "15.0", {} },
|
|
|
|
{ "Papua", "3,486,432", "11.0", {} },
|
|
|
|
{ "New Zealand", "4,823,090", "17.5", {} },
|
|
|
|
{ "West Papua", "877,437", "6.3", {} },
|
|
|
|
{ "Solomon Islands", "599,419", "18.1", {} },
|
|
|
|
{ "New Caledonia", "268,767", "14.5", {} },
|
|
|
|
{ "Fiji", "898,76", "46.4", {} },
|
|
|
|
{ "Hawaii", "1,428,557", "82.6", {} },
|
|
|
|
{ "Vanuatu", "270,402", "19.7", {} },
|
|
|
|
{ "French Polynesia", "280,208", "76.0", {} },
|
|
|
|
{ "Samoa", "192,342", "68.0", {} },
|
|
|
|
{ "Kiribati", "110,136", "152.0", {} }
|
|
|
|
};
|
|
|
|
return list;
|
|
|
|
}
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2017-10-14 22:20:19 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Treeview::adjustSize()
|
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
finalcut::FDialog::adjustSize();
|
|
|
|
|
2019-02-07 23:05:50 +01:00
|
|
|
std::size_t h = getDesktopHeight() - 4;
|
2017-10-14 22:20:19 +02:00
|
|
|
setHeight (h, false);
|
2020-10-04 02:55:15 +02:00
|
|
|
auto x = int((getDesktopWidth() - getWidth()) / 2);
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2020-09-25 00:48:58 +02:00
|
|
|
if ( x < 1 )
|
|
|
|
x = 1;
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2020-10-04 00:59:21 +02:00
|
|
|
setPos (FPoint{x, 3}, false);
|
2017-10-14 22:20:19 +02:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
if ( initialized )
|
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
listview.setHeight (getHeight() - 6, true);
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.setY(int(getHeight()) - 4);
|
2018-10-03 22:23:55 +02:00
|
|
|
}
|
2017-10-14 22:20:19 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 00:47:35 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Treeview::onClose (finalcut::FCloseEvent* ev)
|
2017-08-24 00:47:35 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2017-08-24 00:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FApplication app{argc, argv};
|
2017-08-24 00:47:35 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2020-05-02 00:07:35 +02:00
|
|
|
Treeview d{&app};
|
2017-08-24 00:47:35 +02:00
|
|
|
d.setText (L"Continents");
|
2020-10-04 00:59:21 +02:00
|
|
|
d.setSize (FSize{57, 20});
|
2017-08-24 00:47:35 +02:00
|
|
|
d.setShadow();
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog d as main widget
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget(&d);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2017-08-24 00:47:35 +02:00
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|