QT简易文件管理器

227 阅读9分钟

用QT写的简单的文件管理器

image.png

//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <stdio.h>
#include<io.h>
#include<QTreeWidgetItem>
#include<stdlib.h>
#include<malloc.h>
#include<map>
#include<fstream>
#include <time.h>
#include<string>
#include<QDebug>
#include"stringop.h"
using namespace std;
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    map<QTreeWidgetItem*,bool>memo;
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QTreeWidget *tree ;
    string path;
    stringOP sop;

    QTextEdit *TextEdit,*outTextEdit,*searchTextEdit,*openMethodTextEdit;
    QPushButton *pushButton,*outPushButton,*searchPushButton;

    QString Ss2Qs(string ss){
        return QString::fromLocal8Bit(ss.c_str());
    }
    string Qs2Ss(QString qs){
        return string((const char *)qs.toLocal8Bit().constData());
    }

    template<class T>
    void DfsListFolderFiles(const string path, T *parent,int deep);
    void removeItem(QTreeWidgetItem *item);
    void removeSelectedItems(QTreeWidget *treeWidget);
public slots:
    void myOnItemClicked(string path, QTreeWidgetItem *item, string fname);
    void on_itemClicked(QTreeWidgetItem *item, int column);
    void handleButtonClicked();
    void handleOutButtonClicked();
    void handleSearchButtonClicked();
    void on_itemDoubleClicked(QTreeWidgetItem *item, int column);
private:
    Ui::MainWindow *ui;
private slots:
    void handleItemClicked(QTreeWidgetItem *item, int column);

};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QLineEdit>
#include <QProcess>
#include <QPushButton>
#include <QSplitter>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include"treewidgetitemwrapper.h"
#include<QHBoxLayout>
#include<QSvgRenderer>


template<class T>
void MainWindow::DfsListFolderFiles(const string path,T *parent,int deep=2)
{   if (deep==0)return ;

    _finddata_t file_info;
    string current_path = path + "/*.*";
    long long handle = _findfirst(current_path.c_str(), &file_info);
    //返回值为-1则查找失败
    if (-1 == handle)
    {
        cout << "cannot match the path" << endl;
        return;
    }

    do{
        if ((file_info.attrib &( _A_SUBDIR|_A_ARCH))!=0)
        {
            //.是当前目录,..是上层目录,须排除掉这两种情况
            if (strcmp(file_info.name, "..") == 0 || strcmp(file_info.name, ".") == 0)continue;

            cout<<"Qs2Ss(searchTextEdit->toPlainText())="<<Qs2Ss(searchTextEdit->toPlainText())<<endl;
            if(sop.findPlaceWithRegex(Qs2Ss(searchTextEdit->toPlainText()),file_info.name,2).size()==0)continue;
            QTreeWidgetItem *item1 = new QTreeWidgetItem(parent, QStringList(Ss2Qs(file_info.name)));

            DfsListFolderFiles(path+"/"+file_info.name,item1,deep-1);
                QIcon icon;
                 if((file_info.attrib & _A_SUBDIR)!=0){

         icon.addPixmap(QPixmap(":/map/dir_f4ea2a.png"), QIcon::Normal, QIcon::On);//节点打开状态
         icon.addPixmap(QPixmap(":/map/dir_dbdbdb.png"), QIcon::Normal, QIcon::Off);//节点关闭状态
        }else{
         icon.addPixmap(QPixmap(":/map/file_1296db.png"), QIcon::Normal, QIcon::On);//节点打开状态
         icon.addPixmap(QPixmap(":/map/file_1296db.png"), QIcon::Normal, QIcon::Off);//节点关闭状态
                 }
                 item1->setIcon(0,icon);

    }} while (!_findnext(handle, &file_info));
   //关闭文件句柄
    _findclose(handle);
}

//递归删除节点
void MainWindow::removeItem(QTreeWidgetItem *item)
{
    int count = item->childCount();
    if(count==0)//没有子节点,直接删除
    {
        delete item;
        return;
    }

    for(int i=0; i<count; i++)
    {
        QTreeWidgetItem *childItem = item->child(0);//删除子节点
        removeItem(childItem);
    }
//    delete item;//最后将自己删除

}

//删除选中的节点及子节点
void  MainWindow::removeSelectedItems(QTreeWidget*treeWidget)
{
    QList<QTreeWidgetItem*> items = treeWidget->selectedItems();

    for (int i = 0; i < items.size(); ++i) {
        removeItem(items[i]);
    }
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QVBoxLayout* leftLayout = new QVBoxLayout;

    TextEdit = new QTextEdit(this);
    TextEdit->setAcceptDrops(false); // 关闭文本编辑框的拖拽功能
    TextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // 设置文本编辑框的尺寸策略
    TextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // 设置文本编辑框的垂直滚动条策略
    TextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // 设置文本编辑框的水平滚动条策略

    pushButton = new QPushButton("Open", this);

    outTextEdit = new QTextEdit(this);
    outTextEdit->setAcceptDrops(false);
    outTextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    outTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    outTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


    searchTextEdit = new QTextEdit(this);
    searchTextEdit->setAcceptDrops(false);
    searchTextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    searchTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    searchTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    searchTextEdit->setText(".*");

    openMethodTextEdit = new QTextEdit(this);
    openMethodTextEdit->setAcceptDrops(false);
    openMethodTextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    openMethodTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    openMethodTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    openMethodTextEdit->setText("D:/Program Files(x86)/quicklook/QuickLook-3.7.0/QuickLook.exe");


    leftLayout->addWidget(TextEdit);
    leftLayout->addWidget(pushButton);
    leftLayout->addWidget(outTextEdit);
    leftLayout->addWidget(searchTextEdit);
    leftLayout->addWidget(openMethodTextEdit);


    QWidget* leftWidget = new QWidget(this);
    leftWidget->setLayout(leftLayout);

    QSplitter *splitter = new QSplitter(this);
    splitter->setOrientation(Qt::Horizontal);

    splitter->addWidget(leftWidget);

    tree = new QTreeWidget(this);
    tree->setStyleSheet("background-color:#cfcfcf;");
    tree->setIndentation(40);
    tree->setIconSize(QSize(55, 24));

    path = "E:";

    splitter->addWidget(tree);
    splitter->setStretchFactor(0, 0);
    splitter->setStretchFactor(1, 1);

    setCentralWidget(splitter);
    this->setWindowIcon(QIcon(":/map/totoo.jpg"));

    connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
    connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(on_itemDoubleClicked(QTreeWidgetItem*, int)));

    connect(pushButton, &QPushButton::clicked, this, &MainWindow::handleButtonClicked);
//    connect(outPushButton, &QPushButton::clicked, this, &MainWindow::handleOutButtonClicked);
//    connect(searchPushButton, &QPushButton::clicked, this, &MainWindow::handleSearchButtonClicked);
}




void  MainWindow::handleSearchButtonClicked(){
    tree->clear();
    path= Qs2Ss(TextEdit->toPlainText());
    string searchText=Qs2Ss(searchTextEdit->toPlainText());

  cout<<"Path="<<path<<endl;
  DfsListFolderFiles(path,tree);

}


void  MainWindow::handleButtonClicked(){
    tree->clear();
    path= Qs2Ss(TextEdit->toPlainText());
  cout<<"Path="<<path<<endl;
  DfsListFolderFiles(path,tree);
}

void  MainWindow::handleOutButtonClicked(){
    QString program = "D:/Program Files(x86)/quicklook/QuickLook-3.7.0/QuickLook.exe";
    QStringList arguments;
    arguments << outTextEdit->toPlainText();

    QProcess *process = new QProcess(this);
    process->start(program, arguments);

}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::myOnItemClicked(string path,QTreeWidgetItem *item, string fname)
{    cout<<path + "./" + fname<<endl;
    this->DfsListFolderFiles(path + "./" + fname, item);
}

void MainWindow::on_itemClicked(QTreeWidgetItem* item, int column)
{
    QList<QString> pathList;

    QTreeWidgetItem* currentItem = item;
    while (currentItem)
    {
        QString currentValue = currentItem->text(column);
        pathList.prepend(currentValue);
        currentItem = currentItem->parent();
    }

    QString fullPath = Ss2Qs(path)+"/"+pathList.join("/");
    qDebug() << "Path from root to item: " << fullPath;

    string thisPath=Qs2Ss(fullPath);
    cout<< "Path from root to item: " <<thisPath;

    outTextEdit->clear();
    outTextEdit->setText(Ss2Qs(thisPath));

    _finddata_t file_info;
    string current_path =thisPath;
    long long handle = _findfirst(current_path.c_str(), &file_info);
    //返回值为-1则查找失败
    if (-1 == handle)
    {
        cout << "cannot match the path" << endl;
        return;
    }
        if ((file_info.attrib &( _A_SUBDIR))!=0)
        {
            //.是当前目录,..是上层目录,须排除掉这两种情况
            if (strcmp(file_info.name, "..") == 0 || strcmp(file_info.name, ".") == 0)return;


    if(!memo[item])memo[item]=1;
    else return;
    this->removeItem(item);
        this->DfsListFolderFiles(thisPath, item);

}}

void MainWindow::on_itemDoubleClicked(QTreeWidgetItem* item, int column)
{
    QString program = (openMethodTextEdit->toPlainText());

    QStringList arguments;

    arguments << outTextEdit->toPlainText();

    _finddata_t file_info;
    string current_path = Qs2Ss(outTextEdit->toPlainText());
    long long handle = _findfirst(current_path.c_str(), &file_info);
//auto parent1=type!=0?((QTreeWidget*)parent):((QTreeWidgetItem*)parent);
    //返回值为-1则查找失败
    if (-1 == handle)
    {
        return;
    }

        //目录
        if ((file_info.attrib &(_A_ARCH))!=0)
        {           //.是当前目录,..是上层目录,须排除掉这两种情况
            if (strcmp(file_info.name, "..") != 0 && strcmp(file_info.name, ".") != 0){

    QProcess *process = new QProcess(this);
    process->start(program, arguments);
            }}
}

void MainWindow::handleItemClicked(QTreeWidgetItem *item, int column)
{
}


template void MainWindow::DfsListFolderFiles(const string ,QTreeWidget *,int);
template void MainWindow::DfsListFolderFiles(const string ,QTreeWidgetItem *,int);

//stringop.h
#ifndef STRINGOP_H
#define STRINGOP_H

#include<iostream>
#include<string>
#include<vector>
#include<regex>
#include <algorithm>
#include"vectorop.h"
using namespace std;
#pragma once

class stringOP {

public:
   string txt;

   stringOP() ;
   stringOP(string s) ;

   void setTxt(string s) ;
   vector<int> static findPlace(const string &aim, const string &txt , int op=2);
   vector<int> static findPlaceWithRegex(const string &regexPattern, const string &txt , int op = 2);
   void static getNextArray(const string &aim, vector<int> &nextArray);

   int indexNum(vector<int>vi,int goalNum) ;
   vector<string>* getMid(string Laim,string Raim) ;

   //_aa_bb_cc_->aa,bb,cc
   // aa_bb_cc
  //00b包含开头与结尾aa,cc

   vector<string>* getMid2( string regoalS, int op) ;

   string* eraseString(int begin,int lon,vector<string> delS) ;
   string* eraseString(vector<string> delS) ;
   string* eraseString(int begin, int lon, string delS);
   string* eraseString(string delS);
   string* eraseChar(int begin, int lon, string delC) ;
   string* eraseChar( string delC) ;

   string* eraseChar2(int begin, int lon, string includeC) ;

   string* eraseChar2(string includeC) ;


   void print(string name = "stringOP");

   //未完成
   vector<int>* reFindPlace(string aim) ;

   string replace(string oldS, string newS);

   stringOP &operator =(string s);
   stringOP &operator =(stringOP &s);
   string static replace2(string S, string oldS, string newS);
   vector<vector<string> > ESCS2List(string sourceS);

   template<class T>
   vector<vector<T> > reShape(vector<T> List, int w=1);


};
#endif // STRINGOP_H

//stringop.cpp
#pragma execution_character_set("utf-8")

#include "stringop.h"
#include<iostream>
#include<string>
#include<QDebug>
#include<vector>
#include<map>
#include<regex>

using namespace std;



   stringOP::stringOP() {
   }

   stringOP::stringOP(string s) {
       setTxt(s);
   }

   void stringOP::setTxt(string s) {
       txt = s;
   }

   stringOP& stringOP::operator=(string s){
   txt=s;
   return *this;
   }

   stringOP& stringOP::operator=(stringOP& s){
   *this=s;
   return *this;
   }


   //<<<<<<<找<<<结果0 1 2 3 4 ...【1】
   //<<<<<<<找<<<结果0 3 【2默认】
   /*
   vector<int>*stringOP::findPlace(string aim,int op) {
       vector<int>* vi = new(vector<int>);

       for (int i = 0; i <= int(txt.size()-aim.size()); i++) {
           int j = 0;
           for (; j < int(aim.size()); j++) {
               if (txt[i + j] != aim[j])break;
           }
           if (j == int(aim.size()))vi->push_back(i);
       }

       if (op==2)for(int i=1,j=0;i<int(vi->size());){
//            qDebug()<<i<<j<<vi->at(i)<<vi->at(j);
           if(vi->at(i)-vi->at(j)<int(aim.size()))
               vi->erase(vi->begin()+i);
           else {j=i;i++;}}

       return vi;
   }
   */


vector<int> stringOP::findPlace(const string& aim,const string&txt,int op) {
   vector<int> vi;

   const int txtSize = static_cast<int>(txt.size());
   const int aimSize = static_cast<int>(aim.size());

   vector<int> nextArray(aimSize, 0);
   getNextArray(aim, nextArray);

   int i = 0;
   int j = 0;

   while (i < txtSize) {
       if (txt[i] == aim[j]) {
           i++;
           j++;
       }

       if (j == aimSize) {
           vi.push_back(i - j);
           j = nextArray[j - 1];
       } else if (i < txtSize && txt[i] != aim[j]) {
           if (j != 0) {
               j = nextArray[j - 1];
           } else {
               i++;
           }
       }
   }

   if (op == 2) {
       for (int i = 1, j = 0; i < static_cast<int>(vi.size());) {
           if (vi[i] - vi[j] < aimSize) {
               vi.erase(vi.begin() + i);
           } else {
               j = i;
               i++;
           }
       }
   }

   return vi;
}

vector<int> stringOP::findPlaceWithRegex(const string& regexPattern,const string&txt, int op) {
   vector<int> vi;
   regex pattern(regexPattern);
   const int txtSize = static_cast<int>(txt.size());

   for (int i = 0; i < txtSize; i++) {
       string substring = txt.substr(i);
       smatch match;
       if (regex_search(substring, match, pattern) && match.prefix().length() == i) {
           vi.push_back(i);
       }
   }

   if (op == 2) {
       for (int i = 1, j = 0; i < static_cast<int>(vi.size());) {
           if (vi[i] - vi[j] < static_cast<int>(regex_replace(txt.substr(vi[j], vi[i] - vi[j]), pattern, "#").length())) {
               vi.erase(vi.begin() + i);
           } else {
               j = i;
               i++;
           }
       }
   }

   return vi;
}

