work save
This commit is contained in:
parent
7ebcc2d635
commit
9e5ce0a8ba
|
@ -2468,8 +2468,8 @@ void MainWindow::buildContextMenus()
|
|||
if (!current.isValid()) {
|
||||
return;
|
||||
}
|
||||
ProjectLegacyModelNode * node = static_cast<ProjectLegacyModelNode*>(current.internalPointer());
|
||||
PProjectLegacyModelNode folderNode = mProject->pointerToNode(node);
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
|
||||
PProjectModelNode folderNode = mProject->pointerToNode(node);
|
||||
if (!folderNode)
|
||||
folderNode = mProject->rootNode();
|
||||
if (folderNode->unitIndex>=0)
|
||||
|
@ -2511,8 +2511,8 @@ void MainWindow::buildContextMenus()
|
|||
if (!current.isValid()) {
|
||||
return;
|
||||
}
|
||||
ProjectLegacyModelNode * node = static_cast<ProjectLegacyModelNode*>(current.internalPointer());
|
||||
PProjectLegacyModelNode folderNode = mProject->pointerToNode(node);
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
|
||||
PProjectModelNode folderNode = mProject->pointerToNode(node);
|
||||
if (!folderNode)
|
||||
return;
|
||||
if (folderNode->unitIndex>=0)
|
||||
|
@ -2900,8 +2900,8 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
|
|||
int unitIndex = -1;
|
||||
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->selectionModel()->currentIndex());
|
||||
if (current.isValid() && mProject) {
|
||||
ProjectLegacyModelNode * node = static_cast<ProjectLegacyModelNode*>(current.internalPointer());
|
||||
PProjectLegacyModelNode pNode = mProject->pointerToNode(node);
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
|
||||
PProjectModelNode pNode = mProject->pointerToNode(node);
|
||||
if (pNode) {
|
||||
unitIndex = pNode->unitIndex;
|
||||
onFolder = (unitIndex<0);
|
||||
|
@ -3532,11 +3532,11 @@ void MainWindow::updateProjectView()
|
|||
if (mProjectProxyModel->sourceModel()!=mProject->model()) {
|
||||
mProjectProxyModel->setSourceModel(mProject->model());
|
||||
mProjectProxyModel->sort(0);
|
||||
connect(mProject->model(), &ProjectLegacyModel::dataChanged,
|
||||
connect(mProject->model(), &ProjectModel::dataChanged,
|
||||
this, &MainWindow::invalidateProjectProxyModel);
|
||||
connect(mProject->model(), &ProjectLegacyModel::rowsRemoved,
|
||||
connect(mProject->model(), &ProjectModel::rowsRemoved,
|
||||
this, &MainWindow::invalidateProjectProxyModel);
|
||||
connect(mProject->model(), &ProjectLegacyModel::rowsInserted,
|
||||
connect(mProject->model(), &ProjectModel::rowsInserted,
|
||||
this, &MainWindow::invalidateProjectProxyModel);
|
||||
connect(mProject->model(), &QAbstractItemModel::modelReset,
|
||||
ui->projectView,&QTreeView::expandAll);
|
||||
|
@ -4096,7 +4096,7 @@ void MainWindow::onOJProblemCaseFinished(const QString& id, int current, int tot
|
|||
updateProblemTitle();
|
||||
}
|
||||
|
||||
void MainWindow::onOJProblemCaseNewOutputGetted(const QString &id, const QString &line)
|
||||
void MainWindow::onOJProblemCaseNewOutputGetted(const QString &/* id */, const QString &line)
|
||||
{
|
||||
ui->txtProblemCaseOutput->appendPlainText(line);
|
||||
}
|
||||
|
@ -4953,7 +4953,7 @@ void MainWindow::on_projectView_doubleClicked(const QModelIndex &index)
|
|||
QModelIndex sourceIndex = mProjectProxyModel->mapToSource(index);
|
||||
if (!sourceIndex.isValid())
|
||||
return;
|
||||
ProjectLegacyModelNode * node = static_cast<ProjectLegacyModelNode*>(sourceIndex.internalPointer());
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(sourceIndex.internalPointer());
|
||||
if (!node)
|
||||
return;
|
||||
if (node->unitIndex>=0) {
|
||||
|
@ -5106,11 +5106,11 @@ void MainWindow::on_actionAdd_to_project_triggered()
|
|||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
if (dialog.exec()) {
|
||||
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
|
||||
ProjectLegacyModelNode * node = nullptr;
|
||||
ProjectModelNode * node = nullptr;
|
||||
if (current.isValid()) {
|
||||
node = static_cast<ProjectLegacyModelNode*>(current.internalPointer());
|
||||
node = static_cast<ProjectModelNode*>(current.internalPointer());
|
||||
}
|
||||
PProjectLegacyModelNode folderNode = mProject->pointerToNode(node);
|
||||
PProjectModelNode folderNode = mProject->pointerToNode(node);
|
||||
foreach (const QString& filename, dialog.selectedFiles()) {
|
||||
mProject->addUnit(filename,folderNode,false);
|
||||
mProject->cppParser()->addFileToScan(filename);
|
||||
|
@ -5135,8 +5135,8 @@ void MainWindow::on_actionRemove_from_project_triggered()
|
|||
if (!index.isValid())
|
||||
continue;
|
||||
QModelIndex realIndex = mProjectProxyModel->mapToSource(index);
|
||||
ProjectLegacyModelNode * node = static_cast<ProjectLegacyModelNode*>(realIndex.internalPointer());
|
||||
PProjectLegacyModelNode folderNode = mProject->pointerToNode(node);
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(realIndex.internalPointer());
|
||||
PProjectModelNode folderNode = mProject->pointerToNode(node);
|
||||
if (!folderNode)
|
||||
continue;
|
||||
selected.insert(folderNode->unitIndex);
|
||||
|
@ -5326,9 +5326,9 @@ void MainWindow::newProjectUnitFile()
|
|||
return;
|
||||
int idx = -1;
|
||||
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
|
||||
ProjectLegacyModelNode * node = nullptr;
|
||||
ProjectModelNode * node = nullptr;
|
||||
if (current.isValid()) {
|
||||
node = static_cast<ProjectLegacyModelNode*>(current.internalPointer());
|
||||
node = static_cast<ProjectModelNode*>(current.internalPointer());
|
||||
}
|
||||
QString newFileName;
|
||||
do {
|
||||
|
|
|
@ -207,9 +207,9 @@ void Project::setModified(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
PFolderNode Project::makeNewFileNode(const QString &s, bool isFolder, PFolderNode newParent)
|
||||
PProjectModelNode Project::makeNewFileNode(const QString &s, bool isFolder, PProjectModelNode newParent)
|
||||
{
|
||||
PFolderNode node = std::make_shared<FolderNode>();
|
||||
PProjectModelNode node = std::make_shared<ProjectModelNode>();
|
||||
if (!newParent) {
|
||||
newParent = mNode;
|
||||
}
|
||||
|
@ -224,16 +224,16 @@ PFolderNode Project::makeNewFileNode(const QString &s, bool isFolder, PFolderNod
|
|||
return node;
|
||||
}
|
||||
|
||||
PFolderNode Project::makeProjectNode()
|
||||
PProjectModelNode Project::makeProjectNode()
|
||||
{
|
||||
PFolderNode node = std::make_shared<FolderNode>();
|
||||
PProjectModelNode node = std::make_shared<ProjectModelNode>();
|
||||
node->text = mName;
|
||||
node->level = 0;
|
||||
node->unitIndex = -1;
|
||||
return node;
|
||||
}
|
||||
|
||||
PProjectUnit Project::newUnit(PFolderNode parentNode, const QString& customFileName)
|
||||
PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& customFileName)
|
||||
{
|
||||
PProjectUnit newUnit = std::make_shared<ProjectUnit>(this);
|
||||
|
||||
|
@ -315,17 +315,23 @@ void Project::rebuildNodes()
|
|||
mNode->children.clear();
|
||||
|
||||
// Recreate everything
|
||||
createFolderNodes();
|
||||
switch(mOptions.modelType) {
|
||||
case ProjectModelType::Custom:
|
||||
createFolderNodes();
|
||||
|
||||
for (int idx=0;idx<mUnits.count();idx++) {
|
||||
mUnits[idx]->setNode(
|
||||
makeNewFileNode(
|
||||
extractRelativePath(filename(),mUnits[idx]->fileName()),
|
||||
false,
|
||||
folderNodeFromName(mUnits[idx]->folder())
|
||||
)
|
||||
);
|
||||
mUnits[idx]->node()->unitIndex = idx;
|
||||
for (int idx=0;idx<mUnits.count();idx++) {
|
||||
mUnits[idx]->setNode(
|
||||
makeNewFileNode(
|
||||
extractRelativePath(filename(),mUnits[idx]->fileName()),
|
||||
false,
|
||||
folderNodeFromName(mUnits[idx]->folder())
|
||||
)
|
||||
);
|
||||
mUnits[idx]->node()->unitIndex = idx;
|
||||
}
|
||||
break;
|
||||
case ProjectModelType::FileSystem:
|
||||
createFileSystemFolderNodes();
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,8 +364,8 @@ bool Project::removeUnit(int index, bool doClose , bool removeFile)
|
|||
}
|
||||
|
||||
//if not fUnits.GetItem(index).fNew then
|
||||
PFolderNode node = unit->node();
|
||||
PFolderNode parent = node->parent.lock();
|
||||
PProjectModelNode node = unit->node();
|
||||
PProjectModelNode parent = node->parent.lock();
|
||||
if (parent) {
|
||||
parent->children.removeAll(node);
|
||||
}
|
||||
|
@ -369,7 +375,7 @@ bool Project::removeUnit(int index, bool doClose , bool removeFile)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Project::removeFolder(PFolderNode node)
|
||||
bool Project::removeFolder(PProjectModelNode node)
|
||||
{
|
||||
mModel.beginUpdate();
|
||||
auto action = finally([this]{
|
||||
|
@ -627,21 +633,21 @@ void Project::updateNodeIndexes()
|
|||
mUnits[idx]->node()->unitIndex = idx;
|
||||
}
|
||||
|
||||
PFolderNode Project::pointerToNode(FolderNode *p, PFolderNode parent)
|
||||
PProjectModelNode Project::pointerToNode(ProjectModelNode *p, PProjectModelNode parent)
|
||||
{
|
||||
if (!parent) {
|
||||
parent = mNode;
|
||||
}
|
||||
if (p==mNode.get())
|
||||
return mNode;
|
||||
foreach (const PFolderNode& node , parent->children) {
|
||||
foreach (const PProjectModelNode& node , parent->children) {
|
||||
if (node.get()==p)
|
||||
return node;
|
||||
PFolderNode result = pointerToNode(p,node);
|
||||
PProjectModelNode result = pointerToNode(p,node);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
return PFolderNode();
|
||||
return PProjectModelNode();
|
||||
}
|
||||
|
||||
void Project::setCompilerSet(int compilerSetIndex)
|
||||
|
@ -767,6 +773,7 @@ void Project::saveOptions()
|
|||
ini.SetLongValue("Project","StaticLink", mOptions.staticLink);
|
||||
ini.SetLongValue("Project","AddCharset", mOptions.addCharset);
|
||||
ini.SetValue("Project","Encoding",toByteArray(mOptions.encoding));
|
||||
ini.SetLongValue("Project","ModelType", (int)mOptions.modelType);
|
||||
//for Red Panda Dev C++ 6 compatibility
|
||||
ini.SetLongValue("Project","UseUTF8",mOptions.encoding == ENCODING_UTF8);
|
||||
|
||||
|
@ -815,7 +822,7 @@ void Project::addFolder(const QString &s)
|
|||
}
|
||||
}
|
||||
|
||||
PProjectUnit Project::addUnit(const QString &inFileName, PFolderNode parentNode, bool rebuild)
|
||||
PProjectUnit Project::addUnit(const QString &inFileName, PProjectModelNode parentNode, bool rebuild)
|
||||
{
|
||||
PProjectUnit newUnit;
|
||||
// Don't add if it already exists
|
||||
|
@ -1223,11 +1230,11 @@ void Project::createFolderNodes()
|
|||
{
|
||||
mFolderNodes.clear();
|
||||
for (int idx=0;idx<mFolders.count();idx++) {
|
||||
PFolderNode node = mNode;
|
||||
PProjectModelNode node = mNode;
|
||||
QString s = mFolders[idx];
|
||||
int i = s.indexOf('/');
|
||||
while (i>=0) {
|
||||
PFolderNode findnode;
|
||||
PProjectModelNode findnode;
|
||||
for (int c=0;c<node->children.count();c++) {
|
||||
if (node->children[c]->text == s.mid(0,i))
|
||||
findnode = node->children[c];
|
||||
|
@ -1246,6 +1253,21 @@ void Project::createFolderNodes()
|
|||
}
|
||||
}
|
||||
|
||||
void Project::createFileSystemFolderNodes()
|
||||
{
|
||||
mFolderNodes.clear();
|
||||
PProjectModelNode node = makeNewFileNode(tr("Headers"),true,mNode);
|
||||
createFileSystemFolderNode(folder(),node);
|
||||
mFolderNodes.append(node);
|
||||
node = makeNewFileNode(tr("Sources"),true,mNode);
|
||||
createFileSystemFolderNode(folder(),node);
|
||||
mFolderNodes.append(node);
|
||||
node = makeNewFileNode(tr("Sources"),true,mNode);
|
||||
createFileSystemFolderNode(folder(),node);
|
||||
mFolderNodes.append(node);
|
||||
|
||||
}
|
||||
|
||||
void Project::doAutoOpen()
|
||||
{
|
||||
loadLayout();
|
||||
|
@ -1260,7 +1282,7 @@ bool Project::fileAlreadyExists(const QString &s)
|
|||
return false;
|
||||
}
|
||||
|
||||
PFolderNode Project::folderNodeFromName(const QString &name)
|
||||
PProjectModelNode Project::folderNodeFromName(const QString &name)
|
||||
{
|
||||
int index = mFolders.indexOf(name);
|
||||
if (index>=0) {
|
||||
|
@ -1282,7 +1304,7 @@ char Project::getCompilerOption(const QString &optionString)
|
|||
return '0';
|
||||
}
|
||||
|
||||
QString Project::getFolderPath(PFolderNode node)
|
||||
QString Project::getFolderPath(PProjectModelNode node)
|
||||
{
|
||||
QString result;
|
||||
if (!node)
|
||||
|
@ -1291,7 +1313,7 @@ QString Project::getFolderPath(PFolderNode node)
|
|||
if (node->unitIndex>=0) // not a folder
|
||||
return result;
|
||||
|
||||
PFolderNode p = node;
|
||||
PProjectModelNode p = node;
|
||||
while (p && p->unitIndex==-1 && p!=mNode) {
|
||||
if (!result.isEmpty())
|
||||
result = p->text + "/" + result;
|
||||
|
@ -1400,6 +1422,7 @@ void Project::loadOptions(SimpleIni& ini)
|
|||
mOptions.includeVersionInfo = ini.GetBoolValue("Project", "IncludeVersionInfo", false);
|
||||
mOptions.supportXPThemes = ini.GetBoolValue("Project", "SupportXPThemes", false);
|
||||
mOptions.compilerSet = ini.GetLongValue("Project", "CompilerSet", pSettings->compilerSets().defaultIndex());
|
||||
mOptions.modelType = (ProjectModelType)ini.GetLongValue("Project", "ModelType", (int)ProjectModelType::Custom);
|
||||
|
||||
if (mOptions.compilerSet >= pSettings->compilerSets().size()
|
||||
|| mOptions.compilerSet < 0) { // TODO: change from indices to names
|
||||
|
@ -1544,13 +1567,13 @@ int Project::indexInUnits(const Editor *editor) const
|
|||
return indexInUnits(editor->filename());
|
||||
}
|
||||
|
||||
void Project::removeFolderRecurse(PFolderNode node)
|
||||
void Project::removeFolderRecurse(PProjectModelNode node)
|
||||
{
|
||||
if (!node)
|
||||
return ;
|
||||
// Recursively remove folders
|
||||
for (int i=node->children.count()-1;i>=0;i++) {
|
||||
PFolderNode childNode = node->children[i];
|
||||
PProjectModelNode childNode = node->children[i];
|
||||
// Remove folder inside folder
|
||||
if (childNode->unitIndex<0 && childNode->level>0) {
|
||||
removeFolderRecurse(childNode);
|
||||
|
@ -1563,16 +1586,16 @@ void Project::removeFolderRecurse(PFolderNode node)
|
|||
}
|
||||
}
|
||||
|
||||
PFolderNode parent = node->parent.lock();
|
||||
PProjectModelNode parent = node->parent.lock();
|
||||
if (parent) {
|
||||
parent->children.removeAll(node);
|
||||
}
|
||||
}
|
||||
|
||||
void Project::updateFolderNode(PFolderNode node)
|
||||
void Project::updateFolderNode(PProjectModelNode node)
|
||||
{
|
||||
for (int i=0;i<node->children.count();i++){
|
||||
PFolderNode child = node->children[i];
|
||||
PProjectModelNode child = node->children[i];
|
||||
if (child->unitIndex<0) {
|
||||
mFolders.append(getFolderPath(child));
|
||||
updateFolderNode(child);
|
||||
|
@ -1603,12 +1626,12 @@ ProjectOptions &Project::options()
|
|||
return mOptions;
|
||||
}
|
||||
|
||||
ProjectLegacyModel *Project::legacyModel()
|
||||
ProjectModel *Project::model()
|
||||
{
|
||||
return &mModel;
|
||||
}
|
||||
|
||||
const PFolderNode &Project::rootNode() const
|
||||
const PProjectModelNode &Project::rootNode() const
|
||||
{
|
||||
return mNode;
|
||||
}
|
||||
|
@ -1812,24 +1835,24 @@ bool ProjectUnit::save()
|
|||
return result;
|
||||
}
|
||||
|
||||
PFolderNode &ProjectUnit::node()
|
||||
PProjectModelNode &ProjectUnit::node()
|
||||
{
|
||||
return mNode;
|
||||
}
|
||||
|
||||
void ProjectUnit::setNode(const PFolderNode &newNode)
|
||||
void ProjectUnit::setNode(const PProjectModelNode &newNode)
|
||||
{
|
||||
mNode = newNode;
|
||||
}
|
||||
|
||||
ProjectLegacyModel::ProjectLegacyModel(Project *project, QObject *parent):
|
||||
ProjectModel::ProjectModel(Project *project, QObject *parent):
|
||||
QAbstractItemModel(parent),
|
||||
mProject(project)
|
||||
{
|
||||
mUpdateCount = 0;
|
||||
}
|
||||
|
||||
void ProjectLegacyModel::beginUpdate()
|
||||
void ProjectModel::beginUpdate()
|
||||
{
|
||||
if (mUpdateCount==0) {
|
||||
beginResetModel();
|
||||
|
@ -1837,7 +1860,7 @@ void ProjectLegacyModel::beginUpdate()
|
|||
mUpdateCount++;
|
||||
}
|
||||
|
||||
void ProjectLegacyModel::endUpdate()
|
||||
void ProjectModel::endUpdate()
|
||||
{
|
||||
mUpdateCount--;
|
||||
if (mUpdateCount==0) {
|
||||
|
@ -1845,17 +1868,17 @@ void ProjectLegacyModel::endUpdate()
|
|||
}
|
||||
}
|
||||
|
||||
Project *ProjectLegacyModel::project() const
|
||||
Project *ProjectModel::project() const
|
||||
{
|
||||
return mProject;
|
||||
}
|
||||
|
||||
QModelIndex ProjectLegacyModel::index(int row, int column, const QModelIndex &parent) const
|
||||
QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (!parent.isValid()) {
|
||||
return createIndex(row,column,mProject->rootNode().get());
|
||||
}
|
||||
FolderNode* parentNode = static_cast<FolderNode*>(parent.internalPointer());
|
||||
ProjectModelNode* parentNode = static_cast<ProjectModelNode*>(parent.internalPointer());
|
||||
if (!parentNode) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
@ -1864,21 +1887,21 @@ QModelIndex ProjectLegacyModel::index(int row, int column, const QModelIndex &pa
|
|||
return createIndex(row,column,parentNode->children[row].get());
|
||||
}
|
||||
|
||||
QModelIndex ProjectLegacyModel::parent(const QModelIndex &child) const
|
||||
QModelIndex ProjectModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
if (!child.isValid())
|
||||
return QModelIndex();
|
||||
FolderNode * node = static_cast<FolderNode*>(child.internalPointer());
|
||||
ProjectModelNode * node = static_cast<ProjectModelNode*>(child.internalPointer());
|
||||
if (!node)
|
||||
return QModelIndex();
|
||||
return getParentIndex(node);
|
||||
}
|
||||
|
||||
int ProjectLegacyModel::rowCount(const QModelIndex &parent) const
|
||||
int ProjectModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!parent.isValid())
|
||||
return 1;
|
||||
FolderNode* p = static_cast<FolderNode*>(parent.internalPointer());
|
||||
ProjectModelNode* p = static_cast<ProjectModelNode*>(parent.internalPointer());
|
||||
if (p) {
|
||||
return p->children.count();
|
||||
} else {
|
||||
|
@ -1886,16 +1909,16 @@ int ProjectLegacyModel::rowCount(const QModelIndex &parent) const
|
|||
}
|
||||
}
|
||||
|
||||
int ProjectLegacyModel::columnCount(const QModelIndex &) const
|
||||
int ProjectModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant ProjectLegacyModel::data(const QModelIndex &index, int role) const
|
||||
QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
|
||||
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
||||
if (!p)
|
||||
return QVariant();
|
||||
if (role == Qt::DisplayRole || role==Qt::EditRole) {
|
||||
|
@ -1914,11 +1937,11 @@ QVariant ProjectLegacyModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectLegacyModel::flags(const QModelIndex &index) const
|
||||
Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
|
||||
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
||||
if (!p)
|
||||
return Qt::NoItemFlags;
|
||||
if (p==mProject->rootNode().get())
|
||||
|
@ -1931,12 +1954,12 @@ Qt::ItemFlags ProjectLegacyModel::flags(const QModelIndex &index) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
bool ProjectLegacyModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
|
||||
PFolderNode node = mProject->pointerToNode(p);
|
||||
ProjectModelNode* p = static_cast<ProjectModelNode*>(index.internalPointer());
|
||||
PProjectModelNode node = mProject->pointerToNode(p);
|
||||
if (!node)
|
||||
return false;
|
||||
if (role == Qt::EditRole) {
|
||||
|
@ -2033,12 +2056,12 @@ bool ProjectLegacyModel::setData(const QModelIndex &index, const QVariant &value
|
|||
return false;
|
||||
}
|
||||
|
||||
QModelIndex ProjectLegacyModel::getParentIndex(FolderNode * node) const
|
||||
QModelIndex ProjectModel::getParentIndex(ProjectModelNode * node) const
|
||||
{
|
||||
PFolderNode parent = node->parent.lock();
|
||||
PProjectModelNode parent = node->parent.lock();
|
||||
if (!parent) // root node
|
||||
return QModelIndex();
|
||||
PFolderNode grand = parent->parent.lock();
|
||||
PProjectModelNode grand = parent->parent.lock();
|
||||
if (!grand) {
|
||||
return createIndex(0,0,parent.get());
|
||||
}
|
||||
|
@ -2049,7 +2072,7 @@ QModelIndex ProjectLegacyModel::getParentIndex(FolderNode * node) const
|
|||
return createIndex(row,0,parent.get());
|
||||
}
|
||||
|
||||
bool ProjectLegacyModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) const
|
||||
bool ProjectModel::canDropMimeData(const QMimeData * data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) const
|
||||
{
|
||||
|
||||
if (!data || action != Qt::MoveAction)
|
||||
|
@ -2070,8 +2093,8 @@ bool ProjectLegacyModel::canDropMimeData(const QMimeData * data, Qt::DropAction
|
|||
// } else {
|
||||
// idx= index(row,column,parent);
|
||||
// }
|
||||
FolderNode* p= static_cast<FolderNode*>(idx.internalPointer());
|
||||
PFolderNode node = mProject->pointerToNode(p);
|
||||
ProjectModelNode* p= static_cast<ProjectModelNode*>(idx.internalPointer());
|
||||
PProjectModelNode node = mProject->pointerToNode(p);
|
||||
if (node->unitIndex>=0)
|
||||
return false;
|
||||
QByteArray encoded = data->data(format);
|
||||
|
@ -2080,21 +2103,21 @@ bool ProjectLegacyModel::canDropMimeData(const QMimeData * data, Qt::DropAction
|
|||
qint32 r, c;
|
||||
quintptr v;
|
||||
stream >> r >> c >> v;
|
||||
FolderNode* droppedPointer= (FolderNode*)(v);
|
||||
PFolderNode droppedNode = mProject->pointerToNode(droppedPointer);
|
||||
PFolderNode oldParent = droppedNode->parent.lock();
|
||||
ProjectModelNode* droppedPointer= (ProjectModelNode*)(v);
|
||||
PProjectModelNode droppedNode = mProject->pointerToNode(droppedPointer);
|
||||
PProjectModelNode oldParent = droppedNode->parent.lock();
|
||||
if (oldParent == node)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::DropActions ProjectLegacyModel::supportedDropActions() const
|
||||
Qt::DropActions ProjectModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
bool ProjectLegacyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent)
|
||||
bool ProjectModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent)
|
||||
{
|
||||
// check if the action is supported
|
||||
if (!data || action != Qt::MoveAction)
|
||||
|
@ -2109,8 +2132,8 @@ bool ProjectLegacyModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
|
|||
|
||||
if (!parent.isValid())
|
||||
return false;
|
||||
FolderNode* p= static_cast<FolderNode*>(parent.internalPointer());
|
||||
PFolderNode node = mProject->pointerToNode(p);
|
||||
ProjectModelNode* p= static_cast<ProjectModelNode*>(parent.internalPointer());
|
||||
PProjectModelNode node = mProject->pointerToNode(p);
|
||||
|
||||
QByteArray encoded = data->data(format);
|
||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||
|
@ -2127,9 +2150,9 @@ bool ProjectLegacyModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
|
|||
for (int i=pointers.count()-1;i>=0;i--) {
|
||||
int r = rows[i];
|
||||
intptr_t v = pointers[i];
|
||||
FolderNode* droppedPointer= (FolderNode*)(v);
|
||||
PFolderNode droppedNode = mProject->pointerToNode(droppedPointer);
|
||||
PFolderNode oldParent = droppedNode->parent.lock();
|
||||
ProjectModelNode* droppedPointer= (ProjectModelNode*)(v);
|
||||
PProjectModelNode droppedNode = mProject->pointerToNode(droppedPointer);
|
||||
PProjectModelNode oldParent = droppedNode->parent.lock();
|
||||
QModelIndex oldParentIndex = getParentIndex(droppedPointer);
|
||||
beginRemoveRows(oldParentIndex,r,r);
|
||||
if (oldParent)
|
||||
|
@ -2151,7 +2174,7 @@ bool ProjectLegacyModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
|
|||
return false;
|
||||
}
|
||||
|
||||
QMimeData *ProjectLegacyModel::mimeData(const QModelIndexList &indexes) const
|
||||
QMimeData *ProjectModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
if (indexes.count() <= 0)
|
||||
return nullptr;
|
||||
|
@ -2166,7 +2189,7 @@ QMimeData *ProjectLegacyModel::mimeData(const QModelIndexList &indexes) const
|
|||
QList<QUrl> urls;
|
||||
for (; it != indexes.end(); ++it) {
|
||||
stream << (qint32)((*it).row()) << (qint32)((*it).column()) << (quintptr)((*it).internalPointer());
|
||||
FolderNode* p = static_cast<FolderNode*>((*it).internalPointer());
|
||||
ProjectModelNode* p = static_cast<ProjectModelNode*>((*it).internalPointer());
|
||||
if (p && p->unitIndex>=0) {
|
||||
urls.append(QUrl::fromLocalFile(mProject->units()[p->unitIndex]->fileName()));
|
||||
}
|
||||
|
@ -2187,13 +2210,13 @@ bool ProjectModelSortFilterProxy::lessThan(const QModelIndex &source_left, const
|
|||
{
|
||||
if (!sourceModel())
|
||||
return false;
|
||||
ProjectLegacyModel* projectModel = dynamic_cast<ProjectLegacyModel*>(sourceModel());
|
||||
FolderNode* pLeft=nullptr;
|
||||
ProjectModel* projectModel = dynamic_cast<ProjectModel*>(sourceModel());
|
||||
ProjectModelNode* pLeft=nullptr;
|
||||
if (source_left.isValid())
|
||||
pLeft = static_cast<FolderNode*>(source_left.internalPointer());
|
||||
FolderNode* pRight=nullptr;
|
||||
pLeft = static_cast<ProjectModelNode*>(source_left.internalPointer());
|
||||
ProjectModelNode* pRight=nullptr;
|
||||
if (source_right.isValid())
|
||||
pRight = static_cast<FolderNode*>(source_right.internalPointer());
|
||||
pRight = static_cast<ProjectModelNode*>(source_right.internalPointer());
|
||||
if (!pLeft)
|
||||
return true;
|
||||
if (!pRight)
|
||||
|
@ -2204,14 +2227,3 @@ bool ProjectModelSortFilterProxy::lessThan(const QModelIndex &source_left, const
|
|||
return false;
|
||||
return QString::compare(pLeft->text, pRight->text)<0;
|
||||
}
|
||||
|
||||
ProjectModel::ProjectModel(Project *project, QObject *parent):QAbstractItemModel(parent),
|
||||
mProject(project)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Project *ProjectModel::project() const
|
||||
{
|
||||
return mProject;
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ class Project;
|
|||
class Editor;
|
||||
class CppParser;
|
||||
|
||||
struct ProjectLegacyModelNode;
|
||||
using PProjectLegacyModelNode = std::shared_ptr<ProjectLegacyModelNode>;
|
||||
struct ProjectLegacyModelNode {
|
||||
struct ProjectModelNode;
|
||||
using PProjectModelNode = std::shared_ptr<ProjectModelNode>;
|
||||
struct ProjectModelNode {
|
||||
QString text;
|
||||
std::weak_ptr<ProjectLegacyModelNode> parent;
|
||||
std::weak_ptr<ProjectModelNode> parent;
|
||||
int unitIndex;
|
||||
QList<PProjectLegacyModelNode> children;
|
||||
QList<PProjectModelNode> children;
|
||||
int level;
|
||||
};
|
||||
|
||||
|
@ -69,8 +69,8 @@ public:
|
|||
void setModified(bool value);
|
||||
bool save();
|
||||
|
||||
PProjectLegacyModelNode &node();
|
||||
void setNode(const PProjectLegacyModelNode &newNode);
|
||||
PProjectModelNode &node();
|
||||
void setNode(const PProjectModelNode &newNode);
|
||||
|
||||
private:
|
||||
Project* mParent;
|
||||
|
@ -85,25 +85,15 @@ private:
|
|||
bool mLink;
|
||||
int mPriority;
|
||||
QByteArray mEncoding;
|
||||
PProjectLegacyModelNode mNode;
|
||||
PProjectModelNode mNode;
|
||||
};
|
||||
|
||||
using PProjectUnit = std::shared_ptr<ProjectUnit>;
|
||||
|
||||
class ProjectModel: public QAbstractItemModel {
|
||||
class ProjectModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProjectModel(Project* project, QObject* parent = nullptr);
|
||||
Project *project() const;
|
||||
|
||||
private:
|
||||
Project* mProject;
|
||||
};
|
||||
|
||||
class ProjectLegacyModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProjectLegacyModel(Project* project, QObject* parent=nullptr);
|
||||
explicit ProjectModel(Project* project, QObject* parent=nullptr);
|
||||
void beginUpdate();
|
||||
void endUpdate();
|
||||
private:
|
||||
|
@ -121,7 +111,7 @@ public:
|
|||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
|
||||
private:
|
||||
QModelIndex getParentIndex(ProjectLegacyModelNode * node) const;
|
||||
QModelIndex getParentIndex(ProjectModelNode * node) const;
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||
|
@ -158,7 +148,7 @@ public:
|
|||
|
||||
void addFolder(const QString& s);
|
||||
PProjectUnit addUnit(const QString& inFileName,
|
||||
PProjectLegacyModelNode parentNode,
|
||||
PProjectModelNode parentNode,
|
||||
bool rebuild);
|
||||
QString folder();
|
||||
void buildPrivateResource(bool forceSave=false);
|
||||
|
@ -167,9 +157,9 @@ public:
|
|||
void createFolderNodes();
|
||||
void doAutoOpen();
|
||||
bool fileAlreadyExists(const QString& s);
|
||||
PProjectLegacyModelNode folderNodeFromName(const QString& name);
|
||||
PProjectModelNode folderNodeFromName(const QString& name);
|
||||
char getCompilerOption(const QString& optionString);
|
||||
QString getFolderPath(PProjectLegacyModelNode node);
|
||||
QString getFolderPath(PProjectModelNode node);
|
||||
int getUnitFromString(const QString& s);
|
||||
void incrementBuildNumber();
|
||||
int indexInUnits(const QString& fileName) const;
|
||||
|
@ -178,14 +168,14 @@ public:
|
|||
void loadLayout(); // load all [UnitX]
|
||||
void loadOptions(SimpleIni& ini);
|
||||
void loadUnitLayout(Editor *e, int index); // load single [UnitX] cursor positions
|
||||
PProjectLegacyModelNode makeNewFileNode(const QString& s, bool isFolder, PProjectLegacyModelNode newParent);
|
||||
PProjectLegacyModelNode makeProjectNode();
|
||||
PProjectUnit newUnit(PProjectLegacyModelNode parentNode,
|
||||
PProjectModelNode makeNewFileNode(const QString& s, bool isFolder, PProjectModelNode newParent);
|
||||
PProjectModelNode makeProjectNode();
|
||||
PProjectUnit newUnit(PProjectModelNode parentNode,
|
||||
const QString& customFileName="");
|
||||
Editor* openUnit(int index);
|
||||
void rebuildNodes();
|
||||
bool removeUnit(int index, bool doClose, bool removeFile = false);
|
||||
bool removeFolder(PProjectLegacyModelNode node);
|
||||
bool removeFolder(PProjectModelNode node);
|
||||
void resetParserProjectFiles();
|
||||
void saveAll(); // save [Project] and all [UnitX]
|
||||
void saveLayout(); // save all [UnitX]
|
||||
|
@ -201,7 +191,7 @@ public:
|
|||
void sortUnitsByAlpha();
|
||||
void updateFolders();
|
||||
void updateNodeIndexes();
|
||||
PProjectLegacyModelNode pointerToNode(ProjectLegacyModelNode * p, PProjectLegacyModelNode parent=PProjectLegacyModelNode());
|
||||
PProjectModelNode pointerToNode(ProjectModelNode * p, PProjectModelNode parent=PProjectModelNode());
|
||||
void setCompilerSet(int compilerSetIndex);
|
||||
|
||||
//void showOptions();
|
||||
|
@ -214,11 +204,11 @@ public:
|
|||
const QString &name() const;
|
||||
void setName(const QString &newName);
|
||||
|
||||
const PProjectLegacyModelNode &rootNode() const;
|
||||
const PProjectModelNode &rootNode() const;
|
||||
|
||||
ProjectOptions &options();
|
||||
|
||||
ProjectLegacyModel* legacyModel() ;
|
||||
ProjectModel* model() ;
|
||||
|
||||
const QList<PProjectUnit> &units() const;
|
||||
|
||||
|
@ -227,8 +217,8 @@ signals:
|
|||
void modifyChanged(bool value);
|
||||
private:
|
||||
void open();
|
||||
void removeFolderRecurse(PProjectLegacyModelNode node);
|
||||
void updateFolderNode(PProjectLegacyModelNode node);
|
||||
void removeFolderRecurse(PProjectModelNode node);
|
||||
void updateFolderNode(PProjectModelNode node);
|
||||
void updateCompilerSetType();
|
||||
|
||||
private:
|
||||
|
@ -239,9 +229,9 @@ private:
|
|||
bool mModified;
|
||||
QStringList mFolders;
|
||||
std::shared_ptr<CppParser> mParser;
|
||||
QList<PProjectLegacyModelNode> mFolderNodes;
|
||||
PProjectLegacyModelNode mNode;
|
||||
ProjectLegacyModel mModel;
|
||||
QList<PProjectModelNode> mFolderNodes;
|
||||
PProjectModelNode mNode;
|
||||
ProjectModel mModel;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
||||
|
|
|
@ -52,4 +52,5 @@ ProjectOptions::ProjectOptions()
|
|||
compilerSetType = 0;
|
||||
staticLink = true;
|
||||
addCharset = true;
|
||||
modelType = ProjectModelType::FileSystem;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
enum class ProjectModelType {
|
||||
FileSystem,
|
||||
Custom
|
||||
};
|
||||
|
||||
enum class ProjectType {
|
||||
GUI=0,
|
||||
Console=1,
|
||||
|
@ -83,5 +88,6 @@ struct ProjectOptions{
|
|||
bool staticLink;
|
||||
bool addCharset;
|
||||
QString encoding;
|
||||
ProjectModelType modelType;
|
||||
};
|
||||
#endif // PROJECTOPTIONS_H
|
||||
|
|
|
@ -68,7 +68,7 @@ PProjectUnit ProjectFilesWidget::currentUnit()
|
|||
QModelIndex index = ui->treeProject->currentIndex();
|
||||
if (!index.isValid())
|
||||
return PProjectUnit();
|
||||
ProjectLegacyModelNode* node = static_cast<ProjectLegacyModelNode*>(index.internalPointer());
|
||||
ProjectModelNode* node = static_cast<ProjectModelNode*>(index.internalPointer());
|
||||
if (!node)
|
||||
return PProjectUnit();
|
||||
int i = node->unitIndex;
|
||||
|
@ -136,7 +136,7 @@ void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index)
|
|||
disableFileOptions();
|
||||
return ;
|
||||
}
|
||||
ProjectLegacyModelNode* node = static_cast<ProjectLegacyModelNode*>(index.internalPointer());
|
||||
ProjectModelNode* node = static_cast<ProjectModelNode*>(index.internalPointer());
|
||||
if (!node) {
|
||||
disableFileOptions();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue