mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Make the default history item length to be the same as the limit for the headwords.
So, it is 256 now. And configurable via the same parameter in the config file: maxHeadwordSize.
This commit is contained in:
parent
eefd6a57b1
commit
4d5665d816
10
history.cc
10
history.cc
|
@ -7,13 +7,13 @@
|
|||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
History::History( unsigned size ): maxSize( size ),
|
||||
addingEnabled( true )
|
||||
History::History( unsigned size, unsigned maxItemLength_ ): maxSize( size ),
|
||||
maxItemLength( maxItemLength_ ), addingEnabled( true )
|
||||
{
|
||||
}
|
||||
|
||||
History::History( Load, unsigned size ): maxSize( size ),
|
||||
addingEnabled( true )
|
||||
History::History( Load, unsigned size, unsigned maxItemLength_ ): maxSize( size ),
|
||||
maxItemLength( maxItemLength_ ), addingEnabled( true )
|
||||
{
|
||||
QFile file( Config::getHistoryFileName() );
|
||||
|
||||
|
@ -64,7 +64,7 @@ void History::addItem( Item const & item )
|
|||
if( !enabled() )
|
||||
return;
|
||||
|
||||
if ( item.word.size() > MAX_HISTORY_ITEM_LENGTH || item.word.isEmpty() )
|
||||
if ( (unsigned)item.word.size() > getMaxItemLength() || item.word.isEmpty() )
|
||||
{
|
||||
// The search looks bogus. Don't save it.
|
||||
return;
|
||||
|
|
10
history.hh
10
history.hh
|
@ -8,7 +8,7 @@
|
|||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#define MAX_HISTORY_ITEM_LENGTH 60
|
||||
#define DEFAULT_MAX_HISTORY_ITEM_LENGTH 256
|
||||
|
||||
/// Search history
|
||||
class History: public QObject
|
||||
|
@ -43,11 +43,11 @@ public:
|
|||
struct Load {};
|
||||
|
||||
/// Constructs an empty history which can hold at most "size" items.
|
||||
History( unsigned size = 20 );
|
||||
History( unsigned size = 20 , unsigned maxItemLength = DEFAULT_MAX_HISTORY_ITEM_LENGTH );
|
||||
|
||||
/// Loads history from its file. If load fails, the result would be an empty
|
||||
/// history. The size parameter is same as in other constructor.
|
||||
History( Load, unsigned size = 20 );
|
||||
History( Load, unsigned size = 20, unsigned maxItemLength = DEFAULT_MAX_HISTORY_ITEM_LENGTH );
|
||||
|
||||
/// Adds new item. The item is always added at the beginning of the list.
|
||||
/// If there was such an item already somewhere on the list, it gets removed
|
||||
|
@ -86,6 +86,9 @@ public:
|
|||
unsigned getMaxSize()
|
||||
{ return maxSize; }
|
||||
|
||||
unsigned getMaxItemLength() const
|
||||
{ return maxItemLength; }
|
||||
|
||||
signals:
|
||||
|
||||
/// Signals the changes in items in response to addItem() or clear().
|
||||
|
@ -99,6 +102,7 @@ private:
|
|||
|
||||
QList< Item > items;
|
||||
unsigned maxSize;
|
||||
unsigned maxItemLength;
|
||||
bool addingEnabled;
|
||||
|
||||
};
|
||||
|
|
|
@ -239,7 +239,7 @@ QVariant HistoryModel::data( QModelIndex const & index, int role ) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
if ( role == Qt::DisplayRole )
|
||||
if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
|
||||
{
|
||||
return m_history->getItem( index.row() ).word;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
trayIconMenu( this ),
|
||||
addTab( this ),
|
||||
cfg( cfg_ ),
|
||||
history( History::Load(), cfg_.preferences.maxStringsInHistory ),
|
||||
history( History::Load(), cfg_.preferences.maxStringsInHistory, cfg_.maxHeadwordSize ),
|
||||
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ),
|
||||
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle,
|
||||
cfg.preferences.addonStyle ),
|
||||
|
@ -3151,7 +3151,7 @@ void MainWindow::on_importHistory_triggered()
|
|||
if( trimmedStr.isEmpty() )
|
||||
continue;
|
||||
|
||||
if( trimmedStr.size() <= MAX_HISTORY_ITEM_LENGTH )
|
||||
if( (unsigned)trimmedStr.size() <= history.getMaxItemLength( ) )
|
||||
itemList.prepend( trimmedStr );
|
||||
|
||||
} while( !fileStream.atEnd() && itemList.size() < (int)history.getMaxSize() );
|
||||
|
|
Loading…
Reference in a new issue