diff --git a/src/speechclient.hh b/src/speechclient.hh index 1e3e8262..b72224fc 100644 --- a/src/speechclient.hh +++ b/src/speechclient.hh @@ -5,6 +5,7 @@ #include "config.hh" #include #include +#include class SpeechClient: public QObject { @@ -40,7 +41,7 @@ public: sp( std::make_unique< QTextToSpeech >( e.engine_name ) ), engine( e ) { - qDebug() << "initialize tts" << e.engine_name; + qDebug() << QStringLiteral( "initialize tts" ) << e.engine_name; #if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) if ( !sp || sp->state() == QTextToSpeech::Error ) return; @@ -75,10 +76,6 @@ public: bool tell( QString const & text, int volume, int rate ) const; bool tell( QString const & text ) const; - signals: - void started( bool ok ); - void finished(); - private: std::unique_ptr< InternalData > internalData; }; diff --git a/src/ui/editdictionaries.cc b/src/ui/editdictionaries.cc index b38738c8..3761c202 100644 --- a/src/ui/editdictionaries.cc +++ b/src/ui/editdictionaries.cc @@ -32,18 +32,18 @@ EditDictionaries::EditDictionaries( QWidget * parent, // the initial group readings so that if no edits were really done, we won't // be changing groups. origCfg.groups = groups->getGroups(); - origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder(); + origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder(); origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries(); ui.setupUi( this ); - setWindowIcon( QIcon(":/icons/dictionary.svg") ); + setWindowIcon( QIcon( ":/icons/dictionary.svg" ) ); ui.tabs->clear(); - ui.tabs->addTab( &sources, QIcon(":/icons/sources.png"), tr( "&Sources" ) ); - ui.tabs->addTab( orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); - ui.tabs->addTab( groups.get(), QIcon(":/icons/bookcase.svg"), tr( "&Groups" ) ); + ui.tabs->addTab( &sources, QIcon( ":/icons/sources.png" ), tr( "&Sources" ) ); + ui.tabs->addTab( orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); + ui.tabs->addTab( groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); connect( ui.buttons, &QDialogButtonBox::clicked, this, &EditDictionaries::buttonBoxClicked ); @@ -57,7 +57,7 @@ EditDictionaries::EditDictionaries( QWidget * parent, helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); connect( &helpAction, &QAction::triggered, [ this ]() { - if ( ui.tabs->currentWidget() == this->groups.get() ) { + if ( ui.tabs->currentWidget() == this->groups ) { Help::openHelpWebpage( Help::section::manage_groups ); } else { @@ -240,8 +240,8 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries ); groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); - ui.tabs->insertTab( 1, orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); - ui.tabs->insertTab( 2, groups.get(), QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); + ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) ); + ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) ); connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo ); connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords ); diff --git a/src/ui/groups_widgets.cc b/src/ui/groups_widgets.cc index d2c16f44..ae97d6b7 100644 --- a/src/ui/groups_widgets.cc +++ b/src/ui/groups_widgets.cc @@ -575,8 +575,8 @@ void DictGroupsWidget::populate( Config::Groups const & groups, connect( gr, &DictGroupWidget::showDictionaryInfo,this, &DictGroupsWidget::showDictionaryInfo ); connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - QString toolTipStr = "\"" + tabText( x ) + "\"\n" + tr( "Dictionaries: " ) - + QString::number( getModelAt( x )->getCurrentDictionaries().size() ); + QString toolTipStr = + "\"" + tabText( x ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( x ) ); setTabToolTip( x, toolTipStr ); } @@ -617,13 +617,31 @@ DictListModel * DictGroupsWidget::getCurrentModel() const DictListModel * DictGroupsWidget::getModelAt( int current ) const { if ( current >= 0 && current < count() ) { - const auto w = (DictGroupWidget *)widget( current ); + const auto w = static_cast< DictGroupWidget * >( widget( current ) ); + if ( !w ) + return nullptr; return w->getModel(); } return nullptr; } +int DictGroupsWidget::getDictionaryCountAt( int current ) const +{ + const auto model = getModelAt( current ); + if ( !model ) + return 0; + return model->getCurrentDictionaries().size(); +} + +std::vector< sptr< Dictionary::Class > > DictGroupsWidget::getDictionaryAt( int current ) const +{ + const auto model = getModelAt( current ); + if ( !model ) + return {}; + return model->getCurrentDictionaries(); +} + QItemSelectionModel * DictGroupsWidget::getCurrentSelectionModel() const { const int current = currentIndex(); @@ -653,8 +671,8 @@ int DictGroupsWidget::addNewGroup( QString const & name ) connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); - const QString toolTipStr = "\"" + tabText( idx ) + "\"\n" + tr( "Dictionaries: " ) - + QString::number( getModelAt( idx )->getCurrentDictionaries().size() ); + const QString toolTipStr = + "\"" + tabText( idx ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( idx ) ); setTabToolTip( idx, toolTipStr ); return idx; } @@ -746,6 +764,8 @@ void DictGroupsWidget::addAutoGroups() // add dictionaries into the current group QVector< sptr< Dictionary::Class > > vd = dictMap[ gr ]; DictListModel * model = getModelAt( idx ); + if ( !model ) + continue; for( int i = 0; i < vd.count(); i++ ) model->addRow(QModelIndex(), vd.at( i ) ); } @@ -850,6 +870,9 @@ void DictGroupsWidget::addGroupBasedOnMap( const QMultiMapaddRow( QModelIndex(), dict ); } @@ -939,10 +962,13 @@ void DictGroupsWidget::combineGroups( int source, int target ) if( source < 0 || source >= count() || target < 0 || target >= count() ) return; - vector< sptr< Dictionary::Class > > const & dicts = getModelAt( source )->getCurrentDictionaries(); + vector< sptr< Dictionary::Class > > const & dicts = getDictionaryAt( source ); const auto model = getModelAt( target ); + if ( !model ) + return; + disconnect( model, &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged ); for ( const auto & dict : dicts ) { diff --git a/src/ui/groups_widgets.hh b/src/ui/groups_widgets.hh index f3729ed0..176f4e2e 100644 --- a/src/ui/groups_widgets.hh +++ b/src/ui/groups_widgets.hh @@ -193,6 +193,8 @@ public: DictListModel * getCurrentModel() const; DictListModel * getModelAt( int current ) const; + int getDictionaryCountAt( int current ) const; + std::vector< sptr< Dictionary::Class > > getDictionaryAt( int current ) const; QItemSelectionModel * getCurrentSelectionModel() const;