WIP: generalized interface of properties page

This commit is contained in:
Matthias Koefferlein 2022-10-06 21:31:16 +02:00
parent ddff1f564f
commit eb004e45e1
11 changed files with 117 additions and 236 deletions

View File

@ -65,7 +65,7 @@ PropertiesPage::PropertiesPage (ant::Service *rulers, db::Manager *manager, QWid
: lay::PropertiesPage (parent, manager, rulers), mp_rulers (rulers), m_enable_cb_callback (true), m_in_something_changed (false)
{
mp_rulers->get_selection (m_selection);
m_pos = m_selection.begin ();
m_index = 0;
setupUi (this);
@ -126,18 +126,6 @@ PropertiesPage::~PropertiesPage ()
mp_rulers->restore_highlights ();
}
void
PropertiesPage::back ()
{
m_pos = m_selection.end ();
}
void
PropertiesPage::front ()
{
m_pos = m_selection.begin ();
}
void
PropertiesPage::swap_points_clicked ()
{
@ -374,32 +362,27 @@ PropertiesPage::snap_to_layout_clicked ()
const ant::Object &
PropertiesPage::current () const
{
const ant::Object *ruler = dynamic_cast <const ant::Object *> ((*m_pos)->ptr ());
const ant::Object *ruler = dynamic_cast <const ant::Object *> (m_selection [m_index]->ptr ());
return *ruler;
}
bool
PropertiesPage::at_begin () const
size_t
PropertiesPage::count () const
{
return (m_pos == m_selection.begin ());
return m_selection.size ();
}
bool
PropertiesPage::at_end () const
void
PropertiesPage::select_entries (const std::vector<size_t> &entries)
{
return (m_pos == m_selection.end ());
tl_assert (entries.size () == 1); // @@@
m_index = entries.front ();
}
void
PropertiesPage::operator-- ()
std::string
PropertiesPage::description (size_t entry) const
{
--m_pos;
}
void
PropertiesPage::operator++ ()
{
++m_pos;
return "Ruler"; // @@@
}
void
@ -411,7 +394,7 @@ PropertiesPage::leave ()
void
PropertiesPage::update ()
{
mp_rulers->highlight (std::distance (m_selection.begin (), m_pos));
mp_rulers->highlight (m_index);
update_with (current ());
}
@ -504,7 +487,7 @@ PropertiesPage::apply ()
{
ant::Object obj;
get_object (obj);
mp_rulers->change_ruler (*m_pos, obj);
mp_rulers->change_ruler (m_selection [m_index], obj); // @@@ multi-apply
}
void PropertiesPage::get_object(ant::Object &obj)

View File

@ -43,12 +43,9 @@ public:
PropertiesPage (ant::Service *rulers, db::Manager *manager, QWidget *parent);
~PropertiesPage ();
virtual void back ();
virtual void front ();
virtual bool at_begin () const;
virtual bool at_end () const;
virtual void operator-- ();
virtual void operator++ ();
virtual size_t count () const;
virtual void select_entries (const std::vector<size_t> &entries);
virtual std::string description (size_t entry) const;
virtual void update ();
virtual void leave ();
virtual bool readonly ();
@ -61,7 +58,7 @@ private slots:
private:
std::vector <ant::Service::obj_iterator> m_selection;
std::vector <ant::Service::obj_iterator>::iterator m_pos;
size_t m_index;
ant::Service *mp_rulers;
bool m_enable_cb_callback;
bool m_in_something_changed;

View File

@ -226,40 +226,23 @@ InstPropertiesPage::display_mode_changed (bool)
update ();
}
void
InstPropertiesPage::back ()
size_t
InstPropertiesPage::count () const
{
m_index = (unsigned int) m_selection_ptrs.size ();
return m_selection_ptrs.size ();
}
void
InstPropertiesPage::front ()
void
InstPropertiesPage::select_entries (const std::vector<size_t> &entries)
{
m_index = 0;
tl_assert (entries.size () == 1); // @@@
m_index = entries.front ();
}
bool
InstPropertiesPage::at_begin () const
std::string
InstPropertiesPage::description (size_t entry) const
{
return (m_index == 0);
}
bool
InstPropertiesPage::at_end () const
{
return (m_index == m_selection_ptrs.size ());
}
void
InstPropertiesPage::operator-- ()
{
--m_index;
}
void
InstPropertiesPage::operator++ ()
{
++m_index;
return m_selection_ptrs [entry]->back ().inst_ptr.to_string (); // @@@
}
void

View File

@ -47,12 +47,9 @@ public:
InstPropertiesPage (edt::Service *service, db::Manager *manager, QWidget *parent);
~InstPropertiesPage ();
virtual void back ();
virtual void front ();
virtual bool at_begin () const;
virtual bool at_end () const;
virtual void operator-- ();
virtual void operator++ ();
virtual size_t count () const;
virtual void select_entries (const std::vector<size_t> &entries);
virtual std::string description (size_t entry) const;
virtual void leave ();
private:

View File

@ -73,40 +73,23 @@ ShapePropertiesPage::setup ()
m_enable_cb_callback = true;
}
void
ShapePropertiesPage::back ()
size_t
ShapePropertiesPage::count () const
{
m_index = (unsigned int) m_selection_ptrs.size ();
return m_selection_ptrs.size ();
}
void
ShapePropertiesPage::front ()
void
ShapePropertiesPage::select_entries (const std::vector<size_t> &entries)
{
m_index = 0;
tl_assert (entries.size () == 1); // @@@
m_index = entries.front ();
}
bool
ShapePropertiesPage::at_begin () const
std::string
ShapePropertiesPage::description (size_t entry) const
{
return (m_index == 0);
}
bool
ShapePropertiesPage::at_end () const
{
return (m_index == m_selection_ptrs.size ());
}
void
ShapePropertiesPage::operator-- ()
{
--m_index;
}
void
ShapePropertiesPage::operator++ ()
{
++m_index;
return m_selection_ptrs [entry]->shape ().to_string (); // @@@
}
void

View File

@ -49,12 +49,9 @@ public:
ShapePropertiesPage (edt::Service *service, db::Manager *manager, QWidget *parent);
~ShapePropertiesPage ();
virtual void back ();
virtual void front ();
virtual bool at_begin () const;
virtual bool at_end () const;
virtual void operator-- ();
virtual void operator++ ();
virtual size_t count () const;
virtual void select_entries (const std::vector<size_t> &entries);
virtual std::string description (size_t entry) const;
virtual void leave ();
protected:

View File

@ -44,7 +44,7 @@ PropertiesPage::PropertiesPage (img::Service *service, db::Manager *manager, QWi
: lay::PropertiesPage (parent, manager, service), mp_service (service), mp_direct_image (0)
{
mp_service->get_selection (m_selection);
m_pos = m_selection.begin ();
m_index = 0;
mp_service->clear_highlights ();
@ -154,44 +154,24 @@ PropertiesPage::invalidate ()
}
}
void
PropertiesPage::back ()
size_t
PropertiesPage::count () const
{
m_pos = m_selection.end ();
return m_selection.size ();
}
void
PropertiesPage::select_entries (const std::vector<size_t> &entries)
{
tl_assert (entries.size () == 1); // @@@
m_index = entries.front ();
invalidate ();
}
void
PropertiesPage::front ()
std::string
PropertiesPage::description (size_t entry) const
{
m_pos = m_selection.begin ();
invalidate ();
}
bool
PropertiesPage::at_begin () const
{
return (m_pos == m_selection.begin ());
}
bool
PropertiesPage::at_end () const
{
return (m_pos == m_selection.end ());
}
void
PropertiesPage::operator-- ()
{
--m_pos;
invalidate ();
}
void
PropertiesPage::operator++ ()
{
++m_pos;
invalidate ();
return "image"; // @@@
}
void
@ -378,11 +358,11 @@ PropertiesPage::update ()
if (mp_service) {
mp_service->highlight (std::distance (m_selection.begin (), m_pos));
mp_service->highlight (m_index);
// create a local copy in which we can apply modifications
if (! mp_direct_image) {
const img::Object *image = dynamic_cast <const img::Object *> ((*m_pos)->ptr ());
const img::Object *image = dynamic_cast <const img::Object *> (m_selection [m_index]->ptr ());
mp_direct_image = new img::Object (*image);
}
@ -908,7 +888,7 @@ PropertiesPage::apply ()
mp_direct_image->set_data_mapping (dm);
if (mp_service) {
mp_service->change_image (*m_pos, *mp_direct_image);
mp_service->change_image (m_selection [m_index], *mp_direct_image);
}
}

View File

@ -50,12 +50,9 @@ public:
PropertiesPage (QWidget *parent);
~PropertiesPage ();
virtual void back ();
virtual void front ();
virtual bool at_begin () const;
virtual bool at_end () const;
virtual void operator-- ();
virtual void operator++ ();
virtual size_t count () const;
virtual void select_entries (const std::vector<size_t> &entries);
virtual std::string description (size_t entry) const;
virtual void update ();
virtual void leave ();
virtual bool readonly ();
@ -91,7 +88,7 @@ private slots:
private:
std::vector <img::Service::obj_iterator> m_selection;
std::vector <img::Service::obj_iterator>::iterator m_pos;
size_t m_index;
img::Service *mp_service;
img::Object *mp_direct_image;
bool m_no_signals;

