From: <sv...@va...> - 2010-03-13 12:18:18
|
Author: cerion Date: 2010-03-13 12:17:07 +0000 (Sat, 13 Mar 2010) New Revision: 496 Log: More option page stuff: If any edits in last page, ask user what to do: - Accept edits and move on - Reject edits and move on - Cancel (i.e. cancel move to new page), and remain where we were. oh, and changing option category now works with up/down keys. Modified: branches/valkyrie_qt4port/options/vk_options_dialog.cpp branches/valkyrie_qt4port/options/vk_options_dialog.h branches/valkyrie_qt4port/options/vk_options_page.cpp branches/valkyrie_qt4port/options/vk_options_page.h Modified: branches/valkyrie_qt4port/options/vk_options_dialog.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_options_dialog.cpp 2010-03-12 20:40:12 UTC (rev 495) +++ branches/valkyrie_qt4port/options/vk_options_dialog.cpp 2010-03-13 12:17:07 UTC (rev 496) @@ -50,7 +50,10 @@ setupLayout(); // ------------------------------------------------------------ - // Add categories, and the default page (other pages loaded on demand) + // Add categories, and the pages + // Note: both the pages and categories list use the same 'index', + // which is how we keep them in sync. + // TODO: if any complaints re speed, load the pages on demand. VkObjectList objList = (( MainWindow* )parent )->getValkyrie()->vkObjList(); for ( int i = 0; i < objList.size(); ++i ) { @@ -83,8 +86,9 @@ contentsListWidget->setFocus(); optionPages->setCurrentIndex( 0 ); - // Give a max to our contentsList, based on the hints from the list-items. - //TODO: surely this can be done automatically? QSizePolicy::* don't seem to do the job :-( + // Give a max to our contentsList, based on hints from the list-items. + // TODO: surely this can be done automatically? + // - QSizePolicy::* don't seem to do the job :-( contentsListWidget->setMaximumWidth( 40 + contentsListWidget->sizeHintForColumn( 0 ) ); ContextHelp::addHelp( this, urlValkyrie::optsDlg ); @@ -190,9 +194,9 @@ // ------------------------------------------------------------ // signals / slots - connect( contentsListWidget, SIGNAL( itemClicked( QListWidgetItem* ) ), - this, SLOT( showPage( QListWidgetItem* ) ) ); - + connect( contentsListWidget, SIGNAL( itemSelectionChanged() ), + this, SLOT( showPage() ) ); + QPushButton* applyButton = optionsButtonBox->button( QDialogButtonBox::Apply ); QPushButton* cancelButton = optionsButtonBox->button( QDialogButtonBox::Cancel ); QPushButton* okButton = optionsButtonBox->button( QDialogButtonBox::Ok ); @@ -210,24 +214,71 @@ /*! - Show the chosen options page + Show the chosen options page. + + If any edits in last page, ask user what to do: + - Accept edits and move on + - Reject edits and move on + - Cancel (i.e. cancel move to new page), and remain where we were. + + Note: have to use listwidget signal itemSelectionChanged(), to make + sure the item has already been updated - else our update of + current-item would get overridden. */ -void VkOptionsDialog::showPage( QListWidgetItem* nextItem ) +void VkOptionsDialog::showPage() { - int nextIdx = contentsListWidget->row( nextItem ); - - // std::cerr << "showPage( " << nextIdx << " )" << std::endl; - - // TODO: check no uncommited edits in last page - // proper way to do this is subclass contentsListWidget to catch click events... - - //TODO? setWindowTitle( capt + item->text() ); - optionPages->setCurrentIndex( nextIdx ); + int nextIdx = contentsListWidget->currentRow(); + int prevIdx = optionPages->currentIndex(); + //cerr << "itemSelectionChanged: old->new: " << prevIdx << "->" << nextIdx << endl; + + if ( nextIdx == prevIdx ) { + // get here on startup, and whenever we revert to last list item + // - easier than disconnecting signals etc. + return; + } + + // check no outstanding edits in prevItem. + bool continueToNext = true; + VkOptionsPage* prevPage = (VkOptionsPage*)optionPages->currentWidget(); + vk_assert( prevPage ); + + if ( prevPage->isModified() ) { + // choose to apply/reset edits + QString pageName = contentsListWidget->item( prevIdx )->text(); + + int ret_qry = + vkQuery( this, "Apply/Reset Edits", + "&Apply;&Reset;&Cancel", + "<p>The <b><i>%s</i></b> option page has non-committed edits.<br/>" + "Would you like to <b>Apply</b> or <b>Reset</b> these edits?<br/>" + "Choose <b>Cancel</b> to stay on the edited page.</p>", + qPrintable( pageName ) ); + + switch ( ret_qry ) { + case MsgBox::vkYes: apply(); break; // apply & move on + case MsgBox::vkNo: prevPage->rejectEdits(); break; // reject & move on + case MsgBox::vkCancel: continueToNext = false; break; // remain in prevPage + default: + vk_assert_never_reached(); + } + } + + if ( continueToNext ) { + // All done with last page: open next page + optionPages->setCurrentIndex( nextIdx ); + } + else { + // Revert current item in contents list. + // This will trigger this function to be called again, but with + // nextidx == previdx, so easy to ignore. + contentsListWidget->setCurrentRow( prevIdx ); + } } -/* reject edits - - only current page can be in an edited state. +/*! + reject edits + - showPage() ensures only current page can be in an edited state. */ void VkOptionsDialog::reject() { @@ -235,11 +286,10 @@ VkOptionsPage* page = ( VkOptionsPage* )optionPages->currentWidget(); vk_assert( page ); - - if ( !page->rejectEdits() ) { - VK_DEBUG( "Failed to reject edits" ); - } - + + page->rejectEdits(); + + // close up shop. QDialog::reject(); } @@ -270,7 +320,7 @@ /*! - apply edits and quit if no problems + Accept: apply edits and quit if no problems. - save the settings to the Project cfg file if specified */ void VkOptionsDialog::accept() @@ -278,6 +328,7 @@ // std::cerr << "VkOptionsDialog::apply()" << std::endl; if ( apply() ) { + // close up shop. QDialog::accept(); } @@ -292,11 +343,12 @@ */ void VkOptionsDialog::saveToGlobalConfig() { - int ok = vkQuery( this, 2, "Overwrite Global Config", - "<p>Are you <b>sure</b> you want to overwrite the global config ?</p>" - "<p><i>Note: Valkyrie will regenerate factory global settings<br>" - "if the global config file is removed:<br>" - "%s</i></p>", qPrintable( vkConfig->vkCfgGlblFilename() ) ); + int ok = + vkQuery( this, 2, "Overwrite Global Config", + "<p>Are you <b>sure</b> you want to overwrite the global config ?</p>" + "<p><i>Note: Valkyrie will regenerate factory global settings<br>" + "if the global config file is removed:<br>" + "%s</i></p>", qPrintable( vkConfig->vkCfgGlblFilename() ) ); if ( ok == MsgBox::vkYes ) { vkConfig->saveToGlblConfigFile(); @@ -304,8 +356,6 @@ } - - /*! Enable/disable buttons. This slot is called by page->modified() signal @@ -321,7 +371,7 @@ QPushButton* cancelButton = optionsButtonBox->button( QDialogButtonBox::Cancel ); applyButton->setEnabled( modified ); cancelButton->setEnabled( modified ); - // enable save only when no edits + // enable save-to-global only when no edits saveGlblButton->setEnabled( !modified ); // updates the window title to indicate modified. Modified: branches/valkyrie_qt4port/options/vk_options_dialog.h =================================================================== --- branches/valkyrie_qt4port/options/vk_options_dialog.h 2010-03-12 20:40:12 UTC (rev 495) +++ branches/valkyrie_qt4port/options/vk_options_dialog.h 2010-03-13 12:17:07 UTC (rev 496) @@ -45,11 +45,10 @@ bool apply(); void accept(); // overloaded void reject(); // overloaded - - void showPage( QListWidgetItem* ); + void showPage(); void pageModified(); void saveToGlobalConfig(); - + signals: void flagsChanged(); Modified: branches/valkyrie_qt4port/options/vk_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-03-12 20:40:12 UTC (rev 495) +++ branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-03-13 12:17:07 UTC (rev 496) @@ -103,8 +103,10 @@ } -/* reset button clicked */ -bool VkOptionsPage::rejectEdits() +/*! + Reset action activated +*/ +void VkOptionsPage::rejectEdits() { if ( m_editList.count() != 0 ) { // first copy the list: the list is managed by this->updateEditList(). @@ -112,21 +114,19 @@ // now remove all the items from m_editList: // signal is emitted for by each optw, calls this->updateEditList() - for ( int i = 0; i < tmpList.size(); ++i ) { - tmpList.at( i )->cancelEdit(); + foreach ( OptionWidget* opt, tmpList ) { + opt->cancelEdit(); } } vk_assert( m_mod == false ); vk_assert( m_editList.isEmpty() == true ); - - return ( !m_mod && m_editList.isEmpty() ); } /*! applyEdits() - user clicked Ok/Apply after editing some items + user chose Ok/Apply after editing some items */ bool VkOptionsPage::applyEdits() { Modified: branches/valkyrie_qt4port/options/vk_options_page.h =================================================================== --- branches/valkyrie_qt4port/options/vk_options_page.h 2010-03-12 20:40:12 UTC (rev 495) +++ branches/valkyrie_qt4port/options/vk_options_page.h 2010-03-13 12:17:07 UTC (rev 496) @@ -62,7 +62,7 @@ VkOptionsPage( VkObject* obj ); ~VkOptionsPage(); - bool rejectEdits(); + void rejectEdits(); bool applyEdits(); bool isModified() { return m_mod; |