<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 02/21/2018 11:16 PM, Stefan Giese
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:04e38b79-f23e-e0b8-e9ba-4910ba414876@wheregroup.com">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <p>yes, you can. Save the style in the same directory as foo.qml.<br>
      </p>
      <div class="moz-cite-prefix">Am 22.02.2018 um 02:25 schrieb David
        J. Bakeman:<br>
      </div>
      <blockquote type="cite"
        cite="mid:37000159-9183-5d04-33eb-7ce3d4f91f7a@comcast.net">
        <meta http-equiv="content-type" content="text/html;
          charset=utf-8">
        <p><tt><font size="+1">Can I make it so that every time I load a
              shapefile named foo.shp it gets a particular style?</font></tt><br>
        </p>
        <br>
      </blockquote>
    </blockquote>
    <font size="+1">Yes but I don't want to write a script to populate
      my directories with foo.qml...  What I want is to have foo.qml
      applied to foo.shp whenever I open a foo.shp.  If I was just
      opening a few shape files occasionally I would just apply the
      style the way I do now which is to load Style. <br>
      <br>
      I get lots of shapefiles that come in a deep directory tree. I
      load the whole directory tree using the excellent plug-in load
      them all but then I have to go in and manually apply the styles.  
      I occasionally use another excellent plugin multiqml to apply
      Styles in a somewhat automated fashion but it's still difficult.<br>
      <br>
      I thought I had heard of some way to do this but couldn't google
      the right thing.  So I discovered by browsing the qgis source code
      that whenever it loads a new map layer, in addition to checking
      for a foo.qml file, it checks a sqlite db qgis.qmldb (actually it
      checks for qgis.qmldb in the settings path and
      resources/qgis.qmldb and the project path projectbasename.qmldb)
      and I thought I could use this.  I couldn't find any instructions
      on how to create the sqlite database but I did find an example by
      Googling and I created my own. <br>
      <br>
      Initially I tried using foo.shp as the key but that didn't work. 
      Once I discovered how to build a debug qgis version I discovered
      that unfortunately this looks for the full path instead of just
      foo.shp, actually it is the full path/foo.qml.   So I don't have
      to put foo.qml files all throughout my directory tree but I still
      have to have a separate entry for each foo file in this qml
      database.<br>
      <br>
      So I added one more test where it takes just the file name so
      foo.qml and searches for that in the qml database in the
      application settings directory.  For me this works great I can
      load a whole bunch of shape files using load them all and they all
      get the style that I want!<br>
      <br>
      This is what I changed the code to: <br>
      <br>
      <font color="#ff0000"><code>QFileInfo  fname(theURI);</code></font><code><br>
      </code><code>if ( loadNamedStyleFromDb( QDir(
        QgsApplication::qgisSettingsDirPath() ).absoluteFilePath(
        "qgis.qmldb" ), theURI, qml ) ||</code><code><br>
      </code><code>   ( project.exists() &&
        loadNamedStyleFromDb( project.absoluteDir().absoluteFilePath(
        project.baseName() + ".qmldb" ), theURI, qml ) ) ||</code><code><br>
      </code><code>   loadNamedStyleFromDb( QDir(
        QgsApplication::pkgDataPath() ).absoluteFilePath(
        "resources/qgis.qmldb" ), theURI, qml ) <font color="#ff0000">||</font></code><font
        color="#ff0000"><code><br>
        </code></font><code><font color="#ff0000">  
          loadNamedStyleFromDb( QDir(
          QgsApplication::qgisSettingsDirPath() ).absoluteFilePath(
          "qgis.qmldb" ), fname.fileName(), qml )</font>)</code><code><br>
      </code><code><br>
      </code>Am I doing something the wrong way?</font><br>
  </body>
</html>