Normalize line endings

This commit is contained in:
isaak654 2021-10-15 17:04:52 +02:00
parent 7e380b8c94
commit 39a431e007
No known key found for this signature in database
GPG Key ID: 59D402040437EC44
11 changed files with 10580 additions and 10580 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,164 +1,164 @@
#include "stdafx.h" #include "stdafx.h"
#include "Finder.h" #include "Finder.h"
bool CFinder::m_DarkMode = false; bool CFinder::m_DarkMode = false;
QWidget* CFinder::AddFinder(QWidget* pList, QObject* pFilterTarget, bool HighLightOption, CFinder** ppFinder) QWidget* CFinder::AddFinder(QWidget* pList, QObject* pFilterTarget, bool HighLightOption, CFinder** ppFinder)
{ {
QWidget* pWidget = new QWidget(); QWidget* pWidget = new QWidget();
QVBoxLayout* pLayout = new QVBoxLayout(); QVBoxLayout* pLayout = new QVBoxLayout();
pLayout->setMargin(0); pLayout->setMargin(0);
pWidget->setLayout(pLayout); pWidget->setLayout(pLayout);
pLayout->addWidget(pList); pLayout->addWidget(pList);
CFinder* pFinder = new CFinder(pFilterTarget, pWidget, HighLightOption); CFinder* pFinder = new CFinder(pFilterTarget, pWidget, HighLightOption);
pLayout->addWidget(pFinder); pLayout->addWidget(pFinder);
if (ppFinder) if (ppFinder)
*ppFinder = pFinder; *ppFinder = pFinder;
return pWidget; return pWidget;
} }
CFinder::CFinder(QObject* pFilterTarget, QWidget *parent, bool HighLightOption) CFinder::CFinder(QObject* pFilterTarget, QWidget *parent, bool HighLightOption)
:QWidget(parent) :QWidget(parent)
{ {
m_pSearchLayout = new QHBoxLayout(); m_pSearchLayout = new QHBoxLayout();
m_pSearchLayout->setMargin(0); m_pSearchLayout->setMargin(0);
m_pSearchLayout->setSpacing(3); m_pSearchLayout->setSpacing(3);
m_pSearchLayout->setAlignment(Qt::AlignLeft); m_pSearchLayout->setAlignment(Qt::AlignLeft);
m_pSearch = new QLineEdit(); m_pSearch = new QLineEdit();
m_pSearch->setMinimumWidth(150); m_pSearch->setMinimumWidth(150);
m_pSearch->setMaximumWidth(350); m_pSearch->setMaximumWidth(350);
m_pSearchLayout->addWidget(m_pSearch); m_pSearchLayout->addWidget(m_pSearch);
QObject::connect(m_pSearch, SIGNAL(textChanged(QString)), this, SLOT(OnText())); QObject::connect(m_pSearch, SIGNAL(textChanged(QString)), this, SLOT(OnText()));
QObject::connect(m_pSearch, SIGNAL(returnPressed()), this, SLOT(OnReturn())); QObject::connect(m_pSearch, SIGNAL(returnPressed()), this, SLOT(OnReturn()));
m_pCaseSensitive = new QCheckBox(tr("Case Sensitive")); m_pCaseSensitive = new QCheckBox(tr("Case Sensitive"));
m_pSearchLayout->addWidget(m_pCaseSensitive); m_pSearchLayout->addWidget(m_pCaseSensitive);
connect(m_pCaseSensitive, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate())); connect(m_pCaseSensitive, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate()));
m_pRegExp = new QCheckBox(tr("RegExp")); m_pRegExp = new QCheckBox(tr("RegExp"));
m_pSearchLayout->addWidget(m_pRegExp); m_pSearchLayout->addWidget(m_pRegExp);
connect(m_pRegExp, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate())); connect(m_pRegExp, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate()));
m_pColumn = new QComboBox(); m_pColumn = new QComboBox();
m_pSearchLayout->addWidget(m_pColumn); m_pSearchLayout->addWidget(m_pColumn);
connect(m_pColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(OnUpdate())); connect(m_pColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(OnUpdate()));
m_pColumn->setVisible(false); m_pColumn->setVisible(false);
if (HighLightOption) if (HighLightOption)
{ {
m_pHighLight = new QCheckBox(tr("Highlight")); m_pHighLight = new QCheckBox(tr("Highlight"));
//m_pHighLight->setChecked(true); //m_pHighLight->setChecked(true);
m_pSearchLayout->addWidget(m_pHighLight); m_pSearchLayout->addWidget(m_pHighLight);
connect(m_pHighLight, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate())); connect(m_pHighLight, SIGNAL(stateChanged(int)), this, SLOT(OnUpdate()));
} }
else else
m_pHighLight = NULL; m_pHighLight = NULL;
QToolButton* pClose = new QToolButton(this); QToolButton* pClose = new QToolButton(this);
pClose->setIcon(QIcon(":/close.png")); pClose->setIcon(QIcon(":/close.png"));
pClose->setAutoRaise(true); pClose->setAutoRaise(true);
pClose->setText(tr("Close")); pClose->setText(tr("Close"));
m_pSearchLayout->addWidget(pClose); m_pSearchLayout->addWidget(pClose);
QObject::connect(pClose, SIGNAL(clicked()), this, SLOT(Close())); QObject::connect(pClose, SIGNAL(clicked()), this, SLOT(Close()));
QWidget* pSpacer = new QWidget(); QWidget* pSpacer = new QWidget();
pSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); pSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_pSearchLayout->addWidget(pSpacer); m_pSearchLayout->addWidget(pSpacer);
setLayout(m_pSearchLayout); setLayout(m_pSearchLayout);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
//setMaximumHeight(30); //setMaximumHeight(30);
hide(); hide();
if (parent) if (parent)
{ {
QAction* pFind = new QAction(tr("&Find ..."), parent); QAction* pFind = new QAction(tr("&Find ..."), parent);
pFind->setShortcut(QKeySequence::Find); pFind->setShortcut(QKeySequence::Find);
pFind->setShortcutContext(Qt::WidgetWithChildrenShortcut); pFind->setShortcutContext(Qt::WidgetWithChildrenShortcut);
parent->addAction(pFind); parent->addAction(pFind);
QObject::connect(pFind, SIGNAL(triggered()), this, SLOT(Open())); QObject::connect(pFind, SIGNAL(triggered()), this, SLOT(Open()));
} }
m_pSortProxy = qobject_cast<QSortFilterProxyModel*>(pFilterTarget); m_pSortProxy = qobject_cast<QSortFilterProxyModel*>(pFilterTarget);
if (pFilterTarget) { if (pFilterTarget) {
QObject::connect(this, SIGNAL(SetFilter(const QRegExp&, bool, int)), pFilterTarget, SLOT(SetFilter(const QRegExp&, bool, int))); QObject::connect(this, SIGNAL(SetFilter(const QRegExp&, bool, int)), pFilterTarget, SLOT(SetFilter(const QRegExp&, bool, int)));
QObject::connect(this, SIGNAL(SelectNext()), pFilterTarget, SLOT(SelectNext())); QObject::connect(this, SIGNAL(SelectNext()), pFilterTarget, SLOT(SelectNext()));
} }
m_pTimer = new QTimer(this); m_pTimer = new QTimer(this);
m_pTimer->setSingleShot(true); m_pTimer->setSingleShot(true);
m_pTimer->setInterval(500); m_pTimer->setInterval(500);
connect(m_pTimer, SIGNAL(timeout()), SLOT(OnUpdate())); connect(m_pTimer, SIGNAL(timeout()), SLOT(OnUpdate()));
this->installEventFilter(this); this->installEventFilter(this);
} }
CFinder::~CFinder() CFinder::~CFinder()
{ {
} }
bool CFinder::eventFilter(QObject* source, QEvent* event) bool CFinder::eventFilter(QObject* source, QEvent* event)
{ {
if (event->type() == QEvent::KeyPress && ((QKeyEvent*)event)->key() == Qt::Key_Escape if (event->type() == QEvent::KeyPress && ((QKeyEvent*)event)->key() == Qt::Key_Escape
&& ((QKeyEvent*)event)->modifiers() == Qt::NoModifier) && ((QKeyEvent*)event)->modifiers() == Qt::NoModifier)
{ {
Close(); Close();
return true; // cancel event return true; // cancel event
} }
return QWidget::eventFilter(source, event); return QWidget::eventFilter(source, event);
} }
void CFinder::Open() void CFinder::Open()
{ {
if (m_pSortProxy && m_pColumn->count() == 0) if (m_pSortProxy && m_pColumn->count() == 0)
{ {
m_pColumn->addItem(tr("All columns"), -1); m_pColumn->addItem(tr("All columns"), -1);
for (int i = 0; i < m_pSortProxy->columnCount(); i++) for (int i = 0; i < m_pSortProxy->columnCount(); i++)
m_pColumn->addItem(m_pSortProxy->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(), i); m_pColumn->addItem(m_pSortProxy->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(), i);
m_pColumn->setVisible(true); m_pColumn->setVisible(true);
} }
show(); show();
m_pSearch->setFocus(Qt::OtherFocusReason); m_pSearch->setFocus(Qt::OtherFocusReason);
m_pSearch->selectAll(); m_pSearch->selectAll();
OnUpdate(); OnUpdate();
} }
QRegExp CFinder::GetRegExp() const QRegExp CFinder::GetRegExp() const
{ {
if (!isVisible()) if (!isVisible())
return QRegExp(); return QRegExp();
return QRegExp(m_pSearch->text(), m_pCaseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, m_pRegExp->isChecked() ? QRegExp::RegExp : QRegExp::FixedString); return QRegExp(m_pSearch->text(), m_pCaseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, m_pRegExp->isChecked() ? QRegExp::RegExp : QRegExp::FixedString);
} }
void CFinder::OnUpdate() void CFinder::OnUpdate()
{ {
m_pTimer->stop(); m_pTimer->stop();
emit SetFilter(GetRegExp(), GetHighLight(), GetColumn()); emit SetFilter(GetRegExp(), GetHighLight(), GetColumn());
} }
void CFinder::OnText() void CFinder::OnText()
{ {
m_pTimer->stop(); m_pTimer->stop();
m_pTimer->start(); m_pTimer->start();
} }
void CFinder::OnReturn() void CFinder::OnReturn()
{ {
OnUpdate(); OnUpdate();
if (m_pHighLight->isChecked()) if (m_pHighLight->isChecked())
emit SelectNext(); emit SelectNext();
} }
void CFinder::Close() void CFinder::Close()
{ {
emit SetFilter(QRegExp()); emit SetFilter(QRegExp());
hide(); hide();
} }

View File

@ -1,53 +1,53 @@
#pragma once #pragma once
#include "../mischelpers_global.h" #include "../mischelpers_global.h"
class MISCHELPERS_EXPORT CFinder: public QWidget class MISCHELPERS_EXPORT CFinder: public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
CFinder(QObject* pFilterTarget, QWidget *parent = NULL, bool HighLightOption = true); CFinder(QObject* pFilterTarget, QWidget *parent = NULL, bool HighLightOption = true);
~CFinder(); ~CFinder();
static void SetDarkMode(bool bDarkMode) { m_DarkMode = bDarkMode; } static void SetDarkMode(bool bDarkMode) { m_DarkMode = bDarkMode; }
static bool GetDarkMode() { return m_DarkMode; } static bool GetDarkMode() { return m_DarkMode; }
static QWidget* AddFinder(QWidget* pList, QObject* pFilterTarget, bool HighLightOption = true, CFinder** ppFinder = NULL); static QWidget* AddFinder(QWidget* pList, QObject* pFilterTarget, bool HighLightOption = true, CFinder** ppFinder = NULL);
QRegExp GetRegExp() const; QRegExp GetRegExp() const;
bool GetHighLight() const { return m_pHighLight ? m_pHighLight->isChecked() : false; } bool GetHighLight() const { return m_pHighLight ? m_pHighLight->isChecked() : false; }
int GetColumn() const { return m_pColumn->currentData().toInt(); } int GetColumn() const { return m_pColumn->currentData().toInt(); }
signals: signals:
void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Column = -1); void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Column = -1);
void SelectNext(); void SelectNext();
public slots: public slots:
void Open(); void Open();
void Close(); void Close();
private slots: private slots:
void OnUpdate(); void OnUpdate();
void OnText(); void OnText();
void OnReturn(); void OnReturn();
protected: protected:
bool eventFilter(QObject* source, QEvent* event); bool eventFilter(QObject* source, QEvent* event);
private: private:
QHBoxLayout* m_pSearchLayout; QHBoxLayout* m_pSearchLayout;
QLineEdit* m_pSearch; QLineEdit* m_pSearch;
QCheckBox* m_pCaseSensitive; QCheckBox* m_pCaseSensitive;
QCheckBox* m_pRegExp; QCheckBox* m_pRegExp;
QComboBox* m_pColumn; QComboBox* m_pColumn;
QCheckBox* m_pHighLight; QCheckBox* m_pHighLight;
QSortFilterProxyModel* m_pSortProxy; QSortFilterProxyModel* m_pSortProxy;
QTimer* m_pTimer; QTimer* m_pTimer;
static bool m_DarkMode; static bool m_DarkMode;
}; };

View File

