Commit
Added a customommand provider.
- Loading branch information
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -32,6 +32,7 @@ | ||
#include <QtCore/QFileInfo> | #include <QtCore/QFileInfo> | ||
#include <QtCore/QProcess> | #include <QtCore/QProcess> | ||
#include <QtCore/QDebug> | #include <QtCore/QDebug> | ||
#include <limits.h> | |||
|
|
||
|
|
||
/************************************************ | /************************************************ | ||
|
@@ -110,6 +111,12 @@ bool CommandItemModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sour | ||
************************************************/ | ************************************************/ | ||
bool CommandItemModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | bool CommandItemModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||
{ | { | ||
if (left == mSourceModel->customCommandIndex()) | |||
return true; | |||
|
|||
if (right == mSourceModel->customCommandIndex()) | |||
return false; | |||
|
|||
if (mOnlyHistory) | if (mOnlyHistory) | ||
return left.row() < right.row(); | return left.row() < right.row(); | ||
else | else | ||
|
@@ -123,25 +130,29 @@ bool CommandItemModel::lessThan(const QModelIndex &left, const QModelIndex &righ | ||
QModelIndex CommandItemModel::appropriateItem(const QString &pattern) const | QModelIndex CommandItemModel::appropriateItem(const QString &pattern) const | ||
{ | { | ||
QModelIndex res; | QModelIndex res; | ||
int delta = 0xFFFF; | unsigned int rank = 0; | ||
|
|
||
int cnt = rowCount(); | int cnt = rowCount(); | ||
|
|||
for (int i=0; i<cnt; ++i) | for (int i=0; i<cnt; ++i) | ||
{ | { | ||
QModelIndex ind = index(i,0); | QModelIndex ind = index(i,0); | ||
QModelIndex srcIndex = mapToSource(ind); | QModelIndex srcIndex = mapToSource(ind); | ||
if (srcIndex == mSourceModel->customCommandIndex()) | |||
continue; | |||
|
|||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SokoloffA
Author
Member
|
|||
const CommandProviderItem *item = mSourceModel->command(srcIndex); | const CommandProviderItem *item = mSourceModel->command(srcIndex); | ||
if (!item) | if (!item) | ||
continue; | continue; | ||
|
|
||
int d = item->tile().indexOf(pattern, 0, Qt::CaseInsensitive); | unsigned int r = item->rank(pattern); | ||
if (d<delta) | if (r > rank) | ||
{ | { | ||
res = ind; | res = ind; | ||
delta = d; | rank = r; | ||
} | } | ||
|
|
||
if (delta==0) | if (rank >= MAX_RANK) | ||
break; | break; | ||
} | } | ||
|
|
||
|
@@ -169,8 +180,14 @@ void CommandItemModel::rebuild() | ||
CommandSourceItemModel::CommandSourceItemModel(QObject *parent) : | CommandSourceItemModel::CommandSourceItemModel(QObject *parent) : | ||
QAbstractListModel(parent) | QAbstractListModel(parent) | ||
{ | { | ||
mCustomCommandProvider = new CustomCommandProvider; | |||
mProviders.append(mCustomCommandProvider); | |||
rebuild(); | |||
mCustomCommandIndex = index(0, 0); | |||
|
|||
mHistoryProvider = new HistoryProvider(); | mHistoryProvider = new HistoryProvider(); | ||
mProviders.append(mHistoryProvider); | mProviders.append(mHistoryProvider); | ||
|
|||
mProviders.append(new AppLinkProvider()); | mProviders.append(new AppLinkProvider()); | ||
#ifdef MATH_ENABLED | #ifdef MATH_ENABLED | ||
mProviders.append(new MathProvider()); | mProviders.append(new MathProvider()); | ||
|
@@ -230,7 +247,7 @@ QVariant CommandSourceItemModel::data(const QModelIndex &index, int role) const | ||
switch (role) | switch (role) | ||
{ | { | ||
case Qt::DisplayRole: | case Qt::DisplayRole: | ||
return QString("<b>%1</b><br>\n%2\n").arg(item->tile(), item->comment()); | return QString("<b>%1</b><br>\n%2\n").arg(item->title(), item->comment()); | ||
|
|
||
case Qt::DecorationRole: | case Qt::DecorationRole: | ||
return item->icon(); | return item->icon(); | ||
|
Is the "continue" intentional? I would "return ind" here, so that it selects the matching command.