void stringOP::getNextArray(const string& aim, vector<int>& nextArray) {
   int length = static_cast<int>(aim.size());
   int i = 1;
   int j = 0;
   while (i < length) {
       if (aim[i] == aim[j]) {
           j++;
           nextArray[i] = j;
           i++;
       } else {
           if (j != 0) {
               j = nextArray[j - 1];
           } else {
               nextArray[i] = 0;
               i++;
           }
       }
   }
}




   int stringOP::indexNum(vector<int>vi,int goalNum) {
       int i = 0, j = vi.size(), m = (i + j) / 2;
       if (j == 0)return -1;
       for (; i < j;) {
           if (vi[m] > goalNum)j = m - 1;
           else i = m + 1;
           m = (i + j) / 2;
       }
       if (m >=int( vi.size()))m--;
       if (vi[m] > goalNum)m--;
       return m;
   }

   vector<string>* stringOP::getMid(string Laim,string Raim) {
       vector<int> *Lvi =& findPlace(Laim,txt);
       vector<int> *Rvi =& findPlace(Raim,txt);
       //printVector(*Lvi,"LVI");
       //printVector(*Rvi,"RVI");

       int LR = Raim.length();
       int l, r;
       vector<string>* S = new(vector<string>);

       for (r = 0; int(Rvi->size())>r; r++) {
           l = indexNum(*Lvi, (*Rvi)[r]);
           //printf("【%d,%d】》【%d,%d】", l, r, (*Lvi)[l], (*Rvi)[r]);

           if (l == -1)continue;
           if (l >= 0) {
               S->push_back(txt.substr((*Lvi)[l], (*Rvi)[r] + LR- (*Lvi)[l]));
               Lvi->erase(Lvi->begin()+l);
           }

       }
       free(Lvi);
       free(Rvi);
       return S;
   }


   //字符串_aa_bb_cc_
   // 0b 1 0 1 1 【默认为0】
   // 未匹配到返回原串 包含regalS 包含结尾 包含开头
   vector<string>* stringOP::getMid2( string regoalS, int op) {

       vector<int>*a=&findPlace(regoalS,txt,2),P = *a;

       vector<string>*S = new (vector<string>);
//        if(txt.size()==0)return S;
       if(P.size()==0){
           S->push_back(txt);
           return S;}
       if ((op & 1) != 0){
           S->push_back(txt.substr(0, P[0]));
           qDebug()<<"include head";
       }
       if(P.size()==1)return S;
       int i = 0;
       for (; i < int(P.size() - 1); i++) {
           S->push_back(txt.substr(P[i], P[i+1]-P[i]));
       }
       if ((op & 2) != 0){
           S->push_back(txt.substr(P[i]));
           qDebug()<<"include tail";
       }
       free(a);


       if((op & 4) != 0){

           for(int i=0;i<int(S->size());i++)


           if(S->at(i).size()>=regoalS.size())
               S->at(i)=stringOP::replace2(S->at(i),regoalS,"");
//            qDebug()<<QString::fromStdString(S->at(i));
//qDebug()<<"no include regoalS";
       }

//        qDebug()<<"the end";
       return S;
   }

   string* stringOP::eraseString(int begin,int lon,vector<string> delS) {
       vector<int>PL ;
       vector<int>PR;
       int s;
       map<int, int,sortAsc>m1;
       for (string i : delS) {
           PR=PL = findPlace(i,txt);
           s= i.size();
//        vectorOP::myreplace(PR,0,PR.size(), [s](int e) ->int{return e + s; });
        for(int ii=0;ii<int(PR.size());ii++)
            PR[ii]+=s;

//        vectorOP::vec2map(m1, PL, PR);
       for (int ii = 0; ii < int(PL.size()); ii++)m1[PL[ii]] = PR[ii];
       }
       PL.clear(); PR.clear();
//        vectorOP::map2vec(m1, PL, PR);
       for(auto i:m1){
           PL.push_back(i.first);
           PR.push_back(i.second);
       }

//        vectorOP::printVector(PL,"PL");
//        vectorOP::printVector(PR, "PR");
       //printMap(m1);
       PL.push_back(txt.size());
       PR.insert(PR.begin(), 0);
       string *NS = new(string);
       for (int i = 0; i < int(PR.size()); i++) {
           *NS=*NS+(txt.substr(PR[i], PL[i] - PR[i]));
       }
       txt = *NS;
       return NS;
   }

   string* stringOP::eraseString(vector<string> delS) {
       return eraseString(0, txt.size(), delS);
   }
   string* stringOP::eraseString(int begin, int lon, string delS) {
       vector<string>a ;
       a.push_back(delS);
   return eraseString(begin, lon, a);
   }
   string* stringOP::eraseString(string delS) {
       return eraseString(0, txt.size(), delS);
   }

   string* stringOP::eraseChar(int begin, int lon, string delC) {
       string* NS = new(string);
       for(auto i:txt)
       if(delC.find(i)==string::npos)NS->push_back(i);
       txt = *NS;
       return NS;
   }

   string* stringOP::eraseChar( string delC) {
       return eraseChar(0,txt.size(), delC);

   }

   string* stringOP::eraseChar2(int begin, int lon, string includeC) {
       string* NS = new(string);
       for (auto i : txt)
           if (includeC.find(i) != string::npos)NS->push_back(i);
       txt = *NS;
       return NS;
   }

   string* stringOP::eraseChar2(string includeC) {
       return eraseChar2(0, txt.size(), includeC);

   }



   void stringOP::print(string name ) {

       qDebug()<<endl << QString::fromStdString(name)<< ">>>[" << QString::fromStdString(txt) <<"]"<< endl;
   }


   //未完成
   vector<int>* stringOP::reFindPlace(string aim) {
       regex r(aim);
       vector<int>* vi = new(vector<int>);
       int p=0;
       while (p= regex_search(txt.substr(p+1), r)) {
           vi->push_back(p);
           cout << p <<endl;
       }
       return vi;
   }

   string stringOP::replace(string oldS,string newS){
       vector<int> P=this->findPlace(oldS,txt);
//        vectorOP::printVector(P,"P");
       int s=oldS.size();
       int D=0,d=newS.size()-oldS.size();
       for(int i : P){
//qDebug()<<QString::fromStdString(to_string(i+D*d))<<"|||"<<QString::fromStdString(to_string(i+s+D*d));
//qDebug()<<QString::fromStdString(txt.substr(D*d+i,s));
txt.replace(txt.begin()+i+D*d,txt.begin()+i+s+D*d,newS);
D++;
//print(to_string(i));
       }

//        qDebug()<<QString::fromStdString(txt);
       return txt;
   }


   string stringOP::replace2(string S,string oldS,string newS){
       stringOP sop(S);
       sop.replace(oldS,newS);
       return sop.txt;
   }



   vector<vector<string>> stringOP::ESCS2List(string sourceS)
   {   stringOP SS(sourceS);
//        SS.print();
       vector<string> listDic={" ","\\","'","\n",","};
//        SS.replace("[]","NULL");
       SS.eraseChar("[]");
//        SS.print("erase");

       int j=30;
       string dels;

       //替换回符号
       for(string i :listDic){
           dels="%"+to_string(j);
//            qDebug()<<"dels"<<QString::fromStdString(dels)<<QString::fromStdString(i);
           sourceS=SS.replace(dels,i);
           j++;
       }
       SS.print("替换回符号/30");

       vector<string> slist=(*SS.getMid2(">>>",0b1111));
     vectorOP::printVector(slist,">>>分割");

//      替换回符号/20,以,分割
       vector<vector<string>>Slist;
       stringOP ss;
       qDebug()<<"slist.size>>>"<<slist.size();
       for(string i:slist){
           ss.txt=i;
           qDebug()<<"N\n"<<QString::fromStdString(i) ;


           vector<string> vs=*ss.getMid2(",",0b1111);
           /*111
            * 【1…… 2022-12-20%2010:45:38…… name…… ……
            * 19…… 2022-12-20%2009:09:36…… name1…… null……
            * 29…… 2022-12-20%2015:51:23…… 考研单词…… ……
            * 30…… 2022-12-20%2015:51:35…… 高考单词…… ……
            * 31…… 2022-12-20%2015:51:47…… 重点单词…… ……
            * 32…… 2022-12-20%2015:52:01…… 阅读单词…… ……
            * 33…… 2022-12-20%2015:52:11…… 听力单词…… …………】
             110
             【2022-12-20%2010:45:38…… name…… …… 19……
               2022-12-20%2009:09:36…… name1…… null…… 29……
               2022-12-20%2015:51:23…… 考研单词…… …… 30……
               2022-12-20%2015:51:35…… 高考单词…… …… 31……
               2022-12-20%2015:51:47…… 重点单词…… …… 32……
               2022-12-20%2015:52:01…… 阅读单词…… …… 33……
               2022-12-20%2015:52:11…… 听力单词…… …………】
*/

           Slist.push_back(vs);
           vectorOP::printVector(vs,"vs");

//            qDebug()<<"A\n"<<QString::fromStdString(Slist.end()->c_str()) ;
//            vectorOP::printVector(Slist[a]);

       }
       qDebug()<<"Slist.push_back(vs)ed";
       vectorOP::printVector(Slist,"Slist");
       qDebug()<<"printed";

       j=20;
       vector<vector<string>>SSlist;
       for(auto i : listDic){
           dels="%"+to_string(j);
           for(int k=0;k<int(Slist.size());k++){
//                qDebug()<<QString::fromStdString(i)<<k<<(typeid(Slist[k])!=typeid(int));
               if (typeid(Slist[k])!=typeid(int)){
                   for(int h=0;h<int(Slist[k].size());h++){

                       Slist[k][h]=stringOP::replace2(Slist[k][h],dels,i);
                   }
               }
           }
           j++;
       }
vectorOP::printVector(Slist,"SSList");
       return Slist;


   }

   template<class T>
   vector<vector<T>> stringOP::reShape(vector<T> List, int w)
   {   vector<vector<T>> bookMsg;
       int i=0;
       qDebug()<<"List.size()>>>"<<List.size();
       for(;i<int(List.size()/4*4);i+=w){
           bookMsg.push_back(vectorOP::sub(List,i,w));
       }
       return bookMsg;
   }



  template vector<vector<int>> stringOP::reShape(vector<int> , int );
   template vector<vector<double>> stringOP::reShape(vector<double> , int );
   template vector<vector<string>> stringOP::reShape(vector<string> , int );
   template vector<vector<float>> stringOP::reShape(vector<float> , int );
   template vector<vector<bool>> stringOP::reShape(vector<bool> , int );

//vectorop.h
#ifndef VECTOROP_H
#define VECTOROP_H
#pragma once
#include <string>
#include <vector>
#include<map>
using namespace std;


#include <QString>
#include <iostream>
#include <sstream>
#include <string>
#include<QDebug>


class vectorOP {
public:

   template<class T >
   static string printVector(vector<T>& v, string name = "printVector",string separator="><",int show=1);

   template<class T >
   static string printVector(vector<vector<T>> & v, string name = "printVector2",string separator="><");

//    template<typename T>
//    void static printVectorS(vector<T> &v, string name);


   template<class T>
   static string* vec2str(vector<T> vs, string fill = "");

   template <class T , class Fn>
   static void myreplace(vector<T>& v, int startIndex, int lon, Fn f);

//    template <class T , class _Fn>
//    static void myreplace(vector<T>& v, _Fn f);

   template<class T , class T2,class T3>
   static void printMap(map<T, T2,T3>& v, string name = "printMap");

   template<class T , class T2>
   static void printMap(map<T, T2>& v, string name = "printMap");

   template<class T1, class T2>
   static void map2vec(map<T1, T2>v, vector<T1>& v1, vector<T2>& v2);

   template<class T1, class T2>
   static map<T1, T2> vec2map(map<T1, T2> &v, vector<T1> v1, vector<T2> v2);
   template<class T1, class T2, class T3,class T4>
   static void map2vec(map<T1, T2, T3,T4> v, vector<T1> &v1, vector<T2> &v2);
   template<class T1, class T2, class T3,class T4>
   static map<T1, T2, T3,T4> vec2map(map<T1, T2, T3,T4> &v, vector<T1> v1, vector<T2> v2);

   template<class T>
   //lon:-1后面全部,0不截取
   vector<T> static sub(vector<T>,int head,int lon=-1);


};


class sortDesc {
public:
   template<class T>
   bool operator()(T e1, T e2) const{
       return e1 > e2;
   }
};
class sortAsc {
public:
   template<class T>
   bool operator()(T e1, T e2)const {
       return e1 < e2;
   }
};



#endif // VECTOROP_H

//vectorOP.cpp
#pragma execution_character_set("utf-8")
#include <string>
#include <iostream>
#include<algorithm>
#include <vector>
#include<map>
#include "vectorop.h"
#include<QDebug>

using namespace std;




//*******************P
template<class T=string>
string vectorOP::printVector(vector<T>& v, string name ,string separator,int show) {
   std::ostringstream oss;
   std::streambuf* pOldBuf = std::cout.rdbuf(oss.rdbuf());

   typename::std::vector<T>::iterator itBegin2 = v.begin();
   cout<<name<<">>>[";
   for (; itBegin2 != v.end(); itBegin2++){

   cout <<* itBegin2<<separator;
}
   cout<<"]";
std::cout.rdbuf(pOldBuf);

if(show)qDebug()<<QString::fromStdString(oss.str())  ;
return oss.str();

}

template<class T>
string vectorOP::printVector(vector<vector<T> > &v, string name,string separator)
{
   std::ostringstream oss;
   std::streambuf* pOldBuf = std::cout.rdbuf(oss.rdbuf());
   int a=0;
   cout<< name<< ">>>]";
   for(auto i:v)cout<<vectorOP::printVector(i,"index>>>"+to_string(a++),separator,0);
   cout<< "[\n";

   std::cout.rdbuf(pOldBuf);

   qDebug()<<QString::fromStdString(oss.str())  ;

   return oss.str();
}

template<class T>
string* vectorOP::vec2str(vector<T> vs, string fill ) {
   string* S = new(string);
   for (auto i : vs)
       S->append(fill + i);
   return S;
}

template <class T, class Fn>
void vectorOP::myreplace(vector<T> &v,int startIndex, int lon, Fn f) {
   typename::std::vector<T>::iterator it = v.begin();
   it += startIndex;
   for (; it != v.begin()+ startIndex+lon; it++)
        *it =f(*it);
}

//template <class T , class _Fn>
//void vectorOP::myreplace(vector<T>& v, _Fn f) {
//    vectorOP::myreplace(v, 0, v.size(), f);
//}




////////////////////////////////////////////////////////////////////////////////////////////

template<class T, class T2,class T3>
void vectorOP::printMap(map<T, T2,T3>& v, string name) {
   typename::std::map<T, T2,T3>::iterator itBegin2 = v.begin();
   qDebug() << QString::fromStdString(name) << ">>>[";
   for (; itBegin2 != v.end(); itBegin2++)
       qDebug()  << itBegin2->first << ":" << itBegin2->second << ",";
   qDebug()  << "]\n";
}

template<class T , class T2>
void vectorOP::printMap(map<T, T2>& v, string name) {
   typename::std::map<T, T2>::iterator itBegin2 = v.begin();
   qDebug() << QString::fromStdString(name) << ">>>[";
   for (; itBegin2 != v.end(); itBegin2++)
       qDebug()  << itBegin2->first << ":" << itBegin2->second << ",";
   qDebug()  << "]\n";
}

template<class T1,class T2>
void vectorOP::map2vec(map<T1, T2>v,vector<T1>&v1, vector<T2>& v2) {
   typename::std::map<T1, T2>::iterator itBegin2 = v.begin();
   for (; itBegin2 != v.end(); itBegin2++)
   v1.push_back(itBegin2->first);
   v2.push_back(itBegin2->second);
}

template<class T1, class T2>
map<T1, T2> vectorOP::vec2map(map<T1, T2>&v, vector<T1>v1, vector<T2>v2) {
   for (int i = 0; i < v1.size(); i++)v[v1[i]] = v2[i];
   return v;
}

template<class T1, class T2,class T3,class T4>
void vectorOP::map2vec(map<T1, T2,T3,T4>v, vector<T1>& v1, vector<T2>& v2) {
   typename::std::map<T1, T2,T3>::iterator itBegin2 = v.begin();
   for (; itBegin2 != v.end(); itBegin2++) {
       v1.push_back(itBegin2->first);
       v2.push_back(itBegin2->second);
   }
}

template<class T1, class T2,class T3,class T4>
map<T1, T2,T3,T4> vectorOP::vec2map(map<T1, T2,T3,T4>& v, vector<T1>v1, vector<T2>v2) {
   for (int i = 0; i < v1.size(); i++)v[v1[i]] = v2[i];
   return v;
}

template<class T>
vector<T> vectorOP::sub(vector<T>v, int head, int lon)
{
   vector<T>V;
   int i=lon==-1?v.size():head;
   for(;i<head+lon;i++){
       V.push_back(v[i]);
   }
   return V;
}

template vector<string> vectorOP::sub(vector<string>,int,int);
template vector<int> vectorOP::sub(vector<int>,int,int);
template vector<double> vectorOP::sub(vector<double>,int,int);
template vector<float> vectorOP::sub(vector<float>,int,int);
template vector<bool> vectorOP::sub(vector<bool>,int,int);


template string vectorOP::printVector(vector<string>&,string,string,int);
template string vectorOP::printVector(vector<int>&,string,string,int);
template string vectorOP::printVector(vector<double>&,string,string,int);
template string vectorOP::printVector(vector<float>&,string,string,int);
template string vectorOP::printVector(vector<bool>&,string,string,int);


template string vectorOP::printVector(vector<vector<string>>&,string,string);
template string vectorOP::printVector(vector<vector<int>>&,string,string);
template string vectorOP::printVector(vector<vector<double>>&,string,string);
template string vectorOP::printVector(vector<vector<float>>&,string,string);
template string vectorOP::printVector(vector<vector<bool>>&,string,string);

totoo既是屎山代码的搬运工,也是屎山代码的生产者