@ -1,226 +1,226 @@
#include "stdafx.h" #include "stdafx.h"
#include "PanelView.h" #include "PanelView.h"
bool CPanelView::m_SimpleFormat = false; bool CPanelView::m_SimpleFormat = false;
bool CPanelView::m_DarkMode = false; bool CPanelView::m_DarkMode = false;
int CPanelView::m_MaxCellWidth = 0; int CPanelView::m_MaxCellWidth = 0;
QString CPanelView::m_CellSeparator = "\t"; QString CPanelView::m_CellSeparator = "\t";
QString CPanelView::m_CopyCell = "Copy Cell"; QString CPanelView::m_CopyCell = "Copy Cell";
QString CPanelView::m_CopyRow = "Copy Row"; QString CPanelView::m_CopyRow = "Copy Row";
QString CPanelView::m_CopyPanel = "Copy Panel"; QString CPanelView::m_CopyPanel = "Copy Panel";
CPanelView::CPanelView(QWidget *parent) CPanelView::CPanelView(QWidget *parent)
:QWidget(parent) :QWidget(parent)
{ {
//m_CopyAll = false; //m_CopyAll = false;
m_pMenu = new QMenu(); m_pMenu = new QMenu();
} }
CPanelView::~CPanelView() CPanelView::~CPanelView()
{ {
} }
void CPanelView::AddPanelItemsToMenu(bool bAddSeparator) void CPanelView::AddPanelItemsToMenu(bool bAddSeparator)
{ {
if(bAddSeparator) if(bAddSeparator)
m_pMenu->addSeparator(); m_pMenu->addSeparator();
m_pCopyCell = m_pMenu->addAction(m_CopyCell, this, SLOT(OnCopyCell())); m_pCopyCell = m_pMenu->addAction(m_CopyCell, this, SLOT(OnCopyCell()));
m_pCopyRow = m_pMenu->addAction(m_CopyRow, this, SLOT(OnCopyRow())); m_pCopyRow = m_pMenu->addAction(m_CopyRow, this, SLOT(OnCopyRow()));
m_pCopyRow->setShortcut(QKeySequence::Copy); m_pCopyRow->setShortcut(QKeySequence::Copy);
m_pCopyRow->setShortcutContext(Qt::WidgetWithChildrenShortcut); m_pCopyRow->setShortcutContext(Qt::WidgetWithChildrenShortcut);
this->addAction(m_pCopyRow); this->addAction(m_pCopyRow);
m_pCopyPanel = m_pMenu->addAction(m_CopyPanel, this, SLOT(OnCopyPanel())); m_pCopyPanel = m_pMenu->addAction(m_CopyPanel, this, SLOT(OnCopyPanel()));
} }
void CPanelView::OnMenu(const QPoint& Point) void CPanelView::OnMenu(const QPoint& Point)
{ {
QModelIndex Index = GetView()->currentIndex(); QModelIndex Index = GetView()->currentIndex();
m_pCopyCell->setEnabled(Index.isValid()); m_pCopyCell->setEnabled(Index.isValid());
m_pCopyRow->setEnabled(Index.isValid()); m_pCopyRow->setEnabled(Index.isValid());
m_pCopyPanel->setEnabled(true); m_pCopyPanel->setEnabled(true);
m_pMenu->popup(QCursor::pos()); m_pMenu->popup(QCursor::pos());
} }
void CPanelView::OnCopyCell() void CPanelView::OnCopyCell()
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
QTreeView * pView = GetView(); QTreeView * pView = GetView();
QModelIndex Index = pView->currentIndex(); QModelIndex Index = pView->currentIndex();
QModelIndex ModelIndex = MapToSource(Index); QModelIndex ModelIndex = MapToSource(Index);
int Column = ModelIndex.column(); int Column = ModelIndex.column();
QList<QStringList> Rows; QList<QStringList> Rows;
foreach(const QModelIndex& Index, pView->selectionModel()->selectedIndexes()) foreach(const QModelIndex& Index, pView->selectionModel()->selectedIndexes())
{ {
if (Index.column() != Column) if (Index.column() != Column)
continue; continue;
QModelIndex CurIndex = pModel->index(Index.row(), Column, Index.parent()); QModelIndex CurIndex = pModel->index(Index.row(), Column, Index.parent());
QString Cell = pModel->data(CurIndex, Qt::DisplayRole).toString(); QString Cell = pModel->data(CurIndex, Qt::DisplayRole).toString();
Rows.append(QStringList() << Cell); Rows.append(QStringList() << Cell);
} }
FormatAndCopy(Rows, false); FormatAndCopy(Rows, false);
} }
void CPanelView::OnCopyRow() void CPanelView::OnCopyRow()
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
QTreeView * pView = GetView(); QTreeView * pView = GetView();
int Column = 0; // find first not hidden column int Column = 0; // find first not hidden column
for (int i = 0; i < pModel->columnCount(); i++) for (int i = 0; i < pModel->columnCount(); i++)
{ {
if (!pView->isColumnHidden(i) || m_ForcedColumns.contains(i)) if (!pView->isColumnHidden(i) || m_ForcedColumns.contains(i))
{ {
Column = i; Column = i;
break; break;
} }
} }
QList<QStringList> Rows; QList<QStringList> Rows;
foreach(const QModelIndex& Index, pView->selectionModel()->selectedIndexes()) foreach(const QModelIndex& Index, pView->selectionModel()->selectedIndexes())
{ {
if (Index.column() != Column) if (Index.column() != Column)
continue; continue;
QModelIndex ModelIndex = MapToSource(Index); QModelIndex ModelIndex = MapToSource(Index);
Rows.append(CopyRow(ModelIndex)); Rows.append(CopyRow(ModelIndex));
} }
FormatAndCopy(Rows); FormatAndCopy(Rows);
} }
QStringList CPanelView::CopyHeader() QStringList CPanelView::CopyHeader()
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
QTreeView * pView = GetView(); QTreeView * pView = GetView();
QStringList Headder; QStringList Headder;
for (int i = 0; i < pModel->columnCount(); i++) for (int i = 0; i < pModel->columnCount(); i++)
{ {
if (/*!m_CopyAll &&*/ pView->isColumnHidden(i) && !m_ForcedColumns.contains(i)) if (/*!m_CopyAll &&*/ pView->isColumnHidden(i) && !m_ForcedColumns.contains(i))
continue; continue;
QString Cell = pModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); QString Cell = pModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
if (!m_SimpleFormat) if (!m_SimpleFormat)
Cell = "|" + Cell + "|"; Cell = "|" + Cell + "|";
Headder.append(Cell); Headder.append(Cell);
} }
return Headder; return Headder;
} }
QStringList CPanelView::CopyRow(const QModelIndex& ModelIndex, int Level) QStringList CPanelView::CopyRow(const QModelIndex& ModelIndex, int Level)
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
QTreeView * pView = GetView(); QTreeView * pView = GetView();
QStringList Cells; QStringList Cells;
for (int i = 0; i < pModel->columnCount(); i++) for (int i = 0; i < pModel->columnCount(); i++)
{ {
if (/*!m_CopyAll &&*/ pView->isColumnHidden(i) && !m_ForcedColumns.contains(i)) if (/*!m_CopyAll &&*/ pView->isColumnHidden(i) && !m_ForcedColumns.contains(i))
continue; continue;
QModelIndex CellIndex = pModel->index(ModelIndex.row(), i, ModelIndex.parent()); QModelIndex CellIndex = pModel->index(ModelIndex.row(), i, ModelIndex.parent());
QString Cell = pModel->data(CellIndex, Qt::DisplayRole).toString(); QString Cell = pModel->data(CellIndex, Qt::DisplayRole).toString();
if (Level && i == 0) if (Level && i == 0)
Cell.prepend(QString(Level, '_') + " "); Cell.prepend(QString(Level, '_') + " ");
Cells.append(Cell); Cells.append(Cell);
} }
return Cells; return Cells;
} }
void CPanelView::RecursiveCopyPanel(const QModelIndex& ModelIndex, QList<QStringList>& Rows, int Level) void CPanelView::RecursiveCopyPanel(const QModelIndex& ModelIndex, QList<QStringList>& Rows, int Level)
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
Rows.append(CopyRow(ModelIndex, Level)); Rows.append(CopyRow(ModelIndex, Level));
for (int i = 0; i < pModel->rowCount(ModelIndex); i++) for (int i = 0; i < pModel->rowCount(ModelIndex); i++)
{ {
QModelIndex SubIndex = pModel->index(i, 0, ModelIndex); QModelIndex SubIndex = pModel->index(i, 0, ModelIndex);
RecursiveCopyPanel(SubIndex, Rows, Level + 1); RecursiveCopyPanel(SubIndex, Rows, Level + 1);
} }
} }
void CPanelView::OnCopyPanel() void CPanelView::OnCopyPanel()
{ {
QAbstractItemModel* pModel = GetModel(); QAbstractItemModel* pModel = GetModel();
QList<QStringList> Rows; QList<QStringList> Rows;
for (int i = 0; i < pModel->rowCount(); ++i) for (int i = 0; i < pModel->rowCount(); ++i)
{ {
QModelIndex ModelIndex = pModel->index(i, 0); QModelIndex ModelIndex = pModel->index(i, 0);
RecursiveCopyPanel(ModelIndex, Rows); RecursiveCopyPanel(ModelIndex, Rows);
} }
FormatAndCopy(Rows); FormatAndCopy(Rows);
} }
void CPanelView::FormatAndCopy(QList<QStringList> Rows, bool Headder) void CPanelView::FormatAndCopy(QList<QStringList> Rows, bool Headder)
{ {
int RowCount = Rows.length(); int RowCount = Rows.length();
if (Headder) if (Headder)
{ {
Rows.prepend(QStringList()); Rows.prepend(QStringList());
Rows.prepend(CopyHeader()); Rows.prepend(CopyHeader());
Rows.prepend(QStringList()); Rows.prepend(QStringList());
} }
QStringList TextRows; QStringList TextRows;
if (m_SimpleFormat || !Headder) if (m_SimpleFormat || !Headder)
{ {
foreach(const QStringList& Row, Rows) foreach(const QStringList& Row, Rows)
TextRows.append(Row.join(m_CellSeparator)); TextRows.append(Row.join(m_CellSeparator));
} }
else if(Rows.size() > (Headder ? 3 : 0)) else if(Rows.size() > (Headder ? 3 : 0))
{ {
int Columns = Rows[Headder ? 3 : 0].count(); int Columns = Rows[Headder ? 3 : 0].count();
QVector<int> ColumnWidths(Columns, 0); QVector<int> ColumnWidths(Columns, 0);
foreach(const QStringList& Row, Rows) foreach(const QStringList& Row, Rows)
{ {
for (int i = 0; i < Min(Row.count(), Columns); i++) for (int i = 0; i < Min(Row.count(), Columns); i++)
{ {
int CellWidth = Row[i].length(); int CellWidth = Row[i].length();
if (ColumnWidths[i] < CellWidth) if (ColumnWidths[i] < CellWidth)
ColumnWidths[i] = CellWidth; ColumnWidths[i] = CellWidth;
} }
} }
foreach(const QStringList& Row, Rows) foreach(const QStringList& Row, Rows)
{ {
if (m_MaxCellWidth != 0 && RowCount > 1) if (m_MaxCellWidth != 0 && RowCount > 1)
{ {
for (int Pos = 0;;Pos += m_MaxCellWidth) for (int Pos = 0;;Pos += m_MaxCellWidth)
{ {
bool More = false; bool More = false;
QString RowText; QString RowText;
for (int i = 0; i < Min(Row.count(), Columns); i++) for (int i = 0; i < Min(Row.count(), Columns); i++)
{ {
if (Row[i].length() > Pos) if (Row[i].length() > Pos)
RowText.append(Row[i].mid(Pos, m_MaxCellWidth).leftJustified(Min(m_MaxCellWidth, ColumnWidths[i]) + 3)); RowText.append(Row[i].mid(Pos, m_MaxCellWidth).leftJustified(Min(m_MaxCellWidth, ColumnWidths[i]) + 3));
else else
RowText.append(QString(Min(m_MaxCellWidth, ColumnWidths[i]) + 3, ' ')); RowText.append(QString(Min(m_MaxCellWidth, ColumnWidths[i]) + 3, ' '));
if (Row[i].length() > Pos + m_MaxCellWidth) if (Row[i].length() > Pos + m_MaxCellWidth)
More = true; More = true;
} }
TextRows.append(RowText); TextRows.append(RowText);
if (!More) if (!More)
break; break;
} }
} }
else else
{ {
QString RowText; QString RowText;
for (int i = 0; i < Min(Row.count(), Columns); i++) for (int i = 0; i < Min(Row.count(), Columns); i++)
RowText.append(Row[i].leftJustified(ColumnWidths[i] + 3)); RowText.append(Row[i].leftJustified(ColumnWidths[i] + 3));
TextRows.append(RowText); TextRows.append(RowText);
} }
} }
} }
QApplication::clipboard()->setText(TextRows.join("\n")); QApplication::clipboard()->setText(TextRows.join("\n"));
} }

View File

@ -1,185 +1,185 @@
#pragma once #pragma once
#include "../mischelpers_global.h" #include "../mischelpers_global.h"
class MISCHELPERS_EXPORT CPanelView : public QWidget class MISCHELPERS_EXPORT CPanelView : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
CPanelView(QWidget *parent = 0); CPanelView(QWidget *parent = 0);
virtual ~CPanelView(); virtual ~CPanelView();
static void SetSimpleFormat(bool bSimple) { m_SimpleFormat = bSimple; }
static void SetDarkMode(bool bDarkMode) { m_DarkMode = bDarkMode; }
static void SetMaxCellWidth(int iMaxWidth) { m_MaxCellWidth = iMaxWidth; }
static void SetCellSeparator(const QString& Sep) { m_CellSeparator = Sep; }
static QString m_CopyCell;
static QString m_CopyRow;
static QString m_CopyPanel;
protected slots:
virtual void OnMenu(const QPoint& Point);
virtual void OnCopyCell();
virtual void OnCopyRow();
virtual void OnCopyPanel();
virtual QTreeView* GetView() = 0;
virtual QAbstractItemModel* GetModel() = 0;
virtual QModelIndex MapToSource(const QModelIndex& Model) { return Model; }
static QModelIndexList MapToSource(QModelIndexList Indexes, QSortFilterProxyModel* pProxy) {
for (int i = 0; i < Indexes.count(); i++)
Indexes[i] = pProxy->mapToSource(Indexes[i]);
return Indexes;
}
virtual void AddPanelItemsToMenu(bool bAddSeparator = true);
virtual void ForceColumn(int column, bool bSet = true) { if (bSet) m_ForcedColumns.insert(column); else m_ForcedColumns.remove(column); }
virtual QStringList CopyHeader();
virtual QStringList CopyRow(const QModelIndex& ModelIndex, int Level = 0);
virtual void RecursiveCopyPanel(const QModelIndex& ModelIndex, QList<QStringList>& Rows, int Level = 0);
protected:
void FormatAndCopy(QList<QStringList> Rows, bool Headder = true);
QMenu* m_pMenu;
QAction* m_pCopyCell;
QAction* m_pCopyRow;
QAction* m_pCopyPanel;
//bool m_CopyAll;
QSet<int> m_ForcedColumns;
static bool m_SimpleFormat;
static bool m_DarkMode;
static int m_MaxCellWidth;
static QString m_CellSeparator;
};
template <class T>
class CPanelWidget : public CPanelView
{
public:
CPanelWidget(QWidget *parent = 0) : CPanelView(parent)
{
m_pMainLayout = new QVBoxLayout();
m_pMainLayout->setMargin(0);
this->setLayout(m_pMainLayout);
m_pTreeList = new T();
m_pTreeList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_pTreeList, SIGNAL(customContextMenuRequested( const QPoint& )), this, SLOT(OnMenu(const QPoint &)));
m_pMainLayout->addWidget(m_pTreeList);
m_pTreeList->setMinimumHeight(50);
AddPanelItemsToMenu();
m_pLastAction = m_pMenu->actions()[0];
}
virtual QMenu* GetMenu() { return m_pMenu; }
virtual void AddAction(QAction* pAction) { m_pMenu->insertAction(m_pLastAction, pAction); }
virtual T* GetTree() { return m_pTreeList; }
virtual QTreeView* GetView() { return m_pTreeList; }
virtual QAbstractItemModel* GetModel() { return m_pTreeList->model(); }
virtual QVBoxLayout* GetLayout() { return m_pMainLayout; }
protected:
QVBoxLayout* m_pMainLayout;
T* m_pTreeList;
QAction* m_pLastAction;
};
#include "TreeWidgetEx.h"
#include "Finder.h"
class MISCHELPERS_EXPORT CPanelWidgetEx : public CPanelWidget<QTreeWidgetEx> static void SetSimpleFormat(bool bSimple) { m_SimpleFormat = bSimple; }
{ static void SetDarkMode(bool bDarkMode) { m_DarkMode = bDarkMode; }
Q_OBJECT static void SetMaxCellWidth(int iMaxWidth) { m_MaxCellWidth = iMaxWidth; }
static void SetCellSeparator(const QString& Sep) { m_CellSeparator = Sep; }
public:
CPanelWidgetEx(QWidget *parent = 0) : CPanelWidget<QTreeWidgetEx>(parent) static QString m_CopyCell;
{ static QString m_CopyRow;
m_pFinder = new CFinder(NULL, this, false); static QString m_CopyPanel;
m_pMainLayout->addWidget(m_pFinder);
QObject::connect(m_pFinder, SIGNAL(SetFilter(const QRegExp&, bool, int)), this, SLOT(SetFilter(const QRegExp&, bool, int))); protected slots:
} virtual void OnMenu(const QPoint& Point);
static void ApplyFilter(QTreeWidgetEx* pTree, QTreeWidgetItem* pItem, const QRegExp& Exp/*, bool bHighLight = false, int Col = -1*/) virtual void OnCopyCell();
{ virtual void OnCopyRow();
for (int j = 0; j < pTree->columnCount(); j++) { virtual void OnCopyPanel();
pItem->setForeground(j, (m_DarkMode && !Exp.isEmpty() && pItem->text(j).contains(Exp)) ? Qt::yellow : pTree->palette().color(QPalette::WindowText));
pItem->setBackground(j, (!m_DarkMode && !Exp.isEmpty() && pItem->text(j).contains(Exp)) ? Qt::yellow : pTree->palette().color(QPalette::Base));
} virtual QTreeView* GetView() = 0;
virtual QAbstractItemModel* GetModel() = 0;
for (int i = 0; i < pItem->childCount(); i++) virtual QModelIndex MapToSource(const QModelIndex& Model) { return Model; }
{ static QModelIndexList MapToSource(QModelIndexList Indexes, QSortFilterProxyModel* pProxy) {
ApplyFilter(pTree, pItem->child(i), Exp/*, bHighLight, Col*/); for (int i = 0; i < Indexes.count(); i++)
} Indexes[i] = pProxy->mapToSource(Indexes[i]);
} return Indexes;
}
static void ApplyFilter(QTreeWidgetEx* pTree, const QRegExp& Exp/*, bool bHighLight = false, int Col = -1*/)
{ virtual void AddPanelItemsToMenu(bool bAddSeparator = true);
for (int i = 0; i < pTree->topLevelItemCount(); i++)
ApplyFilter(pTree, pTree->topLevelItem(i), Exp/*, bHighLight, Col*/); virtual void ForceColumn(int column, bool bSet = true) { if (bSet) m_ForcedColumns.insert(column); else m_ForcedColumns.remove(column); }
}
virtual QStringList CopyHeader();
private slots: virtual QStringList CopyRow(const QModelIndex& ModelIndex, int Level = 0);
void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Col = -1) // -1 = any virtual void RecursiveCopyPanel(const QModelIndex& ModelIndex, QList<QStringList>& Rows, int Level = 0);
{
ApplyFilter(m_pTreeList, Exp); protected:
} void FormatAndCopy(QList<QStringList> Rows, bool Headder = true);
private: QMenu* m_pMenu;
CFinder* m_pFinder; QAction* m_pCopyCell;
}; QAction* m_pCopyRow;
QAction* m_pCopyPanel;
#include "TreeViewEx.h"
#include "SortFilterProxyModel.h" //bool m_CopyAll;
QSet<int> m_ForcedColumns;
class CPanelViewEx: public CPanelWidget<QTreeViewEx> static bool m_SimpleFormat;
{ static bool m_DarkMode;
public: static int m_MaxCellWidth;
CPanelViewEx(QAbstractItemModel* pModel, QWidget *parent = 0) : CPanelWidget<QTreeViewEx>(parent) static QString m_CellSeparator;
{ };
m_pModel = pModel;
template <class T>
m_pSortProxy = new CSortFilterProxyModel(false, this); class CPanelWidget : public CPanelView
m_pSortProxy->setSortRole(Qt::EditRole); {
m_pSortProxy->setSourceModel(m_pModel); public:
m_pSortProxy->setDynamicSortFilter(true); CPanelWidget(QWidget *parent = 0) : CPanelView(parent)
{
m_pTreeList->setModel(m_pSortProxy); m_pMainLayout = new QVBoxLayout();
((CSortFilterProxyModel*)m_pSortProxy)->setView(m_pTreeList); m_pMainLayout->setMargin(0);
this->setLayout(m_pMainLayout);
m_pTreeList->setSelectionMode(QAbstractItemView::ExtendedSelection); m_pTreeList = new T();
#ifdef WIN32 m_pTreeList->setContextMenuPolicy(Qt::CustomContextMenu);
QStyle* pStyle = QStyleFactory::create("windows"); connect(m_pTreeList, SIGNAL(customContextMenuRequested( const QPoint& )), this, SLOT(OnMenu(const QPoint &)));
m_pTreeList->setStyle(pStyle); m_pMainLayout->addWidget(m_pTreeList);
#endif m_pTreeList->setMinimumHeight(50);
m_pTreeList->setExpandsOnDoubleClick(false); AddPanelItemsToMenu();
m_pTreeList->setSortingEnabled(true);
m_pLastAction = m_pMenu->actions()[0];
m_pTreeList->setContextMenuPolicy(Qt::CustomContextMenu); }
connect(m_pTreeList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnMenu(const QPoint &)));
virtual QMenu* GetMenu() { return m_pMenu; }
m_pTreeList->setColumnReset(1); virtual void AddAction(QAction* pAction) { m_pMenu->insertAction(m_pLastAction, pAction); }
//connect(m_pTreeList, SIGNAL(ResetColumns()), m_pTreeList, SLOT(OnResetColumns()));
//connect(m_pBoxTree, SIGNAL(ColumnChanged(int, bool)), this, SLOT(OnColumnsChanged())); virtual T* GetTree() { return m_pTreeList; }
virtual QTreeView* GetView() { return m_pTreeList; }
m_pMainLayout->addWidget(CFinder::AddFinder(m_pTreeList, m_pSortProxy)); virtual QAbstractItemModel* GetModel() { return m_pTreeList->model(); }
}
virtual QVBoxLayout* GetLayout() { return m_pMainLayout; }
protected:
QAbstractItemModel* m_pModel; protected:
QSortFilterProxyModel* m_pSortProxy; QVBoxLayout* m_pMainLayout;
T* m_pTreeList;
QAction* m_pLastAction;
};
#include "TreeWidgetEx.h"
#include "Finder.h"
class MISCHELPERS_EXPORT CPanelWidgetEx : public CPanelWidget<QTreeWidgetEx>
{
Q_OBJECT
public:
CPanelWidgetEx(QWidget *parent = 0) : CPanelWidget<QTreeWidgetEx>(parent)
{
m_pFinder = new CFinder(NULL, this, false);
m_pMainLayout->addWidget(m_pFinder);
QObject::connect(m_pFinder, SIGNAL(SetFilter(const QRegExp&, bool, int)), this, SLOT(SetFilter(const QRegExp&, bool, int)));
}
static void ApplyFilter(QTreeWidgetEx* pTree, QTreeWidgetItem* pItem, const QRegExp& Exp/*, bool bHighLight = false, int Col = -1*/)
{
for (int j = 0; j < pTree->columnCount(); j++) {
pItem->setForeground(j, (m_DarkMode && !Exp.isEmpty() && pItem->text(j).contains(Exp)) ? Qt::yellow : pTree->palette().color(QPalette::WindowText));
pItem->setBackground(j, (!m_DarkMode && !Exp.isEmpty() && pItem->text(j).contains(Exp)) ? Qt::yellow : pTree->palette().color(QPalette::Base));
}
for (int i = 0; i < pItem->childCount(); i++)
{
ApplyFilter(pTree, pItem->child(i), Exp/*, bHighLight, Col*/);
}
}
static void ApplyFilter(QTreeWidgetEx* pTree, const QRegExp& Exp/*, bool bHighLight = false, int Col = -1*/)
{
for (int i = 0; i < pTree->topLevelItemCount(); i++)
ApplyFilter(pTree, pTree->topLevelItem(i), Exp/*, bHighLight, Col*/);
}
private slots:
void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Col = -1) // -1 = any
{
ApplyFilter(m_pTreeList, Exp);
}
private:
CFinder* m_pFinder;
};
#include "TreeViewEx.h"
#include "SortFilterProxyModel.h"
class CPanelViewEx: public CPanelWidget<QTreeViewEx>
{
public:
CPanelViewEx(QAbstractItemModel* pModel, QWidget *parent = 0) : CPanelWidget<QTreeViewEx>(parent)
{
m_pModel = pModel;
m_pSortProxy = new CSortFilterProxyModel(false, this);
m_pSortProxy->setSortRole(Qt::EditRole);
m_pSortProxy->setSourceModel(m_pModel);
m_pSortProxy->setDynamicSortFilter(true);
m_pTreeList->setModel(m_pSortProxy);
((CSortFilterProxyModel*)m_pSortProxy)->setView(m_pTreeList);
m_pTreeList->setSelectionMode(QAbstractItemView::ExtendedSelection);
#ifdef WIN32
QStyle* pStyle = QStyleFactory::create("windows");
m_pTreeList->setStyle(pStyle);
#endif
m_pTreeList->setExpandsOnDoubleClick(false);
m_pTreeList->setSortingEnabled(true);
m_pTreeList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_pTreeList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnMenu(const QPoint &)));
m_pTreeList->setColumnReset(1);
//connect(m_pTreeList, SIGNAL(ResetColumns()), m_pTreeList, SLOT(OnResetColumns()));
//connect(m_pBoxTree, SIGNAL(ColumnChanged(int, bool)), this, SLOT(OnColumnsChanged()));
m_pMainLayout->addWidget(CFinder::AddFinder(m_pTreeList, m_pSortProxy));
}
protected:
QAbstractItemModel* m_pModel;
QSortFilterProxyModel* m_pSortProxy;
}; };

View File

@ -1,208 +1,208 @@
#pragma once #pragma once
#include "../mischelpers_global.h" #include "../mischelpers_global.h"
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QTreeView> #include <QTreeView>
#include "Finder.h" #include "Finder.h"
class MISCHELPERS_EXPORT CSortFilterProxyModel: public QSortFilterProxyModel class MISCHELPERS_EXPORT CSortFilterProxyModel: public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
CSortFilterProxyModel(bool bAlternate, QObject* parrent = 0) : QSortFilterProxyModel(parrent) CSortFilterProxyModel(bool bAlternate, QObject* parrent = 0) : QSortFilterProxyModel(parrent)
{ {
m_bAlternate = bAlternate; m_bAlternate = bAlternate;
m_bHighLight = false; m_bHighLight = false;
m_iColumn = 0; m_iColumn = 0;
m_pView = NULL; m_pView = NULL;
this->setSortCaseSensitivity(Qt::CaseInsensitive); this->setSortCaseSensitivity(Qt::CaseInsensitive);
} }
void setView(QTreeView* pView) void setView(QTreeView* pView)
{ {
m_pView = pView; m_pView = pView;
} }
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
{ {
if (m_bHighLight) if (m_bHighLight)
return true; return true;
// allow the item to pass if any of the child items pass // allow the item to pass if any of the child items pass
if(!filterRegExp().isEmpty()) if(!filterRegExp().isEmpty())
{ {
// get source-model index for current row // get source-model index for current row
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent); QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
if(source_index.isValid()) if(source_index.isValid())
{ {
// if any of children matches the filter, then current index matches the filter as well // if any of children matches the filter, then current index matches the filter as well
int nb = sourceModel()->rowCount(source_index); int nb = sourceModel()->rowCount(source_index);
for(int i = 0; i < nb; i++) for(int i = 0; i < nb; i++)
{ {
if(filterAcceptsRow(i, source_index)) if(filterAcceptsRow(i, source_index))
return true; return true;
} }
// check current index itself // check current index itself
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
} }
} }
// default behavioure // default behavioure
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
} }
QVariant data(const QModelIndex &index, int role) const QVariant data(const QModelIndex &index, int role) const
{ {
QVariant Data = QSortFilterProxyModel::data(index, role); QVariant Data = QSortFilterProxyModel::data(index, role);
if (m_bHighLight && role == (CFinder::GetDarkMode() ? Qt::ForegroundRole : Qt::BackgroundRole)) if (m_bHighLight && role == (CFinder::GetDarkMode() ? Qt::ForegroundRole : Qt::BackgroundRole))
{ {
if (!filterRegExp().isEmpty()) if (!filterRegExp().isEmpty())
{ {
QString Key = QSortFilterProxyModel::data(index, filterRole()).toString(); QString Key = QSortFilterProxyModel::data(index, filterRole()).toString();
if (Key.contains(filterRegExp())) if (Key.contains(filterRegExp()))
return QColor(Qt::yellow); return QColor(Qt::yellow);
} }
//return QColor(Qt::white); //return QColor(Qt::white);
} }
if (role == Qt::BackgroundRole) if (role == Qt::BackgroundRole)
{ {
if (m_bAlternate && !Data.isValid()) if (m_bAlternate && !Data.isValid())
{ {
if (0 == index.row() % 2) if (0 == index.row() % 2)
return QColor(226, 237, 253); return QColor(226, 237, 253);
else else
return QColor(Qt::white); return QColor(Qt::white);
} }
} }
return Data; return Data;
} }
public slots: public slots:
void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Col = -1) // -1 = any void SetFilter(const QRegExp& Exp, bool bHighLight = false, int Col = -1) // -1 = any
{ {
QModelIndex idx; QModelIndex idx;
//if (m_pView) idx = m_pView->currentIndex(); //if (m_pView) idx = m_pView->currentIndex();
m_iColumn = Col; m_iColumn = Col;
m_bHighLight = bHighLight; m_bHighLight = bHighLight;
setFilterKeyColumn(Col); setFilterKeyColumn(Col);
setFilterRegExp(Exp); setFilterRegExp(Exp);
//if (m_pView) m_pView->setCurrentIndex(idx); //if (m_pView) m_pView->setCurrentIndex(idx);
if (m_bHighLight) if (m_bHighLight)
emit layoutChanged(); emit layoutChanged();
} }
void SelectNext() void SelectNext()
{ {
if (!m_pView) if (!m_pView)
return; return;
bool next = true; bool next = true;
QModelIndex idx = m_pView->currentIndex(); QModelIndex idx = m_pView->currentIndex();
if (!(next = idx.isValid())) if (!(next = idx.isValid()))
idx = index(0, 0); idx = index(0, 0);
//if (QApplication::keyboardModifiers() & Qt::ControlModifier) //if (QApplication::keyboardModifiers() & Qt::ControlModifier)
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
idx = FindPrev(idx, next); idx = FindPrev(idx, next);
else else
idx = FindNext(idx, next); idx = FindNext(idx, next);
if (idx.isValid()) if (idx.isValid())
m_pView->setCurrentIndex(idx); m_pView->setCurrentIndex(idx);
else else
QApplication::beep(); QApplication::beep();
} }
protected: protected:
bool m_bAlternate; bool m_bAlternate;
bool m_bHighLight; bool m_bHighLight;
int m_iColumn; int m_iColumn;
QTreeView* m_pView; QTreeView* m_pView;
bool MatchCell(QModelIndex idx, int column) bool MatchCell(QModelIndex idx, int column)
{ {
QModelIndex tmp = idx.sibling(idx.row(), column); QModelIndex tmp = idx.sibling(idx.row(), column);
QString str = data(tmp, filterRole()).toString(); QString str = data(tmp, filterRole()).toString();
if (str.contains(filterRegExp())) if (str.contains(filterRegExp()))
return true; return true;
return false; return false;
} }
bool MatchRow(QModelIndex idx) bool MatchRow(QModelIndex idx)
{ {
if (m_iColumn != -1) if (m_iColumn != -1)
return MatchCell(idx, m_iColumn); return MatchCell(idx, m_iColumn);
for(int col = 0; col < columnCount(idx); col++) { for(int col = 0; col < columnCount(idx); col++) {
if (MatchCell(idx, col)) if (MatchCell(idx, col))
return true; return true;
} }
return false; return false;
} }
QModelIndex FindNext(QModelIndex idx, bool next = false) QModelIndex FindNext(QModelIndex idx, bool next = false)
{ {
if (MatchRow(idx) && !next) if (MatchRow(idx) && !next)
return idx; return idx;
if (hasChildren(idx)) if (hasChildren(idx))
{ {
int numRows = rowCount(idx); int numRows = rowCount(idx);
for (int count = 0; count < numRows; count++) { for (int count = 0; count < numRows; count++) {
QModelIndex tmp = FindNext(index(count, 0, idx)); QModelIndex tmp = FindNext(index(count, 0, idx));
if (tmp.isValid()) if (tmp.isValid())
return tmp; return tmp;
} }
} }
do { do {
QModelIndex par = parent(idx); QModelIndex par = parent(idx);
int numRows = rowCount(par); int numRows = rowCount(par);
for (int count = idx.row() + 1; count < numRows; count++) { for (int count = idx.row() + 1; count < numRows; count++) {
QModelIndex tmp = FindNext(index(count, 0, par)); QModelIndex tmp = FindNext(index(count, 0, par));
if (tmp.isValid()) if (tmp.isValid())
return tmp; return tmp;
} }
idx = par; idx = par;
} while (idx.isValid()); } while (idx.isValid());
return QModelIndex(); return QModelIndex();
} }
QModelIndex FindPrev(QModelIndex idx, bool next = false) QModelIndex FindPrev(QModelIndex idx, bool next = false)
{ {
if (MatchRow(idx) && !next) if (MatchRow(idx) && !next)
return idx; return idx;
if (hasChildren(idx)) if (hasChildren(idx))
{ {
int numRows = rowCount(idx); int numRows = rowCount(idx);
for (int count = numRows-1; count >= 0; count++) { for (int count = numRows-1; count >= 0; count++) {
QModelIndex tmp = FindNext(index(count, 0, idx)); QModelIndex tmp = FindNext(index(count, 0, idx));
if (tmp.isValid()) if (tmp.isValid())
return tmp; return tmp;
} }
} }
do { do {
QModelIndex par = parent(idx); QModelIndex par = parent(idx);
int numRows = rowCount(par); int numRows = rowCount(par);
for (int count = idx.row() - 1; count >= 0; count--) { for (int count = idx.row() - 1; count >= 0; count--) {
QModelIndex tmp = FindNext(index(count, 0, par)); QModelIndex tmp = FindNext(index(count, 0, par));
if (tmp.isValid()) if (tmp.isValid())
return tmp; return tmp;
} }
idx = par; idx = par;
} while (idx.isValid()); } while (idx.isValid());
return QModelIndex(); return QModelIndex();
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,187 +1,187 @@
#include "stdafx.h" #include "stdafx.h"
#include "SelectBoxWindow.h" #include "SelectBoxWindow.h"
#include "SandMan.h" #include "SandMan.h"
#include "../MiscHelpers/Common/Settings.h" #include "../MiscHelpers/Common/Settings.h"
#include "../SbiePlusAPI.h" #include "../SbiePlusAPI.h"
#include "../Views/SbieView.h" #include "../Views/SbieView.h"
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
#include <wtypes.h> #include <wtypes.h>
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <dbt.h> #include <dbt.h>
#endif #endif
QTreeWidgetItem* CSelectBoxWindow__GetBoxParent(const QMap<QString, QStringList>& Groups, QMap<QString, QTreeWidgetItem*>& GroupItems, QTreeWidget* treeBoxes, const QString& Name, int Depth = 0) QTreeWidgetItem* CSelectBoxWindow__GetBoxParent(const QMap<QString, QStringList>& Groups, QMap<QString, QTreeWidgetItem*>& GroupItems, QTreeWidget* treeBoxes, const QString& Name, int Depth = 0)
{ {
if (Depth > 100) if (Depth > 100)
return NULL; return NULL;
for (auto I = Groups.constBegin(); I != Groups.constEnd(); ++I) { for (auto I = Groups.constBegin(); I != Groups.constEnd(); ++I) {
if (I->contains(Name)) { if (I->contains(Name)) {
if (I.key().isEmpty()) if (I.key().isEmpty())
return NULL; // global group return NULL; // global group
QTreeWidgetItem*& pParent = GroupItems[I.key()]; QTreeWidgetItem*& pParent = GroupItems[I.key()];
if (!pParent) { if (!pParent) {
pParent = new QTreeWidgetItem(); pParent = new QTreeWidgetItem();
pParent->setText(0, I.key()); pParent->setText(0, I.key());
QFont fnt = pParent->font(0); QFont fnt = pParent->font(0);
fnt.setBold(true); fnt.setBold(true);
pParent->setFont(0, fnt); pParent->setFont(0, fnt);
if (QTreeWidgetItem* pParent2 = CSelectBoxWindow__GetBoxParent(Groups, GroupItems, treeBoxes, I.key(), ++Depth)) if (QTreeWidgetItem* pParent2 = CSelectBoxWindow__GetBoxParent(Groups, GroupItems, treeBoxes, I.key(), ++Depth))
pParent2->addChild(pParent); pParent2->addChild(pParent);
else else
treeBoxes->addTopLevelItem(pParent); treeBoxes->addTopLevelItem(pParent);
} }
return pParent; return pParent;
} }
} }
return NULL; return NULL;
} }
double CSelectBoxWindow__GetBoxOrder(const QMap<QString, QStringList>& Groups, const QString& Name, double value = 0.0, int Depth = 0) double CSelectBoxWindow__GetBoxOrder(const QMap<QString, QStringList>& Groups, const QString& Name, double value = 0.0, int Depth = 0)
{ {
if (Depth > 100) if (Depth > 100)
return 1000000000; return 1000000000;
for (auto I = Groups.constBegin(); I != Groups.constEnd(); ++I) { for (auto I = Groups.constBegin(); I != Groups.constEnd(); ++I) {
int Pos = I->indexOf(Name); int Pos = I->indexOf(Name);
if (Pos != -1) { if (Pos != -1) {
value = double(Pos) + value / 10.0; value = double(Pos) + value / 10.0;
if (I.key().isEmpty()) if (I.key().isEmpty())
return value; return value;
return CSelectBoxWindow__GetBoxOrder(Groups, I.key(), value, ++Depth); return CSelectBoxWindow__GetBoxOrder(Groups, I.key(), value, ++Depth);
} }
} }
return 1000000000; return 1000000000;
} }
CSelectBoxWindow::CSelectBoxWindow(const QStringList& Commands, const QString& BoxName, QWidget *parent) CSelectBoxWindow::CSelectBoxWindow(const QStringList& Commands, const QString& BoxName, QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
m_Commands = Commands; m_Commands = Commands;
Qt::WindowFlags flags = windowFlags(); Qt::WindowFlags flags = windowFlags();
flags |= Qt::CustomizeWindowHint; flags |= Qt::CustomizeWindowHint;
//flags &= ~Qt::WindowContextHelpButtonHint; //flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint; //flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint; //flags &= ~Qt::WindowMinMaxButtonsHint;
//flags |= Qt::WindowMinimizeButtonHint; //flags |= Qt::WindowMinimizeButtonHint;
//flags &= ~Qt::WindowCloseButtonHint; //flags &= ~Qt::WindowCloseButtonHint;
flags &= ~Qt::WindowContextHelpButtonHint; flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint; //flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags(flags); setWindowFlags(flags);
//setWindowState(Qt::WindowActive); //setWindowState(Qt::WindowActive);
SetForegroundWindow((HWND)QWidget::winId()); SetForegroundWindow((HWND)QWidget::winId());
bool bAlwaysOnTop = theConf->GetBool("Options/AlwaysOnTop", false); bool bAlwaysOnTop = theConf->GetBool("Options/AlwaysOnTop", false);
this->setWindowFlag(Qt::WindowStaysOnTopHint, bAlwaysOnTop); this->setWindowFlag(Qt::WindowStaysOnTopHint, bAlwaysOnTop);
if (!bAlwaysOnTop) { if (!bAlwaysOnTop) {
HWND hWnd = (HWND)this->winId(); HWND hWnd = (HWND)this->winId();
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
QTimer::singleShot(100, this, [hWnd]() { QTimer::singleShot(100, this, [hWnd]() {
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}); });
} }
ui.setupUi(this); ui.setupUi(this);
this->setWindowTitle(tr("Sandboxie-Plus - Run Sandboxed")); this->setWindowTitle(tr("Sandboxie-Plus - Run Sandboxed"));
connect(ui.radBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType())); connect(ui.radBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radUnBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType())); connect(ui.radUnBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.buttonBox, SIGNAL(accepted()), SLOT(OnRun())); connect(ui.buttonBox, SIGNAL(accepted()), SLOT(OnRun()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject())); connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
connect(ui.treeBoxes, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(OnBoxDblClick(QTreeWidgetItem*))); connect(ui.treeBoxes, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(OnBoxDblClick(QTreeWidgetItem*)));
QList<CSandBoxPtr> Boxes = theAPI->GetAllBoxes().values(); // map is sorted by key (box name) QList<CSandBoxPtr> Boxes = theAPI->GetAllBoxes().values(); // map is sorted by key (box name)
QMap<QString, QStringList> Groups = theGUI->GetBoxView()->GetGroups(); QMap<QString, QStringList> Groups = theGUI->GetBoxView()->GetGroups();
if (theConf->GetBool("MainWindow/BoxTree_UseOrder", false)) { if (theConf->GetBool("MainWindow/BoxTree_UseOrder", false)) {
QMultiMap<double, CSandBoxPtr> Boxes2; QMultiMap<double, CSandBoxPtr> Boxes2;
foreach(const CSandBoxPtr &pBox, Boxes) { foreach(const CSandBoxPtr &pBox, Boxes) {
Boxes2.insertMulti(CSelectBoxWindow__GetBoxOrder(Groups, pBox->GetName()), pBox); Boxes2.insertMulti(CSelectBoxWindow__GetBoxOrder(Groups, pBox->GetName()), pBox);
} }
Boxes = Boxes2.values(); Boxes = Boxes2.values();
} }
QMap<QString, QTreeWidgetItem*> GroupItems; QMap<QString, QTreeWidgetItem*> GroupItems;
foreach(const CSandBoxPtr &pBox, Boxes) foreach(const CSandBoxPtr &pBox, Boxes)
{ {
if (!pBox->IsEnabled() || !pBox->GetBool("ShowForRunIn", true)) if (!pBox->IsEnabled() || !pBox->GetBool("ShowForRunIn", true))
continue; continue;
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(pBox.data()); CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(pBox.data());
QTreeWidgetItem* pParent = CSelectBoxWindow__GetBoxParent(Groups, GroupItems, ui.treeBoxes, pBox->GetName()); QTreeWidgetItem* pParent = CSelectBoxWindow__GetBoxParent(Groups, GroupItems, ui.treeBoxes, pBox->GetName());
QTreeWidgetItem* pItem = new QTreeWidgetItem(); QTreeWidgetItem* pItem = new QTreeWidgetItem();
pItem->setText(0, pBox->GetName().replace("_", " ")); pItem->setText(0, pBox->GetName().replace("_", " "));
pItem->setData(0, Qt::UserRole, pBox->GetName()); pItem->setData(0, Qt::UserRole, pBox->GetName());
pItem->setData(0, Qt::DecorationRole, theGUI->GetBoxIcon(pBox->GetActiveProcessCount() > 0, pBoxEx->GetType())); pItem->setData(0, Qt::DecorationRole, theGUI->GetBoxIcon(pBox->GetActiveProcessCount() > 0, pBoxEx->GetType()));
if (pParent) if (pParent)
pParent->addChild(pItem); pParent->addChild(pItem);
else else
ui.treeBoxes->addTopLevelItem(pItem); ui.treeBoxes->addTopLevelItem(pItem);
if (pBox->GetName().compare(BoxName, Qt::CaseInsensitive) == 0) if (pBox->GetName().compare(BoxName, Qt::CaseInsensitive) == 0)
ui.treeBoxes->setCurrentItem(pItem); ui.treeBoxes->setCurrentItem(pItem);
} }
ui.treeBoxes->expandAll(); ui.treeBoxes->expandAll();
//ui.treeBoxes->sortByColumn(0, Qt::AscendingOrder); //ui.treeBoxes->sortByColumn(0, Qt::AscendingOrder);
//restoreGeometry(theConf->GetBlob("SelectBoxWindow/Window_Geometry")); //restoreGeometry(theConf->GetBlob("SelectBoxWindow/Window_Geometry"));
} }
CSelectBoxWindow::~CSelectBoxWindow() CSelectBoxWindow::~CSelectBoxWindow()
{ {
//theConf->SetBlob("SelectBoxWindow/Window_Geometry", saveGeometry()); //theConf->SetBlob("SelectBoxWindow/Window_Geometry", saveGeometry());
} }
void CSelectBoxWindow::closeEvent(QCloseEvent *e) void CSelectBoxWindow::closeEvent(QCloseEvent *e)
{ {
//emit Closed(); //emit Closed();
this->deleteLater(); this->deleteLater();
} }
void CSelectBoxWindow::OnBoxType() void CSelectBoxWindow::OnBoxType()
{ {
ui.treeBoxes->setEnabled(!ui.radUnBoxed->isChecked()); ui.treeBoxes->setEnabled(!ui.radUnBoxed->isChecked());
} }
void CSelectBoxWindow::OnBoxDblClick(QTreeWidgetItem*) void CSelectBoxWindow::OnBoxDblClick(QTreeWidgetItem*)
{ {
OnRun(); OnRun();
} }
void CSelectBoxWindow::OnRun() void CSelectBoxWindow::OnRun()
{ {
QTreeWidgetItem* pItem = ui.treeBoxes->currentItem(); QTreeWidgetItem* pItem = ui.treeBoxes->currentItem();
QString BoxName; QString BoxName;
if (ui.radUnBoxed->isChecked()) if (ui.radUnBoxed->isChecked())
{ {
if (QMessageBox("Sandboxie-Plus", tr("Are you sure you want to run the program outside the sandbox?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes) if (QMessageBox("Sandboxie-Plus", tr("Are you sure you want to run the program outside the sandbox?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
return; return;
pItem = NULL; pItem = NULL;
} }
else if (pItem == NULL) { else if (pItem == NULL) {
QMessageBox("Sandboxie-Plus", tr("Please select a sandbox."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec(); QMessageBox("Sandboxie-Plus", tr("Please select a sandbox."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
return; return;
} }
else { else {
BoxName = pItem->data(0, Qt::UserRole).toString(); BoxName = pItem->data(0, Qt::UserRole).toString();
} }
//QList<SB_STATUS> Results; //QList<SB_STATUS> Results;
foreach(const QString & Command, m_Commands) { foreach(const QString & Command, m_Commands) {
theAPI->RunStart(BoxName, Command, NULL, ui.chkAdmin->isChecked()); theAPI->RunStart(BoxName, Command, NULL, ui.chkAdmin->isChecked());
} }
//CSandMan::CheckResults(Results); //CSandMan::CheckResults(Results);
close(); close();
} }