View File

@ -69,80 +69,33 @@ public:
virtual ~PropertiesPage ();
/**
* @brief Move the current pointer to the end of the selected objects list
*
* Must be implemented by the Editable function and must set the
* selected object pointer to past-the-end of the list. at_end () must
* return true after this.
* @brief Gets the number of entries represented by this page
*/
virtual void back () = 0;
virtual size_t count () const = 0;
/**
* @brief A helper function for the dialog that additionally reports
* if there are any elements in the selection
* @brief Selects the entries with the given indexes
*
* If multiple indexes are selected, the properties page shows
* all items with different values as "leave as is". Items with
* same value are shown with the given value.
*/
bool back_checked ()
virtual void select_entries (const std::vector<size_t> &entries) = 0;
/**
* @brief Convenience function to select a specific entry
*/
void select_entry (size_t entry)
{
back ();
return ! at_begin ();
std::vector<size_t> entries;
entries.push_back (entry);
select_entries (entries);
}
/**
* @brief Move the current pointer to the beginning of the selected objects list
*
* Must be implemented by the Editable function and must set the
* selected object pointer to the beginning of the list. at_begin () must
* return true after this.
* This method must return true, if there are any elements in the selection
* - i.e. operator++ () will be successful afterwards.
* @brief Gets a description text for the nth entry
*/
virtual void front () = 0;
/**
* @brief A helper function for the dialog that additionally reports
* if there are any elements in the selection
*/
bool front_checked ()
{
front ();
return ! at_end ();
}
/**
* @brief Tell if the current object references the first one
*
* Must be implemented by the Editable function and must return
* true if the current object is the first one - i.e. if an
* operator-- would render the status invalid.
* If no object is referenced, this method and at_end () must return true.
*/
virtual bool at_begin () const = 0;
/**
* @brief Tell if the current object references past the last one
*
* If the current object pointer is past the end of the selected
* object space,
*/
virtual bool at_end () const = 0;
/**
* @brief Step one element back
*
* This method is supposed to move the current pointer one position
* back. If at_begin () was true before, the result may be unpredictable.
* The dialog will call update () to update the display accordingly.
*/
virtual void operator-- () = 0;
/**
* @brief Advance one element
*
* This method is supposed to move the current pointer one position
* forward. If at_end () was true before, the result may be unpredictable.
* The dialog will call update () to update the display accordingly.
*/
virtual void operator++ () = 0;
virtual std::string description (size_t entry) const = 0;
/**
* @brief Update the display
@ -176,7 +129,7 @@ public:
/**
* @brief Apply any changes to the current object
*
* Apply any changes to the current object. If nothing was
* Apply any changes to the current objects. If nothing was
* changed, the object may be left untouched.
* The dialog will start a transaction on the manager object.
*/
@ -187,6 +140,7 @@ public:
/**
* @brief Returns true, if the properties page supports "apply all"
* @@@ TODO: remove
*/
virtual bool can_apply_to_all () const
{

View File

@ -38,7 +38,7 @@ namespace lay
PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager, lay::Editables *editables)
: QDialog (0 /*parent*/),
mp_manager (manager), mp_editables (editables), m_index (-1), m_auto_applied (false), m_transaction_id (0)
mp_manager (manager), mp_editables (editables), m_index (-1), m_object_index (0), m_auto_applied (false), m_transaction_id (0)
{
mp_ui = new Ui::PropertiesDialog ();
@ -83,7 +83,7 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
// look for next usable editable
while (m_index < int (mp_properties_pages.size ()) &&
(m_index < 0 || mp_properties_pages [m_index] == 0 || mp_properties_pages [m_index]->at_end ())) {
(m_index < 0 || mp_properties_pages [m_index] == 0 || m_object_index >= int (mp_properties_pages [m_index]->count ()))) {
++m_index;
}
@ -103,8 +103,9 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
} else {
mp_ui->next_button->setEnabled (any_next ());
mp_properties_pages [m_index]->update ();
mp_stack->setCurrentWidget (mp_properties_pages [m_index]);
mp_properties_pages [m_index]->select_entry (m_object_index);
mp_properties_pages [m_index]->update ();
mp_ui->apply_to_all_cbx->setEnabled (! mp_properties_pages [m_index]->readonly () && mp_properties_pages [m_index]->can_apply_to_all ());
mp_ui->apply_to_all_cbx->setChecked (false);
mp_ui->relative_cbx->setEnabled (mp_ui->apply_to_all_cbx->isEnabled () && mp_ui->apply_to_all_cbx->isChecked ());
@ -152,21 +153,26 @@ BEGIN_PROTECTED
}
// advance the current entry
++(*mp_properties_pages [m_index]);
++m_object_index;
// look for next usable editable if at end
if (mp_properties_pages [m_index]->at_end ()) {
if (m_object_index >= int (mp_properties_pages [m_index]->count ())) {
mp_properties_pages [m_index]->leave ();
++m_index;
m_object_index = 0;
while (m_index < int (mp_properties_pages.size ()) &&
(mp_properties_pages [m_index] == 0 || ! mp_properties_pages [m_index]->front_checked ())) {
(mp_properties_pages [m_index] == 0 || mp_properties_pages [m_index]->count () == 0)) {
++m_index;
}
// because we checked that there are any further elements, this should not happen:
if (m_index >= int (mp_properties_pages.size ())) {
return;
}
mp_stack->setCurrentWidget (mp_properties_pages [m_index]);
}
++m_current_object;
@ -177,6 +183,7 @@ BEGIN_PROTECTED
mp_ui->apply_to_all_cbx->setEnabled (! mp_properties_pages [m_index]->readonly () && mp_properties_pages [m_index]->can_apply_to_all ());
mp_ui->relative_cbx->setEnabled (mp_ui->apply_to_all_cbx->isEnabled () && mp_ui->apply_to_all_cbx->isChecked ());
mp_ui->ok_button->setEnabled (! mp_properties_pages [m_index]->readonly ());
mp_properties_pages [m_index]->select_entry (m_object_index);
mp_properties_pages [m_index]->update ();
END_PROTECTED
@ -195,25 +202,28 @@ BEGIN_PROTECTED
}
}
if (mp_properties_pages [m_index]->at_begin ()) {
if (m_object_index == 0) {
// look for last usable editable if at end
mp_properties_pages [m_index]->leave ();
--m_index;
while (m_index >= 0 &&
(mp_properties_pages [m_index] == 0 || ! mp_properties_pages [m_index]->back_checked ())) {
(mp_properties_pages [m_index] == 0 || mp_properties_pages [m_index]->count () == 0)) {
--m_index;
}
// because we checked that there are any further elements, this should not happen:
if (m_index < 0) {
return;
}
m_object_index = mp_properties_pages [m_index]->count () - 1;
mp_stack->setCurrentWidget (mp_properties_pages [m_index]);
}
// decrement the current entry
--(*mp_properties_pages [m_index]);
--m_object_index;
--m_current_object;
update_title ();
@ -223,6 +233,7 @@ BEGIN_PROTECTED
mp_ui->apply_to_all_cbx->setEnabled (! mp_properties_pages [m_index]->readonly () && mp_properties_pages [m_index]->can_apply_to_all ());
mp_ui->relative_cbx->setEnabled (mp_ui->apply_to_all_cbx->isEnabled () && mp_ui->apply_to_all_cbx->isChecked ());
mp_ui->ok_button->setEnabled (! mp_properties_pages [m_index]->readonly ());
mp_properties_pages [m_index]->select_entry (m_object_index);
mp_properties_pages [m_index]->update ();
END_PROTECTED
@ -237,32 +248,31 @@ PropertiesDialog::update_title ()
bool
PropertiesDialog::any_next () const
{
// test-advance
// look for the next applicable page
// @@@ Pages should not be empty
int index = m_index;
++(*mp_properties_pages [index]);
if (mp_properties_pages [index]->at_end ()) {
if (m_object_index + 1 >= int (mp_properties_pages [index]->count ())) {
++index;
while (index < int (mp_properties_pages.size ()) &&
(mp_properties_pages [index] == 0 || ! mp_properties_pages [index]->front_checked ())) {
while (index < int (mp_properties_pages.size ()) &&
(mp_properties_pages [index] == 0 || mp_properties_pages [index]->count () == 0)) {
++index;
}
}
// return true, if not at end
bool ret = (index < int (mp_properties_pages.size ()));
--(*mp_properties_pages [m_index]);
return ret;
return (index < int (mp_properties_pages.size ()));
}
bool
PropertiesDialog::any_prev () const
{
// test-decrement
// look for the next applicable page
// @@@ Pages should not be empty
int index = m_index;
if (mp_properties_pages [index]->at_begin ()) {
if (m_object_index == 0) {
--index;
while (index >= 0 &&
(mp_properties_pages [index] == 0 || ! mp_properties_pages [index]->back_checked ())) {
(mp_properties_pages [index] == 0 || mp_properties_pages [index]->count () == 0)) {
--index;
}
}

View File

@ -82,7 +82,7 @@ private:
std::vector<lay::PropertiesPage *> mp_properties_pages;
db::Manager *mp_manager;
lay::Editables *mp_editables;
int m_index;
int m_index, m_object_index;
QStackedLayout *mp_stack;
lay::MainWindow *mp_mw;
size_t m_objects, m_current_object;