2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* listview.cpp - Example for using a multi-column FListView widget *
|
|
|
|
* *
|
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-07-18 23:50:51 +02:00
|
|
|
|
2020-10-08 16:46:14 +02:00
|
|
|
#include <array>
|
2017-07-18 23:50:51 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2017-07-18 23:50:51 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-07-18 23:50:51 +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-07-18 23:50:51 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-08-01 00:56:12 +02:00
|
|
|
// class Listview
|
2017-07-18 23:50:51 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Listview final : public finalcut::FDialog
|
2017-07-18 23:50:51 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Listview (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Listview (const Listview&) = 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
|
|
|
~Listview() 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
|
|
|
Listview& operator = (const Listview&) = delete;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2018-02-04 19:42:30 +01:00
|
|
|
// Method
|
2018-10-03 22:23:55 +02:00
|
|
|
void populate();
|
2018-02-04 19:42:30 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-10-29 18:27:38 +01:00
|
|
|
// Callback method
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_showInMessagebox();
|
2018-10-03 22:23:55 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-09-25 00:48:58 +02:00
|
|
|
finalcut::FListView listview{this};
|
|
|
|
finalcut::FButton quit{this};
|
2017-07-18 23:50:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Listview::Listview (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2017-07-18 23:50:51 +02: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{33, 14});
|
2017-07-18 23:50:51 +02:00
|
|
|
|
|
|
|
// Add columns to the view
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.addColumn ("City");
|
|
|
|
listview.addColumn ("Condition");
|
|
|
|
listview.addColumn ("Temp.");
|
|
|
|
listview.addColumn ("Humidity");
|
|
|
|
listview.addColumn ("Pressure", 10);
|
2017-07-28 22:18:42 +02:00
|
|
|
|
|
|
|
// Set right alignment for the third, fourth, and fifth column
|
2020-12-31 20:45:10 +01:00
|
|
|
listview.setColumnAlignment (3, finalcut::Align::Right);
|
|
|
|
listview.setColumnAlignment (4, finalcut::Align::Right);
|
|
|
|
listview.setColumnAlignment (5, finalcut::Align::Right);
|
2017-07-28 22:18:42 +02:00
|
|
|
|
2018-09-28 06:45:02 +02: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::Name);
|
|
|
|
listview.setColumnSortType (3, finalcut::SortType::Number);
|
|
|
|
listview.setColumnSortType (4, finalcut::SortType::Number);
|
|
|
|
listview.setColumnSortType (5, finalcut::SortType::Number);
|
2018-09-28 06:45:02 +02:00
|
|
|
|
|
|
|
// Sort in ascending order by the 1st column
|
2020-12-31 20:45:10 +01:00
|
|
|
listview.setColumnSort (1, finalcut::SortOrder::Ascending);
|
2018-11-10 00:53:57 +01:00
|
|
|
// Sorting follows later automatically on insert().
|
2018-09-28 06:45:02 +02:00
|
|
|
// Otherwise you could start the sorting directly with sort()
|
|
|
|
|
2018-11-10 00:53:57 +01:00
|
|
|
// Allways show the sort indicator (▼/▲)
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.hideSortIndicator(false);
|
2018-11-10 00:53:57 +01:00
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
// Populate FListView with a list of items
|
2018-10-03 22:23:55 +02:00
|
|
|
populate();
|
2018-02-04 19:42:30 +01:00
|
|
|
|
|
|
|
// Quit button
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
|
|
|
|
quit.setText (L"&Quit");
|
2018-02-04 19:42:30 +01:00
|
|
|
|
|
|
|
// Add some function callbacks
|
2020-09-25 00:48:58 +02:00
|
|
|
quit.addCallback
|
2018-02-04 19:42:30 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
finalcut::getFApplication(),
|
|
|
|
&finalcut::FApplication::cb_exitApp,
|
|
|
|
this
|
2018-02-04 19:42:30 +01:00
|
|
|
);
|
|
|
|
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.addCallback
|
2018-02-04 19:42:30 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Listview::cb_showInMessagebox
|
2018-02-04 19:42:30 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Listview::populate()
|
2018-02-04 19:42:30 +01:00
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
constexpr std::array<std::array<const char*, 5>, 41> weather =
|
|
|
|
{{
|
|
|
|
{{ "Alexandria", "Sunny", "31°C", "61%", "1006.4 mb" }},
|
|
|
|
{{ "Amsterdam", "Cloudy", "21°C", "82%", "1021.3 mb" }},
|
|
|
|
{{ "Baghdad", "Fair", "47°C", "9%", "1001.0 mb" }},
|
|
|
|
{{ "Bangkok", "Partly Cloudy", "30°C", "69%", "1002.0 mb" }},
|
|
|
|
{{ "Beijing", "Fair", "31°C", "68%", "1007.1 mb" }},
|
|
|
|
{{ "Berlin", "Cloudy", "22°C", "53%", "1022.0 mb" }},
|
|
|
|
{{ "Bogotá", "Fair", "9°C", "95%", "1028.5 mb" }},
|
|
|
|
{{ "Budapest", "Partly Cloudy", "23°C", "37%", "1020.7 mb" }},
|
|
|
|
{{ "Buenos Aires", "Cloudy", "7°C", "73%", "1019.0 mb" }},
|
|
|
|
{{ "Cairo", "Fair", "39°C", "22%", "1006.1 mb" }},
|
|
|
|
{{ "Cape Town", "Partly Cloudy", "12°C", "45%", "1030.1 mb" }},
|
|
|
|
{{ "Chicago", "Mostly Cloudy", "21°C", "81%", "1014.9 mb" }},
|
|
|
|
{{ "Delhi", "Haze", "33°C", "68%", "998.0 mb" }},
|
|
|
|
{{ "Dhaka", "Haze", "32°C", "64%", "996.3 mb" }},
|
|
|
|
{{ "Houston", "Cloudy", "23°C", "100%", "1014.2 mb" }},
|
|
|
|
{{ "Istanbul", "Mostly Cloudy", "27°C", "61%", "1011.2 mb" }},
|
|
|
|
{{ "Jakarta", "Fair", "28°C", "71%", "1009.1 mb" }},
|
|
|
|
{{ "Jerusalem", "Sunny", "35°C", "17%", "1005.8 mb" }},
|
|
|
|
{{ "Johannesburg", "Fair", "18°C", "16%", "1020.0 mb" }},
|
|
|
|
{{ "Karachi", "Mostly Cloudy", "29°C", "76%", "998.0 mb" }},
|
|
|
|
{{ "Lagos", "Mostly Cloudy", "27°C", "86%", "1014.6 mb" }},
|
|
|
|
{{ "Lima", "Cloudy", "17°C", "83%", "1017.3 mb" }},
|
|
|
|
{{ "London", "Cloudy", "23°C", "71%", "1023.0 mb" }},
|
|
|
|
{{ "Los Angeles", "Fair", "21°C", "78%", "1011.9 mb" }},
|
|
|
|
{{ "Madrid", "Fair", "32°C", "35%", "1020.0 mb" }},
|
|
|
|
{{ "Mexico City", "Partly Cloudy", "14°C", "79%", "1028.5 mb" }},
|
|
|
|
{{ "Moscow", "Partly Cloudy", "24°C", "54%", "1014.2 mb" }},
|
|
|
|
{{ "Mumbai", "Haze", "28°C", "77%", "1003.0 mb" }},
|
|
|
|
{{ "New York City", "Sunny", "21°C", "80%", "1014.2 mb" }},
|
|
|
|
{{ "Paris", "Partly Cloudy", "27°C", "57%", "1024.4 mb" }},
|
|
|
|
{{ "Reykjavík", "Mostly Cloudy", "11°C", "76%", "998.6 mb" }},
|
|
|
|
{{ "Rio de Janeiro", "Fair", "24°C", "64%", "1022.0 mb" }},
|
|
|
|
{{ "Rome", "Fair", "32°C", "18%", "1014.2 mb" }},
|
|
|
|
{{ "Saint Petersburg", "Mostly Cloudy", "18°C", "55%", "1014.6 mb" }},
|
|
|
|
{{ "São Paulo", "Fair", "19°C", "53%", "1024.0 mb" }},
|
|
|
|
{{ "Seoul", "Cloudy", "26°C", "87%", "1012.2 mb" }},
|
|
|
|
{{ "Shanghai", "Fair", "32°C", "69%", "1009.1 mb" }},
|
|
|
|
{{ "Singapore", "Mostly Cloudy", "29°C", "73%", "1009.1 mb" }},
|
|
|
|
{{ "Tehran", "Fair", "36°C", "14%", "1013.2 mb" }},
|
|
|
|
{{ "Tokyo", "Mostly Cloudy", "28°C", "67%", "1009.1 mb" }},
|
|
|
|
{{ "Zurich", "Mostly Cloudy", "23°C", "44%", "1023.7 mb" }}
|
|
|
|
}};
|
2017-07-18 23:50:51 +02:00
|
|
|
|
2019-10-14 01:44:24 +02:00
|
|
|
for (const auto& place : weather)
|
2017-07-18 23:50:51 +02:00
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
const finalcut::FStringList line (place.begin(), place.end());
|
2020-09-25 00:48:58 +02:00
|
|
|
listview.insert (line);
|
2017-07-18 23:50:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Listview::onClose (finalcut::FCloseEvent* ev)
|
2017-07-18 23:50:51 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2017-07-18 23:50:51 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 00:56:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Listview::cb_showInMessagebox()
|
2017-08-01 00:56:12 +02:00
|
|
|
{
|
2020-09-25 00:48:58 +02:00
|
|
|
const auto& item = listview.getCurrentItem();
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FMessageBox info ( "Weather in " + item->getText(1)
|
|
|
|
, " Condition: " + item->getText(2) + "\n"
|
|
|
|
"Temperature: " + item->getText(3) + "\n"
|
|
|
|
" Humidity: " + item->getText(4) + "\n"
|
|
|
|
" Pressure: " + item->getText(5)
|
2020-12-05 21:24:09 +01:00
|
|
|
, finalcut::FMessageBox::ButtonType::Ok
|
|
|
|
, finalcut::FMessageBox::ButtonType::Reject
|
|
|
|
, finalcut::FMessageBox::ButtonType::Reject
|
2020-10-04 00:59:21 +02:00
|
|
|
, this );
|
2017-08-01 00:56:12 +02:00
|
|
|
info.show();
|
|
|
|
}
|
2017-07-18 23:50:51 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2017-07-18 23:50:51 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication app(argc, argv);
|
2017-07-18 23:50:51 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2017-07-18 23:50:51 +02:00
|
|
|
Listview d(&app);
|
2017-08-01 00:56:12 +02:00
|
|
|
d.setText (L"Weather data");
|
2020-05-02 00:07:35 +02:00
|
|
|
d.setGeometry ( FPoint{int(1 + (app.getWidth() - 37) / 2), 3}
|
|
|
|
, FSize{37, 20} );
|
2017-07-18 23:50:51 +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-07-18 23:50:51 +02:00
|
|
|
d.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|