File indexing completed on 2024-04-28 04:34:27

0001 /*
0002  * This file is part of KDevelop Krazy2 Plugin.
0003  *
0004  * Copyright 2012 Daniel Calviño Sánchez <danxuliu@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License
0008  * as published by the Free Software Foundation; either version 2
0009  * of the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef SELECTPATHSWIDGET_H
0021 #define SELECTPATHSWIDGET_H
0022 
0023 #include <QWidget>
0024 
0025 class QStringListModel;
0026 
0027 namespace Ui {
0028 class SelectPathsWidget;
0029 }
0030 
0031 /**
0032  * Widget to select files and directories.
0033  * The widget contains a list with the selected paths and buttons to add new
0034  * paths or remove one or more of the already selected ones. Only local files
0035  * or directories can be added.
0036  *
0037  * The paths in the list are sorted alphabetically. Directories include a
0038  * trailing '/' to be able to tell them apart from files.
0039  */
0040 class SelectPathsWidget: public QWidget {
0041 Q_OBJECT
0042 public:
0043 
0044     /**
0045      * Creates a new SelectPathsWidget with the given parent.
0046      *
0047      * @param paths The already selected paths.
0048      * @param parent The parent widget.
0049      */
0050     explicit SelectPathsWidget(const QStringList& paths, QWidget* parent = nullptr);
0051 
0052     /**
0053      * Destroys this SelectPathsWidget.
0054      */
0055     ~SelectPathsWidget() override;
0056 
0057     /**
0058      * Returns the selected files and directories.
0059      *
0060      * @return The selected files and directories.
0061      */
0062     QStringList selectedFilesAndDirectories() const;
0063 
0064     /**
0065      * Add the given paths to the selected paths.
0066      *
0067      * @param paths The paths to add.
0068      */
0069     void addPaths(const QStringList& paths);
0070     void clearPaths();
0071 
0072 private:
0073 
0074     /**
0075      * The QtDesigner UI file for this widget.
0076      */
0077     Ui::SelectPathsWidget* m_ui;
0078 
0079     /**
0080      * The list of selected paths.
0081      */
0082     QStringList m_paths;
0083 
0084     /**
0085      * The model to show the paths in the list view.
0086      */
0087     QStringListModel* m_pathsModel;
0088 
0089     /**
0090      * Updates the paths after a change.
0091      * The "Remove" button is disabled after an update.
0092      */
0093     void updatePaths();
0094 
0095 private Q_SLOTS:
0096 
0097     /**
0098      * Shows a dialog to select files and directories and adds them to the list.
0099      */
0100     void add();
0101 
0102     /**
0103      * Removes the currently selected paths, if any.
0104      */
0105     void remove();
0106 
0107     /**
0108      * Enables or disables the "Remove" button depending on whether there is any
0109      * path selected or not.
0110      */
0111     void handleSelectionChanged();
0112 
0113 };
0114 
0115 #endif