Improved part search filter.

This commit is contained in:
Leonardo 2016-12-16 12:52:36 -08:00
parent eb1bc1cd31
commit 1ef60b8ddf
4 changed files with 30 additions and 19 deletions

View file

@ -319,7 +319,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
if (ShowWindow)
QMessageBox::information(gMainWindow, tr("LeoCAD"), Message);
else
fprintf(stderr, Message.toLatin1().constData());
fprintf(stderr, "%s", Message.toLatin1().constData());
}
gMainWindow->CreateWidgets();

View file

@ -157,7 +157,7 @@ public:
return mRelativeTransform;
}
PieceInfo* lcMainWindow::GetCurrentPieceInfo() const
PieceInfo* GetCurrentPieceInfo() const
{
return mCurrentPieceInfo;
}

View file

@ -24,18 +24,37 @@ void lcPartSelectionFilterModel::SetFilter(const QString& Filter)
bool lcPartSelectionFilterModel::filterAcceptsRow(int SourceRow, const QModelIndex& SourceParent) const
{
Q_UNUSED(SourceParent);
if (mFilter.isEmpty())
return true;
lcPartSelectionListModel* SourceModel = (lcPartSelectionListModel*)sourceModel();
PieceInfo* Info = SourceModel->GetPieceInfo(SourceRow);
return strstr(Info->m_strDescription, mFilter);
char Description[sizeof(Info->m_strDescription)];
char* Src = Info->m_strDescription;
char* Dst = Description;
for (;;)
{
*Dst = *Src;
if (*Src == ' ' && *(Src + 1) == ' ')
Src++;
else if (*Src == 0)
break;
Src++;
Dst++;
}
return strcasestr(Description, mFilter) || strcasestr(Info->m_strName, mFilter);
}
void lcPartSelectionItemDelegate::paint(QPainter* Painter, const QStyleOptionViewItem& Option, const QModelIndex& Index) const
{
mListModel->RequestPreview(mFilterModel->mapToSource(Index).row());
mListModel->DrawPreview(mFilterModel->mapToSource(Index).row());
QStyledItemDelegate::paint(Painter, Option, Index);
}
@ -49,10 +68,6 @@ lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
{
}
lcPartSelectionListModel::~lcPartSelectionListModel()
{
}
void lcPartSelectionListModel::SetCategory(int CategoryIndex)
{
beginResetModel();
@ -84,7 +99,10 @@ QVariant lcPartSelectionListModel::data(const QModelIndex& Index, int Role) cons
if (Index.isValid() && InfoIndex < mParts.size())
{
if (Role == Qt::ToolTipRole)
return QVariant(QString::fromLatin1(mParts[InfoIndex].first->m_strDescription));
{
PieceInfo* Info = mParts[InfoIndex].first;
return QVariant(QString("%1 (%2)").arg(QString::fromLatin1(Info->m_strDescription), QString::fromLatin1(Info->m_strName)));
}
else if (Role == Qt::DecorationRole)
{
if (!mParts[InfoIndex].second.isNull())
@ -114,11 +132,10 @@ Qt::ItemFlags lcPartSelectionListModel::flags(const QModelIndex& Index) const
return DefaultFlags;
}
#include "lc_mainwindow.h"
#include "preview.h"
void lcPartSelectionListModel::RequestPreview(int InfoIndex)
void lcPartSelectionListModel::DrawPreview(int InfoIndex)
{
if (mParts[InfoIndex].second.isNull())
{
@ -251,10 +268,6 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
connect(mCategoriesWidget, &QTreeWidget::currentItemChanged, this, &lcPartSelectionWidget::CategoryChanged);
}
lcPartSelectionWidget::~lcPartSelectionWidget()
{
}
void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event)
{
if (width() > height())
@ -280,4 +293,4 @@ void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidge
void lcPartSelectionWidget::PartChanged(const QModelIndex& Current, const QModelIndex& Previous)
{
gMainWindow->SetCurrentPieceInfo(mPartsWidget->GetCurrentPart());
}
}

View file

@ -42,7 +42,6 @@ class lcPartSelectionListModel : public QAbstractListModel
public:
lcPartSelectionListModel(QObject* Parent);
~lcPartSelectionListModel();
virtual int rowCount(const QModelIndex& Parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& Index, int Role = Qt::DisplayRole) const;
@ -60,7 +59,7 @@ public:
}
void SetCategory(int CategoryIndex);
void RequestPreview(int InfoIndex);
void DrawPreview(int InfoIndex);
protected:
QVector<QPair<PieceInfo*, QPixmap>> mParts;
@ -103,7 +102,6 @@ class lcPartSelectionWidget : public QWidget
public:
lcPartSelectionWidget(QWidget* Parent);
~lcPartSelectionWidget();
protected slots:
void FilterChanged(const QString& Text);