Commit 1e525b4b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent 8d87b416
......@@ -41,8 +41,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
WidgetsAddons
)
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
add_subdirectory(src)
add_subdirectory(icons)
......
......@@ -30,8 +30,6 @@ KfindDlg::KfindDlg(const QUrl &url, QWidget *parent)
setModal(true);
QWidget::setWindowTitle(i18nc("@title:window", "Find Files/Folders"));
isResultReported = false;
QFrame *frame = new QFrame;
mainLayout->addWidget(frame);
......
......@@ -30,7 +30,7 @@ class KfindDlg : public QDialog
public:
explicit KfindDlg(const QUrl &url, QWidget *parent = nullptr);
~KfindDlg();
~KfindDlg() override;
void copySelection();
void setStatusMsg(const QString &);
......@@ -59,18 +59,18 @@ Q_SIGNALS:
void resultSelected(bool);
private:
KfindTabWidget *tabWidget;
KFindTreeView *win;
QPushButton *m_saveAsButton;
QPushButton *m_stopButton;
QPushButton *m_findButton;
QStatusBar *mStatusBar;
QLabel *m_labelStatus;
QLabel *m_labelProgress;
bool isResultReported;
KQuery *query;
KDirWatch *dirwatch;
KfindTabWidget *tabWidget = nullptr;
KFindTreeView *win = nullptr;
QPushButton *m_saveAsButton = nullptr;
QPushButton *m_stopButton = nullptr;
QPushButton *m_findButton = nullptr;
QStatusBar *mStatusBar = nullptr;
QLabel *m_labelStatus = nullptr;
QLabel *m_labelProgress = nullptr;
bool isResultReported = false;
KQuery *query = nullptr;
KDirWatch *dirwatch = nullptr;
};
#endif
......@@ -89,7 +89,7 @@ void KFindItemModel::insertFileItems(const QList< QPair<KFileItem, QString> > &p
for (; it != end; ++it) {
QPair<KFileItem, QString> pair = *it;
QString subDir = m_view->reducedDir(pair.first.url().adjusted(QUrl::RemoveFilename).path());
const QString subDir = m_view->reducedDir(pair.first.url().adjusted(QUrl::RemoveFilename).path());
m_itemList.append(KFindItem(pair.first, subDir, pair.second));
}
......@@ -115,6 +115,11 @@ KFindItem KFindItemModel::itemAtIndex(const QModelIndex &index) const
return KFindItem();
}
QList<KFindItem> KFindItemModel::getItemList() const
{
return m_itemList;
}
QVariant KFindItemModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
......@@ -171,9 +176,14 @@ void KFindItemModel::clear()
}
}
Qt::DropActions KFindItemModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::ItemFlags KFindItemModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
const Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if (index.isValid()) {
return Qt::ItemIsDragEnabled | defaultFlags;
}
......@@ -202,6 +212,12 @@ QMimeData *KFindItemModel::mimeData(const QModelIndexList &indexes) const
return mimeData;
}
int KFindItemModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 6;
}
//END KFindItemModel
//BEGIN KFindItem
......@@ -276,6 +292,16 @@ QVariant KFindItem::data(int column, int role) const
return QVariant();
}
KFileItem KFindItem::getFileItem() const
{
return m_fileItem;
}
bool KFindItem::isValid() const
{
return !m_fileItem.isNull();
}
//END KFindItem
//BEGIN KFindSortFilterProxyModel
......@@ -300,11 +326,10 @@ bool KFindSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIn
KFindTreeView::KFindTreeView(QWidget *parent, KfindDlg *findDialog)
: QTreeView(parent)
, m_model(new KFindItemModel(this))
, m_proxyModel(new KFindSortFilterProxyModel(this))
, m_kfindDialog(findDialog)
{
//Configure model and proxy model
m_model = new KFindItemModel(this);
m_proxyModel = new KFindSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_model);
setModel(m_proxyModel);
......@@ -375,6 +400,11 @@ QString KFindTreeView::reducedDir(const QString &fullDir)
return fullDir;
}
int KFindTreeView::itemCount() const
{
return m_model->rowCount();
}
void KFindTreeView::beginSearch(const QUrl &baseUrl)
{
m_baseDir = QDir(baseUrl.toLocalFile());
......@@ -436,6 +466,11 @@ void KFindTreeView::removeItem(const QUrl &url)
m_model->removeItem(url);
}
bool KFindTreeView::isInserted(const QUrl &url) const
{
return m_model->isInserted(url);
}
// copy to clipboard
void KFindTreeView::copySelection()
{
......@@ -604,7 +639,7 @@ void KFindTreeView::contextMenuRequested(const QPoint &p)
m_contextMenu->exec(this->mapToGlobal(p));
}
QList<QUrl> KFindTreeView::selectedUrls()
QList<QUrl> KFindTreeView::selectedUrls() const
{
QList<QUrl> uris;
......@@ -670,4 +705,9 @@ void KFindTreeView::updateMouseButtons()
m_mouseButtons = QApplication::mouseButtons();
}
void KFindTreeView::dragMoveEvent(QDragMoveEvent *e)
{
e->accept();
}
//END KFindTreeView
......@@ -31,15 +31,9 @@ public:
QVariant data(int column, int role) const;
KFileItem getFileItem() const
{
return m_fileItem;
}
KFileItem getFileItem() const;
bool isValid() const
{
return !m_fileItem.isNull();
}
bool isValid() const;
private:
KFileItem m_fileItem;
......@@ -61,19 +55,12 @@ public:
void clear();
Qt::DropActions supportedDropActions() const override
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::DropActions supportedDropActions() const override;
Qt::ItemFlags flags(const QModelIndex &) const override;
QMimeData *mimeData(const QModelIndexList &) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
Q_UNUSED(parent);
return 6;
}
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
......@@ -81,10 +68,7 @@ public:
KFindItem itemAtIndex(const QModelIndex &index) const;
QList<KFindItem> getItemList() const
{
return m_itemList;
}
QList<KFindItem> getItemList() const;
private:
QList<KFindItem> m_itemList;
......@@ -110,7 +94,7 @@ class KFindTreeView : public QTreeView
Q_OBJECT
public:
explicit KFindTreeView(QWidget *parent, KfindDlg *findDialog);
~KFindTreeView();
~KFindTreeView() override;
void beginSearch(const QUrl &baseUrl);
void endSearch();
......@@ -118,19 +102,13 @@ public:
void insertItems(const QList< QPair<KFileItem, QString> > &);
void removeItem(const QUrl &url);
bool isInserted(const QUrl &url)
{
return m_model->isInserted(url);
}
bool isInserted(const QUrl &url) const;
QString reducedDir(const QString &fullDir);
int itemCount()
{
return m_model->rowCount();
}
int itemCount() const;
QList<QUrl> selectedUrls();
QList<QUrl> selectedUrls() const;
public Q_SLOTS:
void copySelection();
......@@ -150,10 +128,7 @@ private Q_SLOTS:
void updateMouseButtons();
protected:
void dragMoveEvent(QDragMoveEvent *e) override
{
e->accept();
}
void dragMoveEvent(QDragMoveEvent *e) override;
Q_SIGNALS:
void resultSelected(bool);
......@@ -165,14 +140,14 @@ private:
QDir m_baseDir;
KFindItemModel *m_model = nullptr;
KFindSortFilterProxyModel *m_proxyModel = nullptr;
KFindItemModel *const m_model;
KFindSortFilterProxyModel *const m_proxyModel;
KActionCollection *m_actionCollection = nullptr;
QMenu *m_contextMenu = nullptr;
Qt::MouseButtons m_mouseButtons;
KfindDlg *m_kfindDialog = nullptr;
KfindDlg *const m_kfindDialog;
};
#endif
......@@ -33,7 +33,7 @@ class KfindTabWidget : public QTabWidget
public:
explicit KfindTabWidget(QWidget *parent = nullptr);
virtual ~KfindTabWidget();
~KfindTabWidget() override;
void setQuery(class KQuery *query);
void setDefaults();
......
......@@ -28,7 +28,7 @@ class KQuery : public QObject
public:
explicit KQuery(QObject *parent = nullptr);
~KQuery();
~KQuery() override;
/* Functions to set Query requirements */
void setSizeRange(int mode, KIO::filesize_t value1, KIO::filesize_t value2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment