mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
fix: group widget null check
This commit is contained in:
parent
2359352781
commit
43c2cfdd65
|
@ -5,6 +5,7 @@
|
||||||
#include "config.hh"
|
#include "config.hh"
|
||||||
#include <QTextToSpeech>
|
#include <QTextToSpeech>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
class SpeechClient: public QObject
|
class SpeechClient: public QObject
|
||||||
{
|
{
|
||||||
|
@ -40,7 +41,7 @@ public:
|
||||||
sp( std::make_unique< QTextToSpeech >( e.engine_name ) ),
|
sp( std::make_unique< QTextToSpeech >( e.engine_name ) ),
|
||||||
engine( e )
|
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 ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||||
if ( !sp || sp->state() == QTextToSpeech::Error )
|
if ( !sp || sp->state() == QTextToSpeech::Error )
|
||||||
return;
|
return;
|
||||||
|
@ -75,10 +76,6 @@ public:
|
||||||
bool tell( QString const & text, int volume, int rate ) const;
|
bool tell( QString const & text, int volume, int rate ) const;
|
||||||
bool tell( QString const & text ) const;
|
bool tell( QString const & text ) const;
|
||||||
|
|
||||||
signals:
|
|
||||||
void started( bool ok );
|
|
||||||
void finished();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr< InternalData > internalData;
|
std::unique_ptr< InternalData > internalData;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,18 +32,18 @@ EditDictionaries::EditDictionaries( QWidget * parent,
|
||||||
// the initial group readings so that if no edits were really done, we won't
|
// the initial group readings so that if no edits were really done, we won't
|
||||||
// be changing groups.
|
// be changing groups.
|
||||||
origCfg.groups = groups->getGroups();
|
origCfg.groups = groups->getGroups();
|
||||||
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
|
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
|
||||||
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
|
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
|
||||||
|
|
||||||
ui.setupUi( this );
|
ui.setupUi( this );
|
||||||
|
|
||||||
setWindowIcon( QIcon(":/icons/dictionary.svg") );
|
setWindowIcon( QIcon( ":/icons/dictionary.svg" ) );
|
||||||
|
|
||||||
ui.tabs->clear();
|
ui.tabs->clear();
|
||||||
|
|
||||||
ui.tabs->addTab( &sources, QIcon(":/icons/sources.png"), tr( "&Sources" ) );
|
ui.tabs->addTab( &sources, QIcon( ":/icons/sources.png" ), tr( "&Sources" ) );
|
||||||
ui.tabs->addTab( orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
ui.tabs->addTab( orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
||||||
ui.tabs->addTab( groups.get(), QIcon(":/icons/bookcase.svg"), tr( "&Groups" ) );
|
ui.tabs->addTab( groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) );
|
||||||
|
|
||||||
connect( ui.buttons, &QDialogButtonBox::clicked, this, &EditDictionaries::buttonBoxClicked );
|
connect( ui.buttons, &QDialogButtonBox::clicked, this, &EditDictionaries::buttonBoxClicked );
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ EditDictionaries::EditDictionaries( QWidget * parent,
|
||||||
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
||||||
|
|
||||||
connect( &helpAction, &QAction::triggered, [ this ]() {
|
connect( &helpAction, &QAction::triggered, [ this ]() {
|
||||||
if ( ui.tabs->currentWidget() == this->groups.get() ) {
|
if ( ui.tabs->currentWidget() == this->groups ) {
|
||||||
Help::openHelpWebpage( Help::section::manage_groups );
|
Help::openHelpWebpage( Help::section::manage_groups );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -240,8 +240,8 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
||||||
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries );
|
orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries );
|
||||||
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
||||||
|
|
||||||
ui.tabs->insertTab( 1, orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
ui.tabs->insertTab( 1, orderAndProps, QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
||||||
ui.tabs->insertTab( 2, groups.get(), QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) );
|
ui.tabs->insertTab( 2, groups, QIcon( ":/icons/bookcase.svg" ), tr( "&Groups" ) );
|
||||||
connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo );
|
connect( groups, &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo );
|
||||||
connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords );
|
connect( orderAndProps, &OrderAndProps::showDictionaryHeadwords, this, &EditDictionaries::showDictionaryHeadwords );
|
||||||
|
|
||||||
|
|
|
@ -575,8 +575,8 @@ void DictGroupsWidget::populate( Config::Groups const & groups,
|
||||||
connect( gr, &DictGroupWidget::showDictionaryInfo,this, &DictGroupsWidget::showDictionaryInfo );
|
connect( gr, &DictGroupWidget::showDictionaryInfo,this, &DictGroupsWidget::showDictionaryInfo );
|
||||||
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
||||||
|
|
||||||
QString toolTipStr = "\"" + tabText( x ) + "\"\n" + tr( "Dictionaries: " )
|
QString toolTipStr =
|
||||||
+ QString::number( getModelAt( x )->getCurrentDictionaries().size() );
|
"\"" + tabText( x ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( x ) );
|
||||||
setTabToolTip( x, toolTipStr );
|
setTabToolTip( x, toolTipStr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,13 +617,31 @@ DictListModel * DictGroupsWidget::getCurrentModel() const
|
||||||
DictListModel * DictGroupsWidget::getModelAt( int current ) const
|
DictListModel * DictGroupsWidget::getModelAt( int current ) const
|
||||||
{
|
{
|
||||||
if ( current >= 0 && current < count() ) {
|
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 w->getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
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
|
QItemSelectionModel * DictGroupsWidget::getCurrentSelectionModel() const
|
||||||
{
|
{
|
||||||
const int current = currentIndex();
|
const int current = currentIndex();
|
||||||
|
@ -653,8 +671,8 @@ int DictGroupsWidget::addNewGroup( QString const & name )
|
||||||
|
|
||||||
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
||||||
|
|
||||||
const QString toolTipStr = "\"" + tabText( idx ) + "\"\n" + tr( "Dictionaries: " )
|
const QString toolTipStr =
|
||||||
+ QString::number( getModelAt( idx )->getCurrentDictionaries().size() );
|
"\"" + tabText( idx ) + "\"\n" + tr( "Dictionaries: " ) + QString::number( getDictionaryCountAt( idx ) );
|
||||||
setTabToolTip( idx, toolTipStr );
|
setTabToolTip( idx, toolTipStr );
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
@ -746,6 +764,8 @@ void DictGroupsWidget::addAutoGroups()
|
||||||
// add dictionaries into the current group
|
// add dictionaries into the current group
|
||||||
QVector< sptr< Dictionary::Class > > vd = dictMap[ gr ];
|
QVector< sptr< Dictionary::Class > > vd = dictMap[ gr ];
|
||||||
DictListModel * model = getModelAt( idx );
|
DictListModel * model = getModelAt( idx );
|
||||||
|
if ( !model )
|
||||||
|
continue;
|
||||||
for( int i = 0; i < vd.count(); i++ )
|
for( int i = 0; i < vd.count(); i++ )
|
||||||
model->addRow(QModelIndex(), vd.at( i ) );
|
model->addRow(QModelIndex(), vd.at( i ) );
|
||||||
}
|
}
|
||||||
|
@ -850,6 +870,9 @@ void DictGroupsWidget::addGroupBasedOnMap( const QMultiMap<QString, sptr<Diction
|
||||||
const auto idx = addUniqueGroup( group );
|
const auto idx = addUniqueGroup( group );
|
||||||
DictListModel * model = getModelAt( idx );
|
DictListModel * model = getModelAt( idx );
|
||||||
|
|
||||||
|
if ( !model ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for ( const auto & dict : groupToDicts.values( group ) ) {
|
for ( const auto & dict : groupToDicts.values( group ) ) {
|
||||||
model->addRow( QModelIndex(), dict );
|
model->addRow( QModelIndex(), dict );
|
||||||
}
|
}
|
||||||
|
@ -939,10 +962,13 @@ void DictGroupsWidget::combineGroups( int source, int target )
|
||||||
if( source < 0 || source >= count() || target < 0 || target >= count() )
|
if( source < 0 || source >= count() || target < 0 || target >= count() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vector< sptr< Dictionary::Class > > const & dicts = getModelAt( source )->getCurrentDictionaries();
|
vector< sptr< Dictionary::Class > > const & dicts = getDictionaryAt( source );
|
||||||
|
|
||||||
const auto model = getModelAt( target );
|
const auto model = getModelAt( target );
|
||||||
|
|
||||||
|
if ( !model )
|
||||||
|
return;
|
||||||
|
|
||||||
disconnect( model, &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
disconnect( model, &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
||||||
|
|
||||||
for ( const auto & dict : dicts ) {
|
for ( const auto & dict : dicts ) {
|
||||||
|
|
|
@ -193,6 +193,8 @@ public:
|
||||||
DictListModel * getCurrentModel() const;
|
DictListModel * getCurrentModel() const;
|
||||||
|
|
||||||
DictListModel * getModelAt( int current ) const;
|
DictListModel * getModelAt( int current ) const;
|
||||||
|
int getDictionaryCountAt( int current ) const;
|
||||||
|
std::vector< sptr< Dictionary::Class > > getDictionaryAt( int current ) const;
|
||||||
|
|
||||||
QItemSelectionModel * getCurrentSelectionModel() const;
|
QItemSelectionModel * getCurrentSelectionModel